diff --git a/src/nodes.rs b/src/nodes.rs index 48ff8d2..3880aaa 100644 --- a/src/nodes.rs +++ b/src/nodes.rs @@ -18,9 +18,9 @@ pub fn head( pub fn title( attributes: impl IntoIterator, - children: impl IntoIterator, + text: impl Into>, ) -> Node { - Node::new("title", attributes, children) + Node::new("title", attributes, [text.into().into()]) } pub fn body( @@ -96,6 +96,12 @@ pub fn raw_unsafe(html: String) -> Node { NodeInner::Raw(html.into()).into() } +impl From> for Node { + fn from(value: Cow<'static, str>) -> Self { + text(value) + } +} + impl From<&'static str> for Node { fn from(value: &'static str) -> Self { text(value) diff --git a/tests/render_spec.rs b/tests/render_spec.rs index c3c1e27..8df3581 100644 --- a/tests/render_spec.rs +++ b/tests/render_spec.rs @@ -17,7 +17,7 @@ fn should_render_html_document() { let doc = html( [lang("en")], [ - head([], [title([], [text("greeting")])]), + head([], [title([], "greeting")]), body([], [h1([], [text("Hello world!")])]), ], ); @@ -47,7 +47,7 @@ fn should_render_attribute(#[case] attr: Attribute, #[case] expected: &str) { #[case(div([("foo", "bar").into()], ["hello".into()]), "
hello
")] #[case(div([("foo", "bar".to_string()).into()], [text("hello".to_string())]), "
hello
")] #[case(head([id("foo")], [text("hello")]), "hello")] -#[case(title([("foo", "bar").into()], [text("hello")]), "hello")] +#[case(title([("foo", "bar").into()], "hello"), "hello")] #[case(body([id("foo")], [text("hello")]), "hello")] #[case(h1([id("foo")], [text("hello")]), "

hello

")] #[case(h2([id("foo")], [text("hello")]), "

hello

")]