From f47a8981abe7c9dd021dee859b2749b1d356ac21 Mon Sep 17 00:00:00 2001 From: Jonathan Cornaz Date: Sat, 2 Nov 2024 21:37:56 +0100 Subject: [PATCH] rename modules --- README.md | 15 ++++++--------- src/{attributes.rs => attr.rs} | 0 src/{elements.rs => elt.rs} | 0 src/lib.rs | 30 ++++++++++++++---------------- tests/render_spec.rs | 2 +- tests/rocket_v05_spec.rs | 4 ++-- 6 files changed, 23 insertions(+), 28 deletions(-) rename src/{attributes.rs => attr.rs} (100%) rename src/{elements.rs => elt.rs} (100%) diff --git a/README.md b/README.md index ae0bdef..7a08be6 100644 --- a/README.md +++ b/README.md @@ -2,22 +2,18 @@ ![rustc](https://img.shields.io/badge/rustc-1.60+-blue?logo=rust) -This rust crate provides a simple and efficient way to generate HTML using Rust functions, +This rust library provides a simple and efficient way to generate HTML using Rust functions, with an intuitive and composable API to create HTML elements. ```rust -use fun_html::{attributes::class, elements::h1}; +use fun_html::{attr::class, elt::h1}; let greeting = h1( - [class(["bold"])], // <-- First argument is the attributes - ["Hello world!".into()], // <-- Second argument is the children + [class(["bold"])], // <-- attributes + ["Hello world!".into()], // <-- children ); -assert_eq!(greeting.to_string(), "

Hello world!

"); +assert_eq!(greeting.to_string(), r#"

Hello world!

"#); ``` -## Feature flags - -* `std`: enabled by default. must be disabled to compile to `no_std` -* `rocket_v05`: implements the `Responder` from [rocket](https://rocket.rs) v0.5 for [`Document`] and [`Element`] ## MSRV @@ -25,6 +21,7 @@ The minimum supported rust version is currently `1.60`. It will be updated when required, and that will not be considered a breaking change (it can happen in a minor version). + ## MIT License Copyright (c) 2024 Jonathan Cornaz diff --git a/src/attributes.rs b/src/attr.rs similarity index 100% rename from src/attributes.rs rename to src/attr.rs diff --git a/src/elements.rs b/src/elt.rs similarity index 100% rename from src/elements.rs rename to src/elt.rs diff --git a/src/lib.rs b/src/lib.rs index 481e573..86035d4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,14 +4,17 @@ //! This crate provides a simple and efficient way to generate HTML using Rust functions, //! with an intuitive and composable API to create HTML elements. //! -//! The [`elements`] module contains functions to create common HTML elements. Most of them take 2 arguments: +//! The [`elt`] module contains functions to create common HTML elements. Most of them take 2 arguments: //! The list of attributes, and the list of children. //! For example, `div([id("mydiv")], ["hello".into()])` creates a `
` with an ID of "mydiv" containing the text "hello". //! -//! The [`attributes`] module contains functions to create common attributes. +//! The [`attr`] module contains functions to create common attributes. +//! +//! Text can be inserted by using the [`elt::text`] function or by using one of the `Into` implementations.//! ``` +//! All text and attribute values are automatically escaped to ensure safe and valid HTML output. //! //! ``` -//! use fun_html::{attributes::class, elements::h1}; +//! use fun_html::{attr::class, elt::h1}; //! //! let greeting = h1( //! [class(["bold"])], // <-- attributes @@ -20,29 +23,24 @@ //! assert_eq!(greeting.to_string(), r#"

Hello world!

"#); //! ``` //! -//! ## Safety -//! -//! Text can be inserted by using the `text` function or by using one of the `Into` implementations. -//! All text and attribute values are automatically escaped to ensure safe and valid HTML output. -//! //! ## Escape hatches //! //! If necessary, it is possible to define custom elements and attributes with respectively [`Element::new`] and [`Attribute::new`]. //! -//! There is also an implementation of `From<(&'static str, &'static str)>` and `From<(&'static str, String)>` for `Attribute`, -//! So it is possible to use custom attribute on the fly (example: `div([("hx-get", "/values").into()], [])`) +//! It is also possible to declare custom attributes on the fly like this: `div([("hx-get", "/values").into()], [])`) //! //! It is also possible to inline raw html with: -//! * [`elements::raw`]: inline HTML that is known at compile time, and is therefore considered safe. -//! * [`elements::raw_unsafe`]: can inline HTML built at runtime, and is therefore unsafe. +//! * [`elt::raw`]: inline HTML that is known at compile time, and is therefore considered safe. +//! * [`elt::raw_unsafe`]: can inline HTML built at runtime, and is therefore unsafe. +//! //! //! ## Feature flags //! //! * `std`: enabled by default. must be disabled to compile to `no_std` //! * `rocket_v05`: implements the `Responder` from [rocket](https://rocket.rs) v0.5 for [`Document`] and [`Element`] -pub mod attributes; -pub mod elements; +pub mod attr; +pub mod elt; mod interop { #[cfg(feature = "rocket_v05")] @@ -56,7 +54,7 @@ use alloc::{borrow::Cow, fmt::Display, vec::Vec}; /// An HTML document (``) /// /// ``` -/// use fun_html::{Document, html, elements::{head, body}}; +/// use fun_html::{Document, html, elt::{head, body}}; /// let doc: Document = html([], [head([], []), body([], [])]); /// /// assert_eq!(doc.to_string(), "\n"); @@ -67,7 +65,7 @@ pub struct Document(Element); /// An HTML element /// /// ``` -/// use fun_html::{Element, elements::div}; +/// use fun_html::{Element, elt::div}; /// let element: Element = div([], []); /// /// assert_eq!(element.to_string(), "
"); diff --git a/tests/render_spec.rs b/tests/render_spec.rs index a3b5e7a..baef6c5 100644 --- a/tests/render_spec.rs +++ b/tests/render_spec.rs @@ -1,6 +1,6 @@ use rstest::rstest; -use fun_html::{attributes::*, elements::*, html, Attribute, Document, Element}; +use fun_html::{attr::*, elt::*, html, Attribute, Document, Element}; #[test] fn should_render_empty_document() { diff --git a/tests/rocket_v05_spec.rs b/tests/rocket_v05_spec.rs index 9f77879..b4c609f 100644 --- a/tests/rocket_v05_spec.rs +++ b/tests/rocket_v05_spec.rs @@ -6,8 +6,8 @@ extern crate rocket_v05 as rocket; use rstest::{fixture, rstest}; use fun_html::{ - attributes::id, - elements::{body, div, head}, + attr::id, + elt::{body, div, head}, html, Document, Element, }; use rocket::{