lewp_html/
lib.rs

1#![deny(missing_docs)]
2
3//! Straightforward HTML document building. Write your HTML with the full power
4//! of a programming language instead of creating messy and confusing
5//! templates that contain typing errors.
6//!
7//! ## API example
8//!
9//! ```
10//! use lewp_html::{api::*, LanguageTag, Script, DocumentExt, NodeExt};
11//!
12//! let valid_html = document(LanguageTag::parse("de-DE").unwrap(),
13//!    head(vec![
14//!        script(Script::Src("/my-javascript")),
15//!        script(Script::Inline("console.log(\"hello world!\");")),
16//!        link("text/css", "/static/css/main.css")
17//!    ]),
18//!    body(
19//!        vec![
20//!        h1(vec![text("Hello World")]),
21//!        p(vec![text("This is a paragraph!")])
22//!            .attrs(vec![
23//!                ("class", "prelude"),
24//!                ("id", "first-paragraph")
25//!            ]),
26//!        h2(vec![text("The elegant way to create a DOM!")]),
27//!        p(vec![text("Creating DOM has never been easier.")])
28//!            .attr("class", "highlighted")
29//!        ])
30//! ).into_html();
31//!
32//! let expected_html = "<!DOCTYPE html><html lang=\"de\"><head><script src=\"/my-javascript\"></script><script>console.log(\"hello world!\");</script><link href=\"/static/css/main.css\" type=\"text/css\"></head><body><h1>Hello World</h1><p class=\"prelude\" id=\"first-paragraph\">This is a paragraph!</p><h2>The elegant way to create a DOM!</h2><p class=\"highlighted\">Creating DOM has never been easier.</p></body></html>";
33//!
34//! assert_eq!(&valid_html, expected_html);
35//! ```
36
37/// API function definitions to create your html document. See the API example
38/// above.
39pub mod api;
40
41mod document;
42mod document_ext;
43mod node;
44mod node_ext;
45mod types;
46
47pub use {
48    charsets::Charset,
49    document::Document,
50    document_ext::DocumentExt,
51    langtag::LanguageTag,
52    node::Node,
53    node_ext::NodeExt,
54    types::*,
55};
56
57/// A list of nodes.
58pub type Nodes = Vec<Node>;
59
60#[macro_export]
61/// Error log with added prefix for this crate.
62macro_rules! error {
63    ($($arg:tt)*) => (
64        log::error!("(LEWP-DOM) {}", format!($($arg)*));
65    )
66}