use html_pipe::*;
#[derive(Default)]
struct MyPage {
value: Vec,
}
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, "");
}
#[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,
"foo
bar
baz
"
);
}
#[test]
fn structure() {
let mut buf = Buffer::default();
let page = MyPage::default();
page.render(&mut buf).unwrap();
}