1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
//! ----------------
//!
//! 
//! [](https://docs.rs/lewp)
//! 
//! 
//! [](https://discord.gg/nx7YtsjEbT)
//!
//! Say goodbye to the web template hell. Generate your HTML5 website technically optimized and always valid. In your Rust source.
//!
//! ⚠ ***This crate is currently evolving. API changes can happen anytime until v1.0.0***
//!
//! ## Provided solutions
//!
//! When using [lewp](crate), you get the following benefits during web development:
//!
//! * No more template hell in your code base
//! * No more whitespace bugs in your website
//! * Technically optimized, always valid, minified, HTML5 code
//! * Module based development, truly isolated
//! * Build the DOM completely in Rust
//!
//! ## Hello world! example
//!
//! ```
//! use {
//! lewp::{
//! config::{ModuleConfig, PageConfig},
//! html::{
//! api::{h1, text},
//! Nodes,
//! },
//! Module, Modules, RuntimeInformation,
//! Page,
//! Charset,
//! LanguageTag,
//! LewpError,
//! },
//! std::rc::Rc,
//! };
//!
//! // This is one of your modules the webpage is build with.
//! struct HelloWorld {
//! config: ModuleConfig,
//! head_tags: Nodes,
//! data: String,
//! }
//!
//! impl HelloWorld {
//! pub fn new() -> Self {
//! Self {
//! config: ModuleConfig::new(),
//! head_tags: vec![],
//! data: String::from("hello-world"),
//! }
//! }
//! }
//!
//! // The [Module] trait is required for [lewp] to know it is a module. :-)
//! impl Module for HelloWorld {
//! fn head_tags(&self) -> &Nodes {
//! &self.head_tags
//! }
//!
//! fn id(&self) -> &str {
//! "hello-world"
//! }
//!
//! fn config(&self) -> &ModuleConfig {
//! &self.config
//! }
//!
//! fn run(
//! &mut self,
//! _runtime_info: Rc<RuntimeInformation>,
//! ) -> Result<(), LewpError> {
//! Ok(())
//! }
//!
//! fn view(&self) -> Nodes {
//! vec![h1(vec![text(&self.data)])]
//! }
//! }
//!
//! // This struct defines the actual page. The containing members are
//! // required because they define the base on which [lewp] is working on.
//! struct HelloWorldPage {
//! modules: Modules,
//! config: PageConfig,
//! }
//!
//! impl HelloWorldPage {
//! /// Creates a new page.
//! pub fn new(config: PageConfig) -> Self {
//! Self {
//! modules: vec![],
//! config,
//! }
//! }
//! }
//!
//! impl Page for HelloWorldPage {
//! fn modules(&self) -> &Modules {
//! &self.modules
//! }
//! fn modules_mut(&mut self) -> &mut Modules {
//! &mut self.modules
//! }
//!
//! fn title(&self) -> &str {
//! "Hello World from lewp!"
//! }
//!
//! fn description(&self) -> &str {
//! "My first page using lewp!"
//! }
//!
//! fn language(&self) -> LanguageTag {
//! LanguageTag::parse("de-DE").unwrap()
//! }
//!
//! fn charset(&self) -> Charset {
//! Charset::Utf8
//! }
//!
//! fn config(&self) -> &PageConfig {
//! &self.config
//! }
//!
//! fn run(&mut self) {
//! self.add_module(HelloWorld::new().into_module_ptr());
//! }
//! }
//!
//! fn main() {
//! let mut page = HelloWorldPage::new(PageConfig::new());
//! println!("{}", page.build());
//! }
//! ```
pub use ;
/// Re-export of the [lewp_html] crate.
pub
pub