aresty 0.1.0

A compiling template library for Rust
Documentation
  • Coverage
  • 0%
    0 out of 14 items documented0 out of 11 items with examples
  • Size
  • Source code size: 10.21 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.96 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 14s Average build duration of successful builds.
  • all releases: 14s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • pozs/aresty
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • pozs

Aresty

A compiling template library for Rust.

Links:

Usage

Add this to your Cargo.toml:

[dependencies]

aresty = "0.1"

Examples

Sample .rst template

<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>

Ad-hoc macro usage

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
}

Proc macro on view struct

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(())
}

Supported tags

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