3 releases (breaking)
0.3.0 | Mar 4, 2022 |
---|---|
0.2.0 | Oct 2, 2021 |
0.0.0 | Aug 6, 2021 |
#31 in #html5
1MB
23K
SLoC
lewp-rs
This is the actual source code of the lewp
crate. See the repository root for information about the framework, or visit the documentation page.
lib.rs
:
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, 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());
}
Dependencies
~4–12MB
~131K SLoC