Skip to content

Commit

Permalink
make the tag title to take text instead of children
Browse files Browse the repository at this point in the history
  • Loading branch information
jcornaz committed Nov 1, 2024
1 parent 50092ec commit 18d368c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
10 changes: 8 additions & 2 deletions src/nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ pub fn head(

pub fn title(
attributes: impl IntoIterator<Item = Attribute>,
children: impl IntoIterator<Item = Node>,
text: impl Into<Cow<'static, str>>,
) -> Node {
Node::new("title", attributes, children)
Node::new("title", attributes, [text.into().into()])
}

pub fn body(
Expand Down Expand Up @@ -96,6 +96,12 @@ pub fn raw_unsafe(html: String) -> Node {
NodeInner::Raw(html.into()).into()
}

impl From<Cow<'static, str>> 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)
Expand Down
4 changes: 2 additions & 2 deletions tests/render_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!")])]),
],
);
Expand Down Expand Up @@ -47,7 +47,7 @@ fn should_render_attribute(#[case] attr: Attribute, #[case] expected: &str) {
#[case(div([("foo", "bar").into()], ["hello".into()]), "<div foo=\"bar\">hello</div>")]
#[case(div([("foo", "bar".to_string()).into()], [text("hello".to_string())]), "<div foo=\"bar\">hello</div>")]
#[case(head([id("foo")], [text("hello")]), "<head id=\"foo\">hello</head>")]
#[case(title([("foo", "bar").into()], [text("hello")]), "<title foo=\"bar\">hello</title>")]
#[case(title([("foo", "bar").into()], "hello"), "<title foo=\"bar\">hello</title>")]
#[case(body([id("foo")], [text("hello")]), "<body id=\"foo\">hello</body>")]
#[case(h1([id("foo")], [text("hello")]), "<h1 id=\"foo\">hello</h1>")]
#[case(h2([id("foo")], [text("hello")]), "<h2 id=\"foo\">hello</h2>")]
Expand Down

0 comments on commit 18d368c

Please sign in to comment.