#html #codegen #generating

htmlificator

Generate HTML source code through rust functions!

3 unstable releases

Uses new Rust 2021

0.2.1 Nov 7, 2022
0.2.0 Nov 6, 2022
0.1.0 Nov 5, 2022

#664 in Rust patterns

Download history 24/week @ 2022-10-31 43/week @ 2022-11-07 4/week @ 2022-11-14 4/week @ 2022-11-21

75 downloads per month

MIT license

8KB
123 lines

Htmlificator

This crate provides an element struct which can be displayed as HTML.

License

This crate is licensed under the MIT license

Credit

This crate has used a snippet from the TextWrap crate for indentation of the child elements.

Usage

[dependencies]
htmlificator = "0.2.1"

use htmlificator::Element;

fn main() {
    let mut el = Element::new("Div", false);
    el.add_class("TestClass");
    let mut h1 = Element::new("H1", false);
    h1.add_text("This is a heading!!");
    el.add_element(h1);
    el.add_comment("A Comment");
    let mut btn = Element::new("Button", true);
    btn.add_attribute("text", "This is a Button");
    el.add_element(btn);
    println!("{}", el)
}

No runtime deps