6 个版本 (3 个重大更改)
0.4.0 | 2022 年 2 月 9 日 |
---|---|
0.3.1 | 2021 年 9 月 19 日 |
0.2.0 | 2021 年 8 月 28 日 |
0.1.1 | 2021 年 7 月 26 日 |
#38 in #trillium
8KB
trillium-ructe
ructe 模板 for trillium.rs.
入门指南
[package]
name = "example-ructe-template"
edition = "2018"
build = "src/build.rs"
[dependencies]
trillium = "0.3.0"
trillium-ructe = "0.3.0"
trillium-smol = "0.3.0"
[build-dependencies]
ructe = { version = "0.13.4", features = ["sass"] }
示例
src/build.rs
use ructe::{Result, Ructe};
fn main() -> Result<()> {
let mut ructe = Ructe::from_env()?;
let mut statics = ructe.statics()?;
statics.add_files("static")?;
statics.add_sass_file("styles/style.scss")?;
ructe.compile_templates("templates")?;
Ok(())
}
templates/helloworld.rs.html
@(text: &str)
<!DOCTYPE html>
<html lang="en">
<head>
<title>Trillium Ructe Example</title>
</head>
<body>
<h1>@text</h1>
</body>
</html>
src/main.rs
use trillium::Conn;
use trillium_ructe::RucteConnExt;
include!(concat!(env!("OUT_DIR"), "/templates.rs"));
fn main() {
trillium_smol::run(|conn: Conn| async move {
conn.render_html(|o| templates::helloworld(o, "html"))
});
}
使用 conn.render_html
来渲染 HTML 或 conn.render
来渲染原始模板。
依赖关系
~9MB
~221K SLoC