sato
an s-expression based html templating system.
sato template language examples
basic template example
(html
(head
(title "basic example")))
tag attributes
(html
(head (@ (some thing))
(title "basic example")))
variables
variables in sato are prefixed with a $.
(html
(head
(title $some_variable)))
conditionals
(html
(head
(title (if (is-set $some_variable)
(div "$some_variable")
(div "variable is not set")))))
iteration over arrays
(html
(body
(for i in $some_array
(div "element: " $i))))
iteration over maps
(html
(body
(for k v in $some_map
(div $k ": " $v))))
switch/case
(html
(body
(switch $blah
(case asdf
qwer)
(case zxcv
(div what else))
(case hjkl
nm))))
basic library example
use Renderer;
use RenderContext;
use Template;
let renderer = builder
.build;
let expr = r#"(html (head (title "basic example")))"#;
let template = from_str.unwrap;
let html = renderer.render.unwrap;
assert_eq!
using variables
use Renderer;
use RenderContext;
use Template;
let renderer = builder
.build;
let expr = r#"(html (body (if (eq $asdf qwer) (for i in $array (div $i)))))"#;
let template = from_str.unwrap;
let context = builder
.insert
.insert
.build;
let html = renderer.render.unwrap;
assert_eq!
custom handler functions
use ;
use RenderContext;
use ;
let post_expr = r##"(div (h2 $title) (span "posted by $author") $content (br) (div (for tag in $tags (span "#$tag"))))"##;
let blogpost_template = from_str.unwrap;
let renderer = builder
.function
.build;
let expr = r#"(html (body (blogpost (@ (title faketitle) (author me)) (div "my content here"))))"#;
let template = from_str.unwrap;
let context = builder
.insert
.build;
let html = renderer.render.unwrap;
assert_eq!