Function build_component

Source
pub fn build_component(component: &Component<'_>) -> String
Expand description

Generates HTML string using the provided struct component

ยงExample

use html_compile::compile::*;
use html_compile::types::*;

let input_component = Component {
    tag: "section",
    meta: Some(vec![
        Attribute {
            label: "style",
            value: "border: 1px solid black; padding: 10px;",
        },
        Attribute {
            label: "class",
            value: "Example",
        },
    ]),
    child: Child::ComponentVec(vec![
        Box::new(Component {
            tag: "h2",
            meta: None,
            child: Child::Text("Text of a Heading"),
        }),
        Box::new(Component {
            tag: "p",
            meta: None,
            child: Child::Text("Text of a Paragraph"),
        }),
    ]),
};

let output = build_component(&input_component);  

assert_eq!(output, String::from("<section style=\"border: 1px solid black; padding: 10px;\" class=\"Example\"><h2>Text of a Heading</h2><p>Text of a Paragraph</p></section>"));

In a browser the string will display as follows:

Text of a Heading

Text of a Paragraph