Skip to content

Commit

Permalink
complete renaming of Node to Element
Browse files Browse the repository at this point in the history
  • Loading branch information
jcornaz committed Nov 1, 2024
1 parent 946aae0 commit df7ae32
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# Rust
/target
/.cargo/*.toml

# Nodes tools
/node_modules
15 changes: 9 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>` for `Node`
* implement `From<[Node; N]>` and `From<Vec<Node>>` for `Node` (group nodes without wrapping them in a `div`)
* implement `From<&'static str>` and `From<String>` for `Element`
* implement `From<[Element; N]>` and `From<Vec<Element>>` for `Element` (group elements without wrapping them in a `div`)

[Unreleased]: https://github.com/jcornaz/fun-html/compare/...HEAD
File renamed without changes.
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down Expand Up @@ -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}")?;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/render_spec.rs
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down Expand Up @@ -56,7 +56,7 @@ fn should_render_attribute(#[case] attr: Attribute, #[case] expected: &str) {
#[case(h4([id("foo")], [text("hello")]), "<h4 id=\"foo\">hello</h4>")]
#[case(h5([id("foo")], [text("hello")]), "<h5 id=\"foo\">hello</h5>")]
#[case(h6([id("foo")], [text("hello")]), "<h6 id=\"foo\">hello</h6>")]
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);
}

Expand Down

0 comments on commit df7ae32

Please sign in to comment.