html-pipe 0.1.1

A basic html component builder
Documentation
use html_pipe::*;

#[derive(Default)]
struct MyPage {
    value: Vec<String>,
}

impl Component for MyPage {
    fn render<'b>(&self, buf: &'b mut Buffer) -> Result<&'b mut Buffer> {
        node(
            "html",
            attr("lang", "en"),
            node("body", noop, |buf| {
                for value in self.value.iter() {
                    node("p", noop, text(value))(buf)?;
                }
                Ok(buf)
            }),
        )(buf)
    }
}

#[test]
fn basic() {
    let mut buf = Buffer::default();
    buf.push_str(DOCTYPE);
    node("html", noop, noop)(&mut buf).unwrap();
    assert_eq!(buf, "<!DOCTYPE html><html></html>");
}

#[test]
fn looping() {
    let mut buf = Buffer::default();

    node(
        "html",
        attr("lang", "en"),
        node("body", noop, |buf| {
            for value in ["foo", "bar", "baz"] {
                node("p", noop, text(value))(buf)?;
            }
            Ok(buf)
        }),
    )(&mut buf)
    .unwrap();

    assert_eq!(
        buf,
        "<html lang=\"en\"><body><p>foo</p><p>bar</p><p>baz</p></body></html>"
    );
}

#[test]
fn structure() {
    let mut buf = Buffer::default();
    let page = MyPage::default();
    page.render(&mut buf).unwrap();
}