Horrorshow
A macro-based html templating library (1.0 compatible).
API: https://stebalien.github.io/horrorshow-rs/horrorshow/
Example:
html! .render;
Becomes (whitespace added for clarity).
<html />
Let's count to 10!
1
2
3
4
5
6
7
8
9
10
Easy!
Hello world!
Hello! This is
Usage
Inside an html template, the following expressions are valid:
-
some_tag;
-- Insert a the tagsome_tag
. -
some_tag(attr=rust_expresion,...);
-- Insert a the tagsome_tag
with the specified attributes. The attribute values will be evaluated as rust expressions at runtime. -
some_tag { ... }
-- Insert a the tagsome_tag
and recursivly evaluate the...
. -
some_tag(...) { ... }
-- Same as above but with custom attributes. -
: rust_expression
,: { rust_code }
-- Evaluate the expression or block and insert result current position. -
#{"format_str", rust_expressions... }
-- Format the arguments according toformat_str
and insert the result at the current position. -
@ rust_expression
,@ { rust_code }
-- Evaluate the expression or block.
In rust code embedded inside of a template, you can append text with any of the following macros:
append_fmt!("format_str", args...)
-- format, escape, and append argumentsappend_raw!(text)
-- append text without escapingappend!(text)
-- escape and append textappend_html! { html_template... }
-- append an html template.
Disclaimer
This library is mostly untested and probably a security hazard.