diff options
author | larros <larserik.rosengren@gmail.com> | 2017-09-26 10:02:44 +0200 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2017-09-26 10:02:44 +0200 |
commit | df58dcb49db77b2c283db3c9a8a738bdff3a8e37 (patch) | |
tree | 0de4a117d1e97216381b8336a1cec826e894d075 /askama_shared/src/parser.rs | |
parent | 4e919e47539b5fa346f1cac323ab250558b834bc (diff) | |
download | askama-df58dcb49db77b2c283db3c9a8a738bdff3a8e37.tar.gz askama-df58dcb49db77b2c283db3c9a8a738bdff3a8e37.tar.bz2 askama-df58dcb49db77b2c283db3c9a8a738bdff3a8e37.zip |
Add support for importing template files with macros (#51)
* Fix review comments for macro imports
Diffstat (limited to 'askama_shared/src/parser.rs')
-rw-r--r-- | askama_shared/src/parser.rs | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/askama_shared/src/parser.rs b/askama_shared/src/parser.rs index ab79a31..083e96b 100644 --- a/askama_shared/src/parser.rs +++ b/askama_shared/src/parser.rs @@ -42,6 +42,7 @@ pub enum Node<'a> { Extends(Expr<'a>), BlockDef(WS, &'a str, Vec<Node<'a>>, WS), Include(WS, &'a str), + Import(WS, &'a str), Macro(&'a str, Macro<'a>), } @@ -388,6 +389,17 @@ named!(block_include<Node>, do_parse!( })) )); +named!(block_import<Node>, do_parse!( + pws: opt!(tag_s!("-")) >> + ws!(tag_s!("import")) >> + name: ws!(expr_str_lit) >> + nws: opt!(tag_s!("-")) >> + (Node::Import(WS(pws.is_some(), nws.is_some()), match name { + Expr::StrLit(s) => s, + _ => panic!("import path must be a string literal"), + })) +)); + named!(block_macro<Node>, do_parse!( pws1: opt!(tag_s!("-")) >> ws!(tag_s!("macro")) >> @@ -420,6 +432,7 @@ named!(block_node<Node>, do_parse!( block_for | block_extends | block_include | + block_import | block_block | block_macro ) >> |