trillium-ructe

Crates.iotrillium-ructe
lib.rstrillium-ructe
version0.4.0
sourcesrc
created_at2021-07-26 00:04:00.789104
updated_at2022-02-09 01:46:06.258678
descriptionructe templates for trillium.rs
homepage
repositoryhttps://github.com/prabirshrestha/trillium-ructe
max_upload_size
id427212
size22,456
Prabir Shrestha (prabirshrestha)

documentation

README

trillium-ructe

ructe templates for trillium.rs.

Getting Started

[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"] }

Example

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"))
    });
}

Use conn.render_html to render html or conn.render to render raw template.

Commit count: 25

cargo fmt