mirror of
https://github.com/askama-rs/askama.git
synced 2026-03-13 18:08:23 +00:00
63 lines
1.3 KiB
Rust
63 lines
1.3 KiB
Rust
use askama::Template;
|
|
|
|
#[test]
|
|
fn test_macro_in_block_inheritance() {
|
|
#[derive(Template)]
|
|
#[template(
|
|
source = r#"{% extends "extend_and_import.html" %}
|
|
{%- import "macro.html" as m2 -%}
|
|
|
|
{%- macro another(param) -%}
|
|
|
|
--> {{ param }}
|
|
|
|
{%- endmacro -%}
|
|
|
|
{% block header -%}
|
|
{% call m1::twice(1) %}{% endcall %}
|
|
{% call m2::twice(2) %}{% endcall %}
|
|
{% call another(3) %}{% endcall %}
|
|
{%- endblock -%}
|
|
"#,
|
|
ext = "txt"
|
|
)]
|
|
struct A;
|
|
|
|
assert_eq!(A.render().unwrap(), "1 1\n2 2\n--> 3");
|
|
}
|
|
|
|
// This test ensures that comments are allowed before `extends` block.
|
|
#[test]
|
|
fn test_comment_before_extend() {
|
|
#[derive(Template)]
|
|
#[template(source = r##"{# comment #}{% extends "base.html" %}"##, ext = "txt")]
|
|
pub struct X {
|
|
title: &'static str,
|
|
}
|
|
}
|
|
|
|
// This test ensures that template variables are correctly generated before the `extends`
|
|
// is processed. It also checks that expressions/literals are not rendered.
|
|
#[test]
|
|
fn test_variables_in_extends_blocks() {
|
|
#[derive(Template)]
|
|
#[template(
|
|
source = r#"
|
|
{% extends "extend_and_import.html" %}
|
|
|
|
{{ 45 }}
|
|
yup
|
|
|
|
{% let x = 12 %}
|
|
{%- block header -%}
|
|
{{ x }} + {{ y }}
|
|
{%- endblock -%}
|
|
{% let y = "hello" %}
|
|
"#,
|
|
ext = "html"
|
|
)]
|
|
struct A;
|
|
|
|
assert_eq!(A.render().unwrap(), "12 + hello");
|
|
}
|