mirror of
https://github.com/askama-rs/askama.git
synced 2025-09-28 13:30:59 +00:00
63 lines
1.2 KiB
Rust
63 lines
1.2 KiB
Rust
use rinja::Template;
|
|
|
|
#[derive(Template)]
|
|
#[template(
|
|
source = r#"
|
|
{%- if *title == "something" -%}
|
|
something1
|
|
{%- elif title == &"another" -%}
|
|
another2
|
|
{%- elif &*title == &&*"yep" -%}
|
|
yep3
|
|
{%- else -%}
|
|
{{title}}
|
|
{%- endif -%}
|
|
"#,
|
|
ext = "html"
|
|
)]
|
|
struct RefDeref {
|
|
title: &'static &'static str,
|
|
}
|
|
|
|
#[test]
|
|
fn test_ref_deref() {
|
|
let x = RefDeref {
|
|
title: &"something",
|
|
};
|
|
assert_eq!(x.render().unwrap(), "something1");
|
|
|
|
let x = RefDeref { title: &"another" };
|
|
assert_eq!(x.render().unwrap(), "another2");
|
|
|
|
let x = RefDeref { title: &"yep" };
|
|
assert_eq!(x.render().unwrap(), "yep3");
|
|
|
|
let x = RefDeref { title: &"bla" };
|
|
assert_eq!(x.render().unwrap(), "bla");
|
|
}
|
|
|
|
#[derive(Template)]
|
|
#[template(
|
|
source = r#"
|
|
{%- let x = **title -%}
|
|
{%- if x == "another" -%}
|
|
another2
|
|
{%- else -%}
|
|
{{x}}
|
|
{%- endif -%}
|
|
"#,
|
|
ext = "html"
|
|
)]
|
|
struct RefDerefAssignment {
|
|
title: &'static &'static str,
|
|
}
|
|
|
|
#[test]
|
|
fn test_ref_deref_assign() {
|
|
let x = RefDerefAssignment { title: &"another" };
|
|
assert_eq!(x.render().unwrap(), "another2");
|
|
|
|
let x = RefDerefAssignment { title: &"two" };
|
|
assert_eq!(x.render().unwrap(), "two");
|
|
}
|