├── book ├── .gitignore ├── book.toml └── src │ ├── SUMMARY.md │ ├── performance.md │ ├── debugging.md │ ├── getting_started.md │ ├── askama.md │ ├── integrations.md │ ├── configuration.md │ └── creating_templates.md ├── askama ├── LICENSE-MIT ├── LICENSE-APACHE ├── src │ ├── helpers.rs │ ├── error.rs │ └── filters │ │ └── json.rs ├── Cargo.toml └── benches │ └── to-json.rs ├── askama_actix ├── LICENSE-MIT ├── LICENSE-APACHE ├── templates │ └── hello.html ├── README.md ├── tests │ └── basic.rs ├── Cargo.toml └── src │ └── lib.rs ├── askama_axum ├── LICENSE-MIT ├── LICENSE-APACHE ├── templates │ └── hello.html ├── README.md ├── tests │ └── basic.rs ├── src │ └── lib.rs └── Cargo.toml ├── askama_derive ├── templates │ ├── a.html │ ├── b.html │ └── sub │ │ ├── b.html │ │ ├── c.html │ │ └── sub1 │ │ └── d.html ├── LICENSE-MIT ├── LICENSE-APACHE ├── README.md ├── Cargo.toml └── src │ ├── tests.rs │ └── heritage.rs ├── askama_warp ├── LICENSE-MIT ├── LICENSE-APACHE ├── templates │ └── hello.html ├── tests │ └── warp.rs ├── README.md ├── Cargo.toml └── src │ └── lib.rs ├── testing ├── templates │ ├── foo.html │ ├── foo.jinja │ ├── attr.html │ ├── foo.html.jinja │ ├── filters.html │ ├── generics.html │ ├── hello.html │ ├── included.html │ ├── composition.html │ ├── filters_join.html │ ├── format.html │ ├── if.html │ ├── invalid_syntax.html │ ├── cycle1.html │ ├── cycle2.html │ ├── nested-attr.html │ ├── rust-macros.html │ ├── let-base.html │ ├── tuple-attr.html │ ├── char-literals │ │ ├── char-literal-1.txt │ │ ├── char-literal-2.txt │ │ ├── char-literal-5.txt │ │ ├── char-literal-3.txt │ │ ├── char-literal-4.txt │ │ ├── char-literal-6.txt │ │ └── char-literal-7.txt │ ├── else.html │ ├── rust-macros-full-path.html │ ├── include_invalid_syntax.html │ ├── let.html │ ├── literals.html │ ├── raw-simple.html │ ├── if-let-shadowing.html │ ├── if-let.html │ ├── json.html │ ├── size-parent.txt │ ├── else-if.html │ ├── include.html │ ├── import.html │ ├── raw-ws.html │ ├── extend_and_import.html │ ├── match-no-ws.html │ ├── deep-import-parent.html │ ├── deep-nested-macro.html │ ├── nested-base.html │ ├── size-child-super.txt │ ├── if-let-struct.html │ ├── include-extends-included.html │ ├── option.html │ ├── size-child.txt │ ├── base.html │ ├── child.html │ ├── include-extends.html │ ├── raw-complex.html │ ├── macro-self-arg.html │ ├── let-child.html │ ├── include-macro.html │ ├── nested-child.html │ ├── included-macro.html │ ├── match-literal-num.html │ ├── big-table.html │ ├── deep-import-child.html │ ├── let-decl.html │ ├── ranges.txt │ ├── render_in_place.html │ ├── let-destruct-tuple.html │ ├── nested-for.html │ ├── simple.html │ ├── precedence.html │ ├── literals-escape.html │ ├── simple-no-escape.txt │ ├── match-literal-char.html │ ├── if-let-else.html │ ├── match-literal.html │ ├── include-extends-base.html │ ├── match-opt.html │ ├── fragment-base.html │ ├── match-opt-bool.html │ ├── precedence-for.html │ ├── fragment-include.html │ ├── fragment-mid-super.html │ ├── fragment-simple.html │ ├── blocks.txt │ ├── match-enum-or.html │ ├── deep-kid.html │ ├── nested-macro-args.html │ ├── nested-macro.html │ ├── for.html │ ├── fragment-super.html │ ├── fragment-unused-expr.html │ ├── macro-import-str-cmp.html │ ├── fragment-nested-super.html │ ├── rust-macro-args.html │ ├── macro-no-args.html │ ├── macro-short-circuit.html │ ├── fragment-nested-block.html │ ├── match-option-result-option.html │ ├── deep-base.html │ ├── if-let-with-for.html │ ├── for-break-continue.html │ ├── for-range.html │ ├── macro-import-str-cmp-macro.html │ ├── named-end.html │ ├── macro.html │ ├── match-custom-enum.html │ ├── teams.html │ ├── let-shadow.html │ ├── deep-mid.html │ ├── operators.html │ ├── num-literals.html │ ├── compare.html │ ├── if-coerce.html │ └── allow-whitespaces.html ├── test_minimize.toml ├── test_trim.toml ├── tests │ ├── ui │ │ ├── no_template_attribute.rs │ │ ├── cycle.rs │ │ ├── cycle2.rs │ │ ├── incorrect_path.rs │ │ ├── macro-super.rs │ │ ├── lit_on_assignment_lhs.rs │ │ ├── name_mismatch_endblock.rs │ │ ├── name_mismatch_endmacro.rs │ │ ├── break_outside_of_loop.rs │ │ ├── filter_block_ws.rs │ │ ├── loop_cycle_empty.rs │ │ ├── typo_in_keyword.rs │ │ ├── duplicated_template_attribute.rs │ │ ├── block_and_vars.rs │ │ ├── block_and_vars.stderr │ │ ├── loop_cycle_empty.stderr │ │ ├── no_template_attribute.stderr │ │ ├── loop_cycle_wrong_argument_count.rs │ │ ├── duplicated_template_attribute.stderr │ │ ├── loop_cycle_wrong_argument_count.stderr │ │ ├── lit_on_assignment_lhs.stderr │ │ ├── extends.rs │ │ ├── filter_block_ws.stderr │ │ ├── match_with_extra.stderr │ │ ├── typo_in_keyword.stderr │ │ ├── excessive_nesting.stderr │ │ ├── incorrect_path.stderr │ │ ├── error_file_path.rs │ │ ├── match_with_extra.rs │ │ ├── macro-super.stderr │ │ ├── break_outside_of_loop.stderr │ │ ├── name_mismatch_endblock.stderr │ │ ├── name_mismatch_endmacro.stderr │ │ ├── cycle2.stderr │ │ ├── cycle.stderr │ │ ├── macro.rs │ │ ├── extends.stderr │ │ ├── macro.stderr │ │ ├── char_literal.rs │ │ ├── error_file_path.stderr │ │ ├── unclosed-nodes.rs │ │ ├── macro_named_argument.rs │ │ ├── macro_named_argument.stderr │ │ ├── char_literal.stderr │ │ └── unclosed-nodes.stderr │ ├── coerce.rs │ ├── extend.rs │ ├── if.rs │ ├── hello.rs │ ├── render_in_place.rs │ ├── size_hint.rs │ ├── ui.rs │ ├── methods.rs │ ├── include.rs │ ├── operators.rs │ ├── gen_loop_else.py │ ├── rust_macro.rs │ ├── ext.rs │ ├── try.rs │ ├── tuple.rs │ ├── calls.rs │ ├── vars.rs │ ├── let_destructoring.rs │ ├── block_fragments.rs │ ├── if_let.rs │ ├── macro.rs │ └── filter_block.rs ├── Cargo.toml └── benches │ └── all.rs ├── askama_escape ├── LICENSE-MIT ├── LICENSE-APACHE ├── Cargo.toml ├── README.md ├── benches │ └── all.rs └── src │ └── lib.rs ├── askama_parser ├── LICENSE-MIT ├── LICENSE-APACHE ├── benches │ ├── librustdoc │ │ ├── item_info.html │ │ ├── type_layout_size.html │ │ ├── LICENSE.md │ │ ├── source.html │ │ ├── short_item_info.html │ │ ├── print_item.html │ │ ├── item_union.html │ │ ├── sidebar.html │ │ └── type_layout.html │ └── from_str.rs ├── README.md ├── Cargo.toml └── tests │ └── target-recursion.txt ├── askama_rocket ├── LICENSE-MIT ├── LICENSE-APACHE ├── templates │ └── hello.html ├── README.md ├── tests │ └── basic.rs ├── Cargo.toml └── src │ └── lib.rs ├── .gitignore ├── .gitattributes ├── .github └── FUNDING.yml ├── fuzz ├── .gitignore ├── README.md ├── fuzz_targets │ ├── fuzz_parser.rs │ └── fuzz_filters.rs └── Cargo.toml ├── deny.toml ├── Cargo.toml ├── README.md └── LICENSE-MIT /book/.gitignore: -------------------------------------------------------------------------------- 1 | book 2 | -------------------------------------------------------------------------------- /askama/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | ../LICENSE-MIT -------------------------------------------------------------------------------- /askama/LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | ../LICENSE-APACHE -------------------------------------------------------------------------------- /askama_actix/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | ../LICENSE-MIT -------------------------------------------------------------------------------- /askama_axum/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | ../LICENSE-MIT -------------------------------------------------------------------------------- /askama_derive/templates/a.html: -------------------------------------------------------------------------------- 1 | foo 2 | -------------------------------------------------------------------------------- /askama_derive/templates/b.html: -------------------------------------------------------------------------------- 1 | bar 2 | -------------------------------------------------------------------------------- /askama_warp/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | ../LICENSE-MIT -------------------------------------------------------------------------------- /testing/templates/foo.html: -------------------------------------------------------------------------------- 1 | foo.html -------------------------------------------------------------------------------- /testing/templates/foo.jinja: -------------------------------------------------------------------------------- 1 | foo.jinja -------------------------------------------------------------------------------- /askama_axum/LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | ../LICENSE-APACHE -------------------------------------------------------------------------------- /askama_derive/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | ../LICENSE-MIT -------------------------------------------------------------------------------- /askama_derive/templates/sub/b.html: -------------------------------------------------------------------------------- 1 | bar 2 | -------------------------------------------------------------------------------- /askama_derive/templates/sub/c.html: -------------------------------------------------------------------------------- 1 | baz 2 | -------------------------------------------------------------------------------- /askama_escape/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | ../LICENSE-MIT -------------------------------------------------------------------------------- /askama_parser/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | ../LICENSE-MIT -------------------------------------------------------------------------------- /askama_rocket/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | ../LICENSE-MIT -------------------------------------------------------------------------------- /askama_warp/LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | ../LICENSE-APACHE -------------------------------------------------------------------------------- /askama_actix/LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | ../LICENSE-APACHE -------------------------------------------------------------------------------- /askama_derive/LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | ../LICENSE-APACHE -------------------------------------------------------------------------------- /askama_derive/templates/sub/sub1/d.html: -------------------------------------------------------------------------------- 1 | echo 2 | -------------------------------------------------------------------------------- /askama_escape/LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | ../LICENSE-APACHE -------------------------------------------------------------------------------- /askama_parser/LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | ../LICENSE-APACHE -------------------------------------------------------------------------------- /askama_rocket/LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | ../LICENSE-APACHE -------------------------------------------------------------------------------- /testing/templates/attr.html: -------------------------------------------------------------------------------- 1 | {{ inner.a }} 2 | -------------------------------------------------------------------------------- /testing/templates/foo.html.jinja: -------------------------------------------------------------------------------- 1 | foo.html.jinja -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | Cargo.lock 3 | .DS_Store 4 | -------------------------------------------------------------------------------- /testing/templates/filters.html: -------------------------------------------------------------------------------- 1 | {{ strvar|e }} 2 | -------------------------------------------------------------------------------- /testing/templates/generics.html: -------------------------------------------------------------------------------- 1 | {{ t }}{{ u }} 2 | -------------------------------------------------------------------------------- /testing/templates/hello.html: -------------------------------------------------------------------------------- 1 | Hello, {{ name }}! 2 | -------------------------------------------------------------------------------- /testing/templates/included.html: -------------------------------------------------------------------------------- 1 | INCLUDED: {{ s }} 2 | -------------------------------------------------------------------------------- /askama_actix/templates/hello.html: -------------------------------------------------------------------------------- 1 | Hello, {{ name }}! 2 | -------------------------------------------------------------------------------- /askama_axum/templates/hello.html: -------------------------------------------------------------------------------- 1 | Hello, {{ name }}! 2 | -------------------------------------------------------------------------------- /askama_rocket/templates/hello.html: -------------------------------------------------------------------------------- 1 | Hello, {{ name }}! 2 | -------------------------------------------------------------------------------- /askama_warp/templates/hello.html: -------------------------------------------------------------------------------- 1 | Hello, {{ name }}! 2 | -------------------------------------------------------------------------------- /testing/templates/composition.html: -------------------------------------------------------------------------------- 1 | composed: {{ foo }} 2 | -------------------------------------------------------------------------------- /testing/templates/filters_join.html: -------------------------------------------------------------------------------- 1 | {{ s|join(", ") }} 2 | -------------------------------------------------------------------------------- /testing/templates/format.html: -------------------------------------------------------------------------------- 1 | {{ "{:?}"|format(var) }} 2 | -------------------------------------------------------------------------------- /testing/templates/if.html: -------------------------------------------------------------------------------- 1 | {% if cond %}true{% endif %} 2 | -------------------------------------------------------------------------------- /testing/templates/invalid_syntax.html: -------------------------------------------------------------------------------- 1 | {% let 12 = 0 } 2 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.html text eol=lf 2 | *.txt text eol=lf 3 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: [djc] 2 | patreon: dochtman 3 | -------------------------------------------------------------------------------- /testing/templates/cycle1.html: -------------------------------------------------------------------------------- 1 | {% extends "cycle1.html" %} 2 | -------------------------------------------------------------------------------- /testing/templates/cycle2.html: -------------------------------------------------------------------------------- 1 | {% extends "cycle1.html" %} 2 | -------------------------------------------------------------------------------- /testing/templates/nested-attr.html: -------------------------------------------------------------------------------- 1 | {{ inner.holder.a }} 2 | -------------------------------------------------------------------------------- /testing/templates/rust-macros.html: -------------------------------------------------------------------------------- 1 | Hello, {{ hello!() }}! 2 | -------------------------------------------------------------------------------- /fuzz/.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | corpus 3 | artifacts 4 | coverage 5 | -------------------------------------------------------------------------------- /testing/templates/let-base.html: -------------------------------------------------------------------------------- 1 | {% block body %}{% endblock %} 2 | -------------------------------------------------------------------------------- /testing/templates/tuple-attr.html: -------------------------------------------------------------------------------- 1 | {{ tuple.0 }}{{ tuple.1 }} 2 | -------------------------------------------------------------------------------- /testing/test_minimize.toml: -------------------------------------------------------------------------------- 1 | [general] 2 | whitespace = "minimize" 3 | -------------------------------------------------------------------------------- /testing/test_trim.toml: -------------------------------------------------------------------------------- 1 | [general] 2 | whitespace = "suppress" 3 | -------------------------------------------------------------------------------- /testing/templates/char-literals/char-literal-1.txt: -------------------------------------------------------------------------------- 1 | {% let s = '\a' %} 2 | -------------------------------------------------------------------------------- /testing/templates/char-literals/char-literal-2.txt: -------------------------------------------------------------------------------- 1 | {% let s = '\x' %} 2 | -------------------------------------------------------------------------------- /testing/templates/char-literals/char-literal-5.txt: -------------------------------------------------------------------------------- 1 | {% let s = '\u' %} 2 | -------------------------------------------------------------------------------- /testing/templates/char-literals/char-literal-3.txt: -------------------------------------------------------------------------------- 1 | {% let s = '\x1' %} 2 | -------------------------------------------------------------------------------- /testing/templates/char-literals/char-literal-4.txt: -------------------------------------------------------------------------------- 1 | {% let s = '\x80' %} 2 | -------------------------------------------------------------------------------- /testing/templates/char-literals/char-literal-6.txt: -------------------------------------------------------------------------------- 1 | {% let s = '\u{}' %} 2 | -------------------------------------------------------------------------------- /testing/templates/else.html: -------------------------------------------------------------------------------- 1 | {% if cond %}true{% else %}false{% endif %} 2 | -------------------------------------------------------------------------------- /testing/templates/rust-macros-full-path.html: -------------------------------------------------------------------------------- 1 | Hello, {{ foo::hello2!() }}! 2 | -------------------------------------------------------------------------------- /testing/templates/char-literals/char-literal-7.txt: -------------------------------------------------------------------------------- 1 | {% let s = '\u{110000}' %} 2 | -------------------------------------------------------------------------------- /testing/templates/include_invalid_syntax.html: -------------------------------------------------------------------------------- 1 | {% extends "invalid_syntax.html" %} 2 | -------------------------------------------------------------------------------- /testing/templates/let.html: -------------------------------------------------------------------------------- 1 | {% let v = s %}{{ v }} 2 | {% let (v1,v2) = t %}{{ v1 }}{{ v2 }} -------------------------------------------------------------------------------- /testing/templates/literals.html: -------------------------------------------------------------------------------- 1 | {{ 'a' }} 2 | {{ "a" }} 3 | {{ true }} 4 | {{ false }} 5 | -------------------------------------------------------------------------------- /testing/templates/raw-simple.html: -------------------------------------------------------------------------------- 1 | {% raw %} 2 | {{ name }} 3 | {% endraw %} 4 | -------------------------------------------------------------------------------- /testing/templates/if-let-shadowing.html: -------------------------------------------------------------------------------- 1 | {% if let Some(text) = text %}{{ text }}{% endif %} 2 | -------------------------------------------------------------------------------- /testing/templates/if-let.html: -------------------------------------------------------------------------------- 1 | {% if let Some(some_text) = text %}{{ some_text }}{% endif %} 2 | -------------------------------------------------------------------------------- /testing/templates/json.html: -------------------------------------------------------------------------------- 1 | { 2 | "foo": "{{ foo }}", 3 | "bar": {{ bar|json|safe }} 4 | } 5 | -------------------------------------------------------------------------------- /testing/templates/size-parent.txt: -------------------------------------------------------------------------------- 1 | {% block main %}{% if true %}12345{% endif %}{% endblock %} 2 | -------------------------------------------------------------------------------- /testing/templates/else-if.html: -------------------------------------------------------------------------------- 1 | {% if cond %}true{% else if check %}checked{% else %}false{% endif %} 2 | -------------------------------------------------------------------------------- /testing/templates/include.html: -------------------------------------------------------------------------------- 1 | {% for s in strs %} 2 | {% include "included.html" %} 3 | {%- endfor %} 4 | -------------------------------------------------------------------------------- /testing/templates/import.html: -------------------------------------------------------------------------------- 1 | 2 | {%- import "macro.html" as scope -%} 3 | 4 | {% call scope::thrice(s) %} 5 | -------------------------------------------------------------------------------- /testing/templates/raw-ws.html: -------------------------------------------------------------------------------- 1 | <{% raw -%} {{hello}} {%- endraw %}> 2 | < {%- raw %}{{bye}}{% endraw -%} > 3 | -------------------------------------------------------------------------------- /testing/templates/extend_and_import.html: -------------------------------------------------------------------------------- 1 | {% import "macro.html" as m1 %} 2 | 3 | {% block header %}{% endblock %} 4 | -------------------------------------------------------------------------------- /testing/templates/match-no-ws.html: -------------------------------------------------------------------------------- 1 | {% match foo %}{% when Some with (bar) %}{{ bar }}{% when None %}{% endmatch %} 2 | -------------------------------------------------------------------------------- /testing/templates/deep-import-parent.html: -------------------------------------------------------------------------------- 1 | {%- import "deep-import-child.html" as libj -%} 2 | {% call libj::parent() %} 3 | -------------------------------------------------------------------------------- /testing/templates/deep-nested-macro.html: -------------------------------------------------------------------------------- 1 | {%- import "nested-macro.html" as libi -%} 2 | {%- call libi::parent() -%} 3 | -------------------------------------------------------------------------------- /testing/templates/nested-base.html: -------------------------------------------------------------------------------- 1 | {% block content %} 2 | loopy 3 | {% block foo %}Foo{% endblock %} 4 | {% endblock %} 5 | -------------------------------------------------------------------------------- /testing/templates/size-child-super.txt: -------------------------------------------------------------------------------- 1 | {% extends "size-parent.txt" %} 2 | {% block main %}{% call super() %}{% endblock %} 3 | -------------------------------------------------------------------------------- /testing/templates/if-let-struct.html: -------------------------------------------------------------------------------- 1 | {% if let Digits { one, two, three } = digits %}{{ one }} {{ two }} {{ three }}{% endif %} 2 | -------------------------------------------------------------------------------- /testing/templates/include-extends-included.html: -------------------------------------------------------------------------------- 1 | {% extends "include-extends-base.html" %} 2 | {% block header %}foo{% endblock %} 3 | -------------------------------------------------------------------------------- /testing/templates/option.html: -------------------------------------------------------------------------------- 1 | {% if var.is_some() -%} 2 | some: {{ var.unwrap() }} 3 | {%- else -%} 4 | none 5 | {%- endif %} 6 | -------------------------------------------------------------------------------- /testing/templates/size-child.txt: -------------------------------------------------------------------------------- 1 | {% extends "size-parent.txt" %} 2 | {% block main %}{% if true %}123{% endif %}{% endblock %} 3 | -------------------------------------------------------------------------------- /testing/templates/base.html: -------------------------------------------------------------------------------- 1 | {{ title }} 2 | {% block content %}{% endblock %} 3 | {% block foo %}Foo{% endblock %} 4 | Copyright 2017 5 | -------------------------------------------------------------------------------- /testing/templates/child.html: -------------------------------------------------------------------------------- 1 | {% extends "base.html" %} 2 | {% block content %}({{ title }}) Content goes here{% endblock content %} 3 | -------------------------------------------------------------------------------- /testing/templates/include-extends.html: -------------------------------------------------------------------------------- 1 |
| {{ col|escape }} | {% endfor %}
Below me is the header
3 | {% block header %}{% endblock %} 4 |Above me is the header
5 |Parent body content
6 | {% endblock %} 7 | {% block other_body %}{% endblock %} 8 | 9 | 10 | -------------------------------------------------------------------------------- /testing/templates/match-opt-bool.html: -------------------------------------------------------------------------------- 1 | {% match item %} 2 | {% when Some with (true) %} 3 | Found Some(true) 4 | {% when Some with (false) %} 5 | Found Some(false) 6 | {% when None %} 7 | Not Found 8 | {% endmatch %} 9 | -------------------------------------------------------------------------------- /testing/templates/precedence-for.html: -------------------------------------------------------------------------------- 1 | {% for s in strings %} 2 | {{- loop.index0 }}. {{ s }}{{ 2 * loop.index }}{% if !loop.first %}{% else %} (first){% endif %}{% if loop.last %} (last){% endif %} 3 | {% endfor %} 4 | -------------------------------------------------------------------------------- /testing/templates/fragment-include.html: -------------------------------------------------------------------------------- 1 | {% extends "fragment-base.html" %} 2 | 3 | {% block body %} 4 | {% include "included.html" %} 5 | {% endblock %} 6 | 7 | {% block other_body %} 8 |Don't render me.
9 | {% endblock %} -------------------------------------------------------------------------------- /testing/tests/ui/lit_on_assignment_lhs.rs: -------------------------------------------------------------------------------- 1 | use askama::Template; 2 | 3 | #[derive(Template)] 4 | #[template( 5 | source = "{%let 7=x%}", 6 | ext = "txt" 7 | )] 8 | struct MyTemplate; 9 | 10 | fn main() { 11 | } 12 | -------------------------------------------------------------------------------- /testing/templates/fragment-mid-super.html: -------------------------------------------------------------------------------- 1 | {% extends "fragment-base.html" %} 2 | 3 | {% block body %} 4 | [{% call super() %}] 5 | {% endblock %} 6 | 7 | {% block other_body %} 8 | ({% call super() %}) 9 | {% endblock %} 10 | -------------------------------------------------------------------------------- /testing/tests/ui/name_mismatch_endblock.rs: -------------------------------------------------------------------------------- 1 | use askama::Template; 2 | 3 | #[derive(Template)] 4 | #[template(source = "{% block foo %}{% endblock not_foo %}", ext = "html")] 5 | struct NameMismatchEndBlock; 6 | 7 | fn main() { 8 | } 9 | -------------------------------------------------------------------------------- /askama_parser/benches/librustdoc/item_info.html: -------------------------------------------------------------------------------- 1 | {% if !items.is_empty() %} 2 | 3 | {% for item in items %} 4 | {{item|safe}} {# #} 5 | {% endfor %} 6 | 7 | {% endif %} 8 | -------------------------------------------------------------------------------- /testing/templates/fragment-simple.html: -------------------------------------------------------------------------------- 1 | {% extends "fragment-base.html" %} 2 | 3 | {% block body %} 4 |Hello {{ name }}!
5 | {% endblock %} 6 | 7 | {% block other_body %} 8 |Don't render me.
9 | {% endblock %} 10 | -------------------------------------------------------------------------------- /testing/templates/blocks.txt: -------------------------------------------------------------------------------- 1 | {% block index %} 2 | Section: {{ s1 }} 3 | {% endblock %} 4 | 5 | {% block section -%} 6 | [ 7 | {%- for value in values -%} 8 | {{ value }} 9 | {%- endfor -%} 10 | ] 11 | {%- endblock %} 12 | -------------------------------------------------------------------------------- /testing/templates/match-enum-or.html: -------------------------------------------------------------------------------- 1 | The card is 2 | {%- match suit %} 3 | {%- when Suit::Clubs or Suit::Spades -%} 4 | {{ " black" }} 5 | {%- when Suit::Diamonds or Suit::Hearts -%} 6 | {{ " red" }} 7 | {%- endmatch %} 8 | 9 | -------------------------------------------------------------------------------- /testing/tests/ui/name_mismatch_endmacro.rs: -------------------------------------------------------------------------------- 1 | use askama::Template; 2 | 3 | #[derive(Template)] 4 | #[template(source = "{% macro foo(arg) %} {{arg}} {% endmacro not_foo %}", ext = "html")] 5 | struct NameMismatchEndMacro; 6 | 7 | fn main() { 8 | } 9 | -------------------------------------------------------------------------------- /testing/tests/ui/break_outside_of_loop.rs: -------------------------------------------------------------------------------- 1 | use askama::Template; 2 | 3 | #[derive(Template)] 4 | #[template( 5 | source = "Have a {%break%}, have a parsing error!", 6 | ext = "txt" 7 | )] 8 | struct MyTemplate; 9 | 10 | fn main() { 11 | } 12 | -------------------------------------------------------------------------------- /testing/templates/deep-kid.html: -------------------------------------------------------------------------------- 1 | {% extends "deep-mid.html" %} 2 | {% import "macro.html" as libk %} 3 | 4 | {% block head %} 5 | 6 | {% endblock %} 7 | 8 | {% block content %} 9 | {% call libk::thrice(item) %} 10 | {% endblock %} 11 | -------------------------------------------------------------------------------- /testing/templates/nested-macro-args.html: -------------------------------------------------------------------------------- 1 | {%- macro outer(first) -%} 2 | {%- call inner(first, "second") -%} 3 | {%- endmacro -%} 4 | 5 | {%- macro inner(first, second) -%} 6 | {{ first }} {{ second }} 7 | {%- endmacro -%} 8 | 9 | {%- call outer("first") -%} 10 | -------------------------------------------------------------------------------- /testing/templates/nested-macro.html: -------------------------------------------------------------------------------- 1 | {%- macro child0() -%} 2 | foo 3 | {%- endmacro -%} 4 | 5 | {%- macro child1() -%} 6 | {% call child0() %} 7 | {%- endmacro -%} 8 | 9 | {%- macro parent() -%} 10 | {% call child1() %} 11 | {%- endmacro -%} 12 | -------------------------------------------------------------------------------- /testing/templates/for.html: -------------------------------------------------------------------------------- 1 | {% for s in strings %} 2 | {{- loop.index0 }}. {{ s }}{% if loop.first %} (first){% endif %} 3 | {% endfor %} 4 | {% for (s1, s2, ) in tuple_strings %} 5 | {{- loop.index0 }}. {{ s1 }},{{ s2 }}{% if loop.first %} (first){% endif %} 6 | {% endfor %} 7 | -------------------------------------------------------------------------------- /testing/tests/ui/filter_block_ws.rs: -------------------------------------------------------------------------------- 1 | use askama::Template; 2 | 3 | #[derive(Template)] 4 | #[template(source = "{% filter lower|indent(2) - %} 5 | HELLO 6 | {{v}} 7 | {%- endfilter %}", ext = "html")] 8 | struct A; 9 | 10 | fn main() { 11 | A.render().unwrap(); 12 | } 13 | -------------------------------------------------------------------------------- /testing/tests/ui/loop_cycle_empty.rs: -------------------------------------------------------------------------------- 1 | use askama::Template; 2 | 3 | #[derive(Template)] 4 | #[template( 5 | source = r#"{% for v in values %}{{ loop.cycle([]) }}{{ v }},{% endfor %}"#, 6 | ext = "txt" 7 | )] 8 | struct ForCycleEmpty; 9 | 10 | fn main() { 11 | } 12 | -------------------------------------------------------------------------------- /testing/templates/fragment-super.html: -------------------------------------------------------------------------------- 1 | {% extends "fragment-base.html" %} 2 | 3 | {% block body %} 4 |Hello {{ name }}!
5 | {% call super() %} 6 | {% endblock %} 7 | 8 | {% block other_body %} 9 |Don't render me.
10 | {% call super() %} 11 | {% endblock %} 12 | 13 | -------------------------------------------------------------------------------- /testing/tests/ui/typo_in_keyword.rs: -------------------------------------------------------------------------------- 1 | use askama::Template; 2 | 3 | #[derive(Template)] 4 | #[template( 5 | source = "{%for i in 1..=10%}{{i}}{%endfo%}\n1234567890123456789012345678901234567890", 6 | ext = "txt" 7 | )] 8 | struct MyTemplate; 9 | 10 | fn main() { 11 | } 12 | -------------------------------------------------------------------------------- /testing/templates/fragment-unused-expr.html: -------------------------------------------------------------------------------- 1 | {% extends "fragment-base.html" %} 2 | 3 | {{ not_required }} 4 | 5 | {% block body %} 6 |{{ required }}
7 | {% endblock %} 8 | 9 | {% block other_body %} 10 | {{ not_required_2 }} 11 |Don't render me.
12 | {% endblock %} 13 | -------------------------------------------------------------------------------- /testing/templates/macro-import-str-cmp.html: -------------------------------------------------------------------------------- 1 | {%- import "macro-import-str-cmp-macro.html" as macros -%} 2 | 3 | A 4 | 5 | {%- call macros::strcmp("foo") -%} 6 | 7 | B 8 | 9 | {%- call macros::strcmp("bar") -%} 10 | 11 | C 12 | 13 | {%- call macros::strcmp("cat") -%} 14 | 15 | D 16 | -------------------------------------------------------------------------------- /fuzz/README.md: -------------------------------------------------------------------------------- 1 | # Fuzzing 2 | 3 | Install `cargo-fuzz`: 4 | 5 | ```sh 6 | cargo install -f cargo-fuzz 7 | ``` 8 | 9 | Run any available target where `$target` is the name of the target. 10 | 11 | ```sh 12 | cargo fuzz list # get list of targets 13 | cargo +nightly fuzz run $target 14 | ``` -------------------------------------------------------------------------------- /testing/tests/ui/duplicated_template_attribute.rs: -------------------------------------------------------------------------------- 1 | use askama::Template; 2 | 3 | #[derive(Template)] 4 | #[template( 5 | source = "🙂", 6 | ext = "txt" 7 | )] 8 | #[template( 9 | source = "🙃", 10 | ext = "txt" 11 | )] 12 | struct TwoEmojis; 13 | 14 | fn main() { 15 | } 16 | -------------------------------------------------------------------------------- /testing/templates/fragment-nested-super.html: -------------------------------------------------------------------------------- 1 | {% extends "fragment-mid-super.html" %} 2 | 3 | {% block body %} 4 |Hello {{ name }}!
5 | {% call super() %} 6 | {% endblock %} 7 | 8 | {% block other_body %} 9 |Don't render me.
10 | {% call super() %} 11 | {% endblock %} 12 | 13 | -------------------------------------------------------------------------------- /testing/templates/rust-macro-args.html: -------------------------------------------------------------------------------- 1 | {{ call_a_or_b_on_tail!((a: year, b: month, c: day), call a: 2021, "July", (0+2)) }} 2 | {{ call_a_or_b_on_tail!((a: year, b: month, c: day), call b: 2021, "July", (0+2)) }} 3 | {{ call_a_or_b_on_tail!((a: year, b: day, c: month), call b: 2021, "July", (0+2)) }} 4 | -------------------------------------------------------------------------------- /testing/templates/macro-no-args.html: -------------------------------------------------------------------------------- 1 | 1 2 | 3 | {%- macro empty -%} 4 | the best thing 5 | {%- endmacro -%} 6 | 7 | 1 8 | 9 | {%- call empty() -%} 10 | 11 | 1 12 | 13 | {%- macro whole() -%} 14 | we've ever done 15 | {%- endmacro -%} 16 | 17 | 11 18 | 19 | {%- call whole -%} 20 | 21 | 11 22 | -------------------------------------------------------------------------------- /testing/tests/ui/block_and_vars.rs: -------------------------------------------------------------------------------- 1 | use askama::Template; 2 | 3 | #[derive(Template)] 4 | #[template(source = r#"{% extends "extend_and_import.html" %} 5 | 6 | {% let x = 12 %} 7 | {% block header -%} 8 | {{ x }} 9 | {% endblock %}"#, ext = "html")] 10 | struct A; 11 | 12 | fn main() { 13 | } 14 | -------------------------------------------------------------------------------- /testing/templates/macro-short-circuit.html: -------------------------------------------------------------------------------- 1 | {% macro foo(b) -%} 2 | {{ b }} 3 | {%- endmacro -%} 4 | {% call foo(true) -%} 5 | {% call foo(true && true) -%} 6 | {% call foo(true && true && true) -%} 7 | {% call foo(false) -%} 8 | {% call foo(false || true) -%} 9 | {% call foo(false || false || true) -%} 10 | -------------------------------------------------------------------------------- /testing/templates/fragment-nested-block.html: -------------------------------------------------------------------------------- 1 | {% extends "fragment-base.html" %} 2 | 3 | {% block body %} 4 |Don't render me!
5 | {% block nested %} 6 |I should be here.
7 | {% endblock %} 8 | {% endblock %} 9 | 10 | {% block other_body %} 11 |Don't render me!
12 | {% endblock %} 13 | 14 | -------------------------------------------------------------------------------- /testing/templates/match-option-result-option.html: -------------------------------------------------------------------------------- 1 | {%- match foo -%} 2 | {%- when None -%} 3 | nothing 4 | {%- when Some(Err(err)) -%} 5 | err={{err}} 6 | {%- when Some(Ok(None)) -%} 7 | num=absent 8 | {%- when Some(Ok(Some(num))) -%} 9 | num={{num}} 10 | {%- endmatch -%} 11 | -------------------------------------------------------------------------------- /testing/tests/ui/block_and_vars.stderr: -------------------------------------------------------------------------------- 1 | error[E0609]: no field `x` on type `&A` 2 | --> tests/ui/block_and_vars.rs:3:10 3 | | 4 | 3 | #[derive(Template)] 5 | | ^^^^^^^^ unknown field 6 | | 7 | = note: this error originates in the derive macro `Template` (in Nightly builds, run with -Z macro-backtrace for more info) 8 | -------------------------------------------------------------------------------- /testing/tests/ui/loop_cycle_empty.stderr: -------------------------------------------------------------------------------- 1 | error: loop.cycle(…) cannot use an empty array 2 | --> tests/ui/loop_cycle_empty.rs:3:10 3 | | 4 | 3 | #[derive(Template)] 5 | | ^^^^^^^^ 6 | | 7 | = note: this error originates in the derive macro `Template` (in Nightly builds, run with -Z macro-backtrace for more info) 8 | -------------------------------------------------------------------------------- /testing/tests/ui/no_template_attribute.stderr: -------------------------------------------------------------------------------- 1 | error: no attribute 'template' found 2 | --> tests/ui/no_template_attribute.rs:3:10 3 | | 4 | 3 | #[derive(Template)] 5 | | ^^^^^^^^ 6 | | 7 | = note: this error originates in the derive macro `Template` (in Nightly builds, run with -Z macro-backtrace for more info) 8 | -------------------------------------------------------------------------------- /deny.toml: -------------------------------------------------------------------------------- 1 | [licenses] 2 | version = 2 3 | allow = ["Apache-2.0", "BSD-2-Clause", "BSD-3-Clause", "ISC", "MIT", "Unicode-3.0", "Unicode-DFS-2016"] 4 | private = { ignore = true } 5 | 6 | [[licenses.clarify]] 7 | name = "ring" 8 | expression = "ISC AND MIT AND OpenSSL" 9 | license-files = [{ path = "LICENSE", hash = 0xbd0eed23 }] 10 | -------------------------------------------------------------------------------- /fuzz/fuzz_targets/fuzz_parser.rs: -------------------------------------------------------------------------------- 1 | #![no_main] 2 | use askama_parser::*; 3 | use libfuzzer_sys::fuzz_target; 4 | 5 | fuzz_target!(|data: &[u8]| { 6 | // fuzzed code goes here 7 | if let Ok(data) = std::str::from_utf8(data) { 8 | let _ = Ast::from_str(data, None, &Syntax::default()).is_ok(); 9 | } 10 | }); 11 | -------------------------------------------------------------------------------- /testing/templates/deep-base.html: -------------------------------------------------------------------------------- 1 | {% import "macro.html" as libb %} 2 | 3 | 4 | {% block head %} 5 | 6 | {% endblock %} 7 | 8 | 9 | {% block body %} 10 | {% call libb::thrice("nav") %} 11 | Copyright {{ year }} 12 | {% endblock %} 13 | 14 | 15 | -------------------------------------------------------------------------------- /testing/templates/if-let-with-for.html: -------------------------------------------------------------------------------- 1 | {%- if let Some(thing) = thing -%} 2 | {%- for item in thing.items -%} 3 | {{ item }} 4 | {%- endfor -%} 5 | {%- endif -%} 6 | 7 | {%- if let Some(thing) = thing -%} 8 | {%- for item in thing.items -%} 9 | {{ item }} 10 | {%- endfor -%} 11 | {%- endif -%} 12 | -------------------------------------------------------------------------------- /testing/tests/ui/loop_cycle_wrong_argument_count.rs: -------------------------------------------------------------------------------- 1 | use askama::Template; 2 | 3 | #[derive(Template)] 4 | #[template( 5 | source = r#"{% for v in values %}{{ loop.cycle("r", "g", "b") }}{{ v }},{% endfor %}"#, 6 | ext = "txt" 7 | )] 8 | struct ForCycle<'a> { 9 | values: &'a [u8], 10 | } 11 | 12 | fn main() { 13 | } 14 | -------------------------------------------------------------------------------- /testing/tests/ui/duplicated_template_attribute.stderr: -------------------------------------------------------------------------------- 1 | error: duplicated 'template' attribute 2 | --> tests/ui/duplicated_template_attribute.rs:3:10 3 | | 4 | 3 | #[derive(Template)] 5 | | ^^^^^^^^ 6 | | 7 | = note: this error originates in the derive macro `Template` (in Nightly builds, run with -Z macro-backtrace for more info) 8 | -------------------------------------------------------------------------------- /testing/templates/for-break-continue.html: -------------------------------------------------------------------------------- 1 | {%- for v in values -%} 2 | x {{- v -}} 3 | {%- if matches!(v, x if *x > 9) -%} 4 | {%- if matches!(v, x if *x % 2 == 0) -%} 5 | {%- break -%} 6 | {%- else -%} 7 | {%- continue -%} 8 | {%- endif -%} 9 | {%- endif -%} 10 | y 11 | {%- endfor -%} 12 | -------------------------------------------------------------------------------- /testing/tests/ui/loop_cycle_wrong_argument_count.stderr: -------------------------------------------------------------------------------- 1 | error: loop.cycle(…) expects exactly one argument 2 | --> $DIR/loop_cycle_wrong_argument_count.rs:3:10 3 | | 4 | 3 | #[derive(Template)] 5 | | ^^^^^^^^ 6 | | 7 | = note: this error originates in the derive macro `Template` (in Nightly builds, run with -Z macro-backtrace for more info) 8 | -------------------------------------------------------------------------------- /testing/templates/for-range.html: -------------------------------------------------------------------------------- 1 | {% for s in 0..2 -%} 2 | foo{% if loop.first %} (first){% endif %}{% if loop.last %} (last){% endif %} 3 | {% endfor -%} 4 | 5 | {% for s in init..1 -%} 6 | bar 7 | {% endfor -%} 8 | 9 | {% for s in 0..end -%} 10 | foo 11 | {% endfor -%} 12 | 13 | {% for s in init..end -%} 14 | bar 15 | {% endfor -%} 16 | -------------------------------------------------------------------------------- /testing/templates/macro-import-str-cmp-macro.html: -------------------------------------------------------------------------------- 1 | {% macro strcmp0(s, other) -%} 2 | {%- if s == "foo" -%} 3 | foo 4 | {%- else if s == other -%} 5 | other 6 | {%- else -%} 7 | neither 8 | {%- endif -%} 9 | {% endmacro %} 10 | 11 | {% macro strcmp(s) %} 12 | {%- call strcmp0(s, "bar") -%} 13 | {% endmacro %} 14 | -------------------------------------------------------------------------------- /testing/templates/named-end.html: -------------------------------------------------------------------------------- 1 | {% extends "base.html" %} 2 | {# Testing named "endmacro" #} 3 | {% macro foo(b) -%} 4 | {% if b %}t{% else %}f{% endif -%} 5 | {% endmacro foo -%} 6 | {# Testing named endblock declaration #} 7 | {% block what %}{% endblock what %} 8 | {# Testing named endblock call #} 9 | {% block foo %}tadam{% endblock foo %} 10 | -------------------------------------------------------------------------------- /testing/tests/ui/lit_on_assignment_lhs.stderr: -------------------------------------------------------------------------------- 1 | error: literals are not allowed on the left-hand side of an assignment 2 | --> tests/ui/lit_on_assignment_lhs.rs:3:10 3 | | 4 | 3 | #[derive(Template)] 5 | | ^^^^^^^^ 6 | | 7 | = note: this error originates in the derive macro `Template` (in Nightly builds, run with -Z macro-backtrace for more info) 8 | -------------------------------------------------------------------------------- /testing/tests/coerce.rs: -------------------------------------------------------------------------------- 1 | use askama::Template; 2 | 3 | #[derive(Template)] 4 | #[template(path = "if-coerce.html")] 5 | struct IfCoerceTemplate { 6 | t: bool, 7 | f: bool, 8 | } 9 | 10 | #[test] 11 | fn test_coerce() { 12 | let t = IfCoerceTemplate { t: true, f: false }; 13 | assert_eq!(t.render().unwrap(), "ftftfttftelseifelseif"); 14 | } 15 | -------------------------------------------------------------------------------- /testing/templates/macro.html: -------------------------------------------------------------------------------- 1 | 1 2 | 3 | {%- macro thrice(param) -%} 4 | 5 | {{ param }} {{ param }} {{ param }} 6 | 7 | {%- endmacro -%} 8 | 9 | 2 10 | 11 | {%- call thrice(s) -%} 12 | 13 | 3 14 | 15 | {%- macro twice(param) -%} 16 | 17 | {{ param }} {{ param }} 18 | 19 | {%- endmacro twice -%} 20 | 21 | 4 22 | 23 | {%- call twice(s) -%} 24 | 25 | 5 26 | -------------------------------------------------------------------------------- /testing/templates/match-custom-enum.html: -------------------------------------------------------------------------------- 1 | {% match color %} 2 | {% when Color::Rgb with {r, g: g, b: blue} %} 3 | Colorful: #{{ "{:02X}"|format(r) }}{{ "{:02X}"|format(g) }}{{ "{:02X}"|format(blue) }} 4 | {% when Color::GrayScale with (val) %} 5 | Gray: #{{ "{:02X}"|format(val) }}{{ "{:02X}"|format(val) }}{{ "{:02X}"|format(val) }} 6 | {% else %} 7 | CMYK not supported 8 | {% endmatch %} 9 | -------------------------------------------------------------------------------- /askama_parser/benches/librustdoc/type_layout_size.html: -------------------------------------------------------------------------------- 1 | {% if is_unsized %} 2 | (unsized) 3 | {% else %} 4 | {% if size == 1 %} 5 | 1 byte 6 | {% else %} 7 | {{ size +}} bytes 8 | {% endif %} 9 | {% if is_uninhabited %} 10 | {# +#} (uninhabited) 11 | {% endif %} 12 | {% endif %} 13 | -------------------------------------------------------------------------------- /testing/templates/teams.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
5 | {% for line in lines.clone() %}
6 | {% if embedded %}
7 | {{line|safe}}
8 | {%~ else %}
9 | {{line|safe}}
10 | {%~ endif %}
11 | {% endfor %}
12 | {# #}
14 |
15 | {% if needs_expansion %}
16 |
17 | {% endif %}
18 | {{code_html|safe}}
19 | {# #}
20 | {# #}
21 | {{feature}} {# #}
13 | {% match tracking %}
14 | {% when Some with ((url, num)) %}
15 | #{{num}} {# #}
16 | {% when None %}
17 | {% endmatch %}
18 | ) {# #}
19 | {# #}
20 |
2 | {{ self.render_attributes_in_pre()|safe }}
3 | {{ self.render_union()|safe }}
4 |
5 | {{ self.document()|safe }}
6 | {% if self.fields_iter().peek().is_some() %}
7 | {{ name }}: {{+ self.print_ty(ty)|safe }} {# #}
16 |
17 | {% if let Some(stability_class) = self.stability_field(field) %}
18 |
19 | {% endif %}
20 | {{ self.document_field(field)|safe }}
21 | {% endfor %}
22 | {% endif %}
23 | {{ self.render_assoc_items()|safe }}
24 | {{ self.document_type_layout()|safe }}
25 |
--------------------------------------------------------------------------------
/testing/tests/size_hint.rs:
--------------------------------------------------------------------------------
1 | use askama::Template;
2 |
3 | macro_rules! test_size {
4 | ($source:literal, $expected:expr) => {{
5 | #[derive(Template)]
6 | #[allow(dead_code)]
7 | #[template(source = $source, ext = "txt")]
8 | struct T(bool);
9 |
10 | assert_eq!(T::SIZE_HINT, $expected);
11 | }};
12 | }
13 |
14 | #[test]
15 | fn test_cond_size_hint() {
16 | test_size!("{% if self.0 %}12345{% else %}12345{% endif %}", 10);
17 | }
18 |
19 | #[test]
20 | fn test_match_size_hint() {
21 | test_size!(
22 | "{% match self.0 %}{% when true %}12345{% else %}12345{% endmatch %}",
23 | 5
24 | );
25 | }
26 |
27 | #[test]
28 | fn test_loop_size_hint() {
29 | test_size!("{% for i in 0..1 %}12345{% endfor %}", 7);
30 | }
31 |
32 | #[test]
33 | fn test_block_size_hint() {
34 | #[derive(Template)]
35 | #[template(path = "size-child.txt")]
36 | struct T;
37 |
38 | assert_eq!(T::SIZE_HINT, 3);
39 | }
40 |
41 | #[test]
42 | fn test_super_size_hint() {
43 | #[derive(Template)]
44 | #[template(path = "size-child-super.txt")]
45 | struct T;
46 |
47 | assert_eq!(T::SIZE_HINT, 5);
48 | }
49 |
--------------------------------------------------------------------------------
/testing/tests/ui.rs:
--------------------------------------------------------------------------------
1 | #![cfg(not(windows))]
2 |
3 | use std::os::unix::fs::symlink;
4 | use std::path::Path;
5 | use trybuild::TestCases;
6 |
7 | #[test]
8 | fn ui() {
9 | let t = TestCases::new();
10 | t.compile_fail("tests/ui/*.rs");
11 |
12 | // To be able to use existing templates, we create a link to the `templates` folder.
13 | let manifest_dir = match std::env::var("CARGO_MANIFEST_DIR") {
14 | Ok(manifest_dir) => manifest_dir,
15 | Err(_) => panic!("you need to run tests with `cargo`"),
16 | };
17 | let target = Path::new(&manifest_dir).join("../target/tests/trybuild/askama_testing");
18 | if !target.exists() {
19 | if let Err(err) = std::fs::create_dir_all(&target) {
20 | panic!("failed to create folder `{}`: {err:?}", target.display());
21 | }
22 | }
23 | let target = target.canonicalize().unwrap().join("templates");
24 | if target.exists() {
25 | return;
26 | }
27 | let original = Path::new(&manifest_dir).join("templates");
28 | if symlink(&original, &target).is_err() {
29 | panic!(
30 | "failed to create to create link on `{}` as `{}`",
31 | original.display(),
32 | target.display()
33 | );
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/testing/tests/ui/unclosed-nodes.rs:
--------------------------------------------------------------------------------
1 | use askama::Template;
2 |
3 | #[derive(Template)]
4 | #[template(source = "{{ expr", ext = "txt")]
5 | struct Expr1;
6 |
7 | #[derive(Template)]
8 | #[template(source = "{{ expr ", ext = "txt")]
9 | struct Expr2;
10 |
11 | #[derive(Template)]
12 | #[template(source = "{{ expr -", ext = "txt")]
13 | struct Expr3;
14 |
15 | #[derive(Template)]
16 | #[template(source = "{{ expr -}", ext = "txt")]
17 | struct Expr4;
18 |
19 | #[derive(Template)]
20 | #[template(source = "{% let x", ext = "txt")]
21 | struct Node1;
22 |
23 | #[derive(Template)]
24 | #[template(source = "{% let x ", ext = "txt")]
25 | struct Node2;
26 |
27 | #[derive(Template)]
28 | #[template(source = "{% let x -", ext = "txt")]
29 | struct Node3;
30 |
31 | #[derive(Template)]
32 | #[template(source = "{% let x -%", ext = "txt")]
33 | struct Node4;
34 |
35 | #[derive(Template)]
36 | #[template(source = "{# comment", ext = "txt")]
37 | struct Comment1;
38 |
39 | #[derive(Template)]
40 | #[template(source = "{# comment ", ext = "txt")]
41 | struct Comment2;
42 |
43 | #[derive(Template)]
44 | #[template(source = "{# comment -", ext = "txt")]
45 | struct Comment3;
46 |
47 | #[derive(Template)]
48 | #[template(source = "{# comment -#", ext = "txt")]
49 | struct Comment4;
50 |
51 | fn main() {}
52 |
--------------------------------------------------------------------------------
/askama_warp/src/lib.rs:
--------------------------------------------------------------------------------
1 | #![forbid(unsafe_code)]
2 | #![deny(elided_lifetimes_in_paths)]
3 | #![deny(unreachable_pub)]
4 |
5 | #[doc(no_inline)]
6 | pub use askama::*;
7 | #[doc(no_inline)]
8 | pub use warp;
9 | use warp::reply::Response;
10 |
11 | /// Render a [`Template`] into a [`Response`], or render an error page.
12 | pub fn into_responseBelow me is the header
\n \ 32 | foo\n \ 33 |Above me is the header
\n\ 34 | {# #}
9 | Note: Most layout information is completely {#+ #}
10 | unstable and may even differ between compilations. {#+ #}
11 | The only exception is types with certain repr(...) {#+ #}
12 | attributes. Please see the Rust Reference's {#+ #}
13 | “Type Layout” {#+ #}
14 | chapter for details on type layout guarantees. {# #}
15 |
Size: {{+ type_layout_size|safe }}
{# #} 18 | {% if !variants.is_empty() %} 19 |{# #} 20 | Size for each variant: {# #} 21 |
{# #} 22 |{{ name }}: {#+ #}
26 | {{ layout_size|safe }}
27 | {# #} 35 | Note: Unable to compute type layout, {#+ #} 36 | possibly due to this type having generic parameters. {#+ #} 37 | Layout can only be computed for concrete, fully-instantiated types. {# #} 38 |
{# #} 39 | {# This kind of error probably can't happen with valid code, but we don't 40 | want to panic and prevent the docs from building, so we just let the 41 | user know that we couldn't compute the layout. #} 42 | {% when Err(LayoutError::SizeOverflow(_)) %} 43 |{# #} 44 | Note: Encountered an error during type layout; {#+ #} 45 | the type was too big. {# #} 46 |
{# #} 47 | {% when Err(LayoutError::ReferencesError(_)) %} 48 |{# #} 49 | Note: Encountered an error during type layout; {#+ #} 50 | the type references errors. {# #} 51 |
{# #} 52 | {% when Err(LayoutError::NormalizationFailure(_, _)) %} 53 |{# #} 54 | Note: Encountered an error during type layout; {#+ #} 55 | the type failed to be normalized. {# #} 56 |
{# #} 57 | {% when Err(LayoutError::Cycle(_)) %} 58 |{# #} 59 | Note: Encountered an error during type layout; {#+ #} 60 | the type's layout depended on the type's layout itself. {# #} 61 |
{# #} 62 | {% endmatch %} 63 |{{data|json|safe}}` is safe, too.
21 | #[inline]
22 | pub fn json