From 06c36e1bfdc9d3be2bc17201d2af34a6cffd5337 Mon Sep 17 00:00:00 2001 From: Roland Fredenhagen Date: Sun, 17 Sep 2023 00:08:43 +0200 Subject: [PATCH] documentation --- Cargo.lock | 21 +++++ Cargo.toml | 4 +- example/actix.rs | 9 +- htmx-macros/src/lib.rs | 58 +++++++++++- src/actix.rs | 56 +++++++++++ src/attributes.rs | 14 +++ src/axum.rs | 23 +++++ src/htmx_utils.rs | 14 ++- src/lib.rs | 206 +++++++++++++++++++---------------------- src/native.rs | 83 ++++++++++------- 10 files changed, 335 insertions(+), 153 deletions(-) create mode 100644 src/actix.rs create mode 100644 src/axum.rs diff --git a/Cargo.lock b/Cargo.lock index f056d44..ec009dc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1424,6 +1424,7 @@ dependencies = [ "quote-use", "serde", "serde_json", + "typed-builder", ] [[package]] @@ -3225,6 +3226,26 @@ version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" +[[package]] +name = "typed-builder" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6605aaa56cce0947127ffa0675a8a1b181f87773364390174de60a86ab9085f1" +dependencies = [ + "typed-builder-macro", +] + +[[package]] +name = "typed-builder-macro" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a6a6884f6a890a012adcc20ce498f30ebdc70fb1ea242c333cc5f435b0b3871" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.33", +] + [[package]] name = "typenum" version = "1.16.0" diff --git a/Cargo.toml b/Cargo.toml index a40b437..71abc6d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ repository = "https://github.com/ModProg/htmx" documentation = "https://docs.rs/htmx" [features] -# default = ["axum"] +default = ["axum", "actix-web"] sorted_attributes = [] axum = ["dep:axum-core"] @@ -36,6 +36,7 @@ actix-web = { version = "4.4.0", default-features = false, optional = true } axum-core = { version = "0.3.4", optional = true } serde = "1.0.188" serde_json = "1.0.107" +typed-builder = "0.16.0" [dev-dependencies] insta = "1.31.0" @@ -43,6 +44,7 @@ insta = "1.31.0" htmx = { path = ".", default-features = false, features = [ "sorted_attributes", ] } +serde = { version = "1.0.188", features = ["derive"] } [profile.dev.package.insta] opt-level = 3 diff --git a/example/actix.rs b/example/actix.rs index be9cbd9..c5ec5d2 100644 --- a/example/actix.rs +++ b/example/actix.rs @@ -13,7 +13,7 @@ async fn index() -> impl Responder { let rust_str = ["hello", "world", "!"]; htmx! { - + + } } } diff --git a/src/lib.rs b/src/lib.rs index 920ba8a..6633806 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,24 +1,69 @@ -#![warn(clippy::pedantic/* , missing_docs */)] +#![warn(clippy::pedantic, missing_docs)] #![allow(clippy::wildcard_imports)] #![cfg_attr(docsrs, feature(doc_auto_cfg))] +//! Library for doing serverside rendering of htm{l,x} using a macro. +//! +//! # `htmx!` macro +//! +//! The [`htmx!`] macro allows to write [`Html`] inside your rust code allowing +//! to include rust values and instantiate [custom +//! components](#custom-components). +//! +//! ``` +//! # use htmx::htmx; +//! +//! ``` +//! +//! # Custom Components +//! +//! For more documentation see the individual items and the [examples](https://github.com/ModProg/htmx/tree/main/example). +use std::fmt::Write; + +use derive_more::Display; +use serde::Serialize; pub mod attributes; mod htmx_utils; pub mod native; -use std::fmt::Write; -use std::iter; -use derive_more::Display; pub use htmx_macros::*; pub use htmx_utils::*; -const DOCTYPE: &str = ""; +#[cfg(feature = "actix-web")] +mod actix; +#[cfg(feature = "actix-web")] +pub use actix::*; -#[derive(Default, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Display)] -#[must_use] -pub struct Html(String); +#[cfg(feature = "axum")] +mod axum; +#[cfg(feature = "axum")] +pub use axum::*; + +const DOCTYPE: &str = ""; +/// Trait used with the custom rust like js in `