diff --git a/.gitignore b/.gitignore index abdc56d..ce771a2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,3 @@ # Rust /target /.cargo/*.toml - -# Nodes tools -/node_modules diff --git a/CHANGELOG.md b/CHANGELOG.md index 609a36c..2511b04 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,18 +9,21 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Added -* `Node`, `Attribute` and `Document` types +* `Element`, `Attribute` and `Document` types * `html` function to create an html document -* Attribute values and text nodes are escaped for HTML -* `lang`, `id` and `class` attributes -* Nodes +* Attribute values and text elements are escaped for HTML +* Attributes + * `lang` + * `id` + * `class` +* Elements * Html document (`html`, `head` and `body`) * Meta (`meta`, `title`) * Text (`h1` to `h6`, and `text`) * Container (`div`) * Escape hatches (`raw` and `raw_unsafe`) * implement `From<(&'static str, Cow<'static, str)>` for `Attribute` -* implement `From<&'static str>` and `From` for `Node` -* implement `From<[Node; N]>` and `From>` for `Node` (group nodes without wrapping them in a `div`) +* implement `From<&'static str>` and `From` for `Element` +* implement `From<[Element; N]>` and `From>` for `Element` (group elements without wrapping them in a `div`) [Unreleased]: https://github.com/jcornaz/fun-html/compare/...HEAD diff --git a/src/nodes.rs b/src/elements.rs similarity index 100% rename from src/nodes.rs rename to src/elements.rs diff --git a/src/lib.rs b/src/lib.rs index 134c0c9..593ae3c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,7 @@ #![cfg_attr(docsrs, feature(doc_auto_cfg))] pub mod attributes; -pub mod nodes; +pub mod elements; use std::{borrow::Cow, fmt::Display}; @@ -112,9 +112,9 @@ impl Display for Element { } ElementInner::Text(text) => write!(f, "{}", html_escape::encode_text(text))?, ElementInner::Raw(raw) => write!(f, "{raw}")?, - ElementInner::Multiple(nodes) => { - for node in nodes { - write!(f, "{node}")?; + ElementInner::Multiple(elems) => { + for elt in elems { + write!(f, "{elt}")?; } } } diff --git a/tests/render_spec.rs b/tests/render_spec.rs index f119b83..507e5a5 100644 --- a/tests/render_spec.rs +++ b/tests/render_spec.rs @@ -1,6 +1,6 @@ use rstest::rstest; -use fun_html::{attributes::*, html, nodes::*, Attribute, Document, Element}; +use fun_html::{attributes::*, elements::*, html, Attribute, Document, Element}; #[test] fn should_render_empty_document() { @@ -56,7 +56,7 @@ fn should_render_attribute(#[case] attr: Attribute, #[case] expected: &str) { #[case(h4([id("foo")], [text("hello")]), "

hello

")] #[case(h5([id("foo")], [text("hello")]), "
hello
")] #[case(h6([id("foo")], [text("hello")]), "
hello
")] -fn should_render_node(#[case] def: Element, #[case] expected: &str) { +fn should_render_element(#[case] def: Element, #[case] expected: &str) { assert_eq!(def.to_string(), expected); }