Crates.io | aresty |
lib.rs | aresty |
version | 0.1.0 |
source | src |
created_at | 2024-02-18 20:15:32.471546 |
updated_at | 2024-02-18 20:15:32.471546 |
description | A compiling template library for Rust |
homepage | |
repository | https://github.com/pozs/aresty |
max_upload_size | |
id | 1144363 |
size | 9,361 |
A compiling template library for Rust.
Links:
Add this to your Cargo.toml
:
[dependencies]
aresty = "0.1"
<ol>
{{#for i in ints}}
<li class="{{#if i % 6 == 0}}fizzbuzz{{#else if i % 2 == 0}}fizz{{#else if i % 3 == 0}}buzz{{#else}}none{{/if}}">{{i}}</li>
{{/for}}
</ol>
<ul>
{{#for o in opts}}
<li>
{{#match o}}
{{=None}}Nothing at all
{{=Some(s)}}It is a "{{s}}"
{{/match}}
</li>
{{/for}}
</ul>
use std::io::Write;
use aresty::{aresty_render, escape::Escape, escape::NoEscape, Result};
fn hello_world(out: &mut impl Write) -> Result {
let world = "World!";
let result: Result = aresty_render!(out, NoEscape, "aresty_examples/src/hello_world.rst");
result
}
use aresty::{aresty, Result, Template};
#[aresty("aresty_examples/src/view.rst")]
struct View<'a> {
ints: Vec<i32>,
opts: &'a Vec<Option<String>>,
}
fn main() -> Result {
let mut out = std::io::stdout();
let view = View {
ints: vec![1, 2, 3, 4, 5, 6, 60],
opts: &vec![None, Some("thing & co".to_string())],
};
view.render_html(&mut out)?;
Ok(())
}
Tag | effect |
---|---|
{{expr}} |
expr is evaluated, and printed escaped |
{{{expr}}} |
expr is evaluated, and printed as is (without escaping) |
{{!expr}} |
expr is evaluated, but not printed (i.e. let ) |
{{#block}} |
block opened (i.e. if , else , else if , for , match , etc.) |
{{/block}} |
block closed |
{{=expr}} |
expr branch for the parent match block; does not need to be closed |