use std::fmt::Display;
use oxiplate::{Oxiplate, Render};
struct HelloWorld;
impl HelloWorld {
fn hello() -> String {
String::from("Hello world <<script><!--")
}
}
impl Display for HelloWorld {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str("Hello world <<script><!--")
}
}
#[derive(Oxiplate)]
#[oxiplate_inline(html: "
# default:
{{ slice }}
{{ string }}
{{ integer }}
{{ float }}
{{ display }}
{{ display_borrowed }}
{{ fn_string }}
# text:
{{ text: slice }}
{{ text: string }}
{{ text: integer }}
{{ text: float }}
{{ text: display }}
{{ text: display_borrowed }}
{{ text: fn_string }}
# comment:
{{ comment: slice }}
{{ comment: string }}
{{ comment: integer }}
{{ comment: float }}
{{ comment: display }}
{{ comment: display_borrowed }}
{{ comment: fn_string }}
# raw:
{{ raw: slice }}
{{ raw: string }}
{{ raw: integer }}
{{ raw: float }}
{{ raw: display }}
{{ raw: display_borrowed }}
{{ raw: fn_string }}
")]
struct Types<'a> {
slice: &'a str,
string: String,
integer: u64,
float: f64,
display: HelloWorld,
display_borrowed: &'a HelloWorld,
fn_string: String,
}
#[test]
fn types() {
let data = Types {
slice: "Hello world <<script><!--",
string: String::from("Hello world <<script><!--"),
integer: 19,
float: 19.89,
display: HelloWorld,
display_borrowed: &HelloWorld,
fn_string: HelloWorld::hello(),
};
assert_eq!(
data.render().unwrap(),
r"
# default:
Hello world &lt;<script><!--
Hello world &lt;<script><!--
19
19.89
Hello world &lt;<script><!--
Hello world &lt;<script><!--
Hello world &lt;<script><!--
# text:
Hello world &lt;<script><!--
Hello world &lt;<script><!--
19
19.89
Hello world &lt;<script><!--
Hello world &lt;<script><!--
Hello world &lt;<script><!--
# comment:
Hello world <‹script›‹ǃ−−
Hello world <‹script›‹ǃ−−
19
19.89
Hello world <‹script›‹ǃ−−
Hello world <‹script›‹ǃ−−
Hello world <‹script›‹ǃ−−
# raw:
Hello world <<script><!--
Hello world <<script><!--
19
19.89
Hello world <<script><!--
Hello world <<script><!--
Hello world <<script><!--
"
);
}