mirror of
https://github.com/askama-rs/askama.git
synced 2025-09-30 14:31:36 +00:00
Expand include node to template source during code generation
This commit is contained in:
parent
077c56c007
commit
47df34c0f0
@ -292,8 +292,10 @@ impl<'a> Generator<'a> {
|
||||
self.writeln("}");
|
||||
}
|
||||
|
||||
fn handle_include(&mut self, ws: &WS, src: &str) {
|
||||
fn handle_include(&mut self, ws: &WS, path: &str) {
|
||||
self.prepare_ws(ws);
|
||||
let path = path::find_template_from_path(&path, None);
|
||||
let src = path::get_template_source(&path);
|
||||
let nodes = parser::parse(&src);
|
||||
let mut gen = self.child();
|
||||
gen.handle(&nodes);
|
||||
@ -319,8 +321,8 @@ impl<'a> Generator<'a> {
|
||||
Node::BlockDef(ref ws1, name, ref block_nodes, ref ws2) => {
|
||||
self.write_block_def(ws1, name, block_nodes, ws2);
|
||||
}
|
||||
Node::Include(ref ws, ref src) => {
|
||||
self.handle_include(ws, src);
|
||||
Node::Include(ref ws, ref path) => {
|
||||
self.handle_include(ws, path);
|
||||
},
|
||||
Node::Extends(_) => {
|
||||
panic!("no extends or block definition allowed in content");
|
||||
|
@ -1,6 +1,4 @@
|
||||
use nom::{self, IResult};
|
||||
use path;
|
||||
use std::path::Path;
|
||||
use std::str;
|
||||
|
||||
#[derive(Debug)]
|
||||
@ -33,7 +31,7 @@ pub enum Node<'a> {
|
||||
Extends(Expr<'a>),
|
||||
BlockDef(WS, &'a str, Vec<Node<'a>>, WS),
|
||||
Block(WS, &'a str, WS),
|
||||
Include(WS, String),
|
||||
Include(WS, &'a str),
|
||||
}
|
||||
|
||||
pub type Cond<'a> = (WS, Option<Expr<'a>>, Vec<Node<'a>>);
|
||||
@ -325,7 +323,7 @@ named!(block_include<Node>, do_parse!(
|
||||
name: ws!(expr_str_lit) >>
|
||||
nws: opt!(tag_s!("-")) >>
|
||||
(Node::Include(WS(pws.is_some(), nws.is_some()), match name {
|
||||
Expr::StrLit(s) => path::get_template_source(Path::new(s)),
|
||||
Expr::StrLit(s) => s,
|
||||
_ => panic!("include path must be a string literal"),
|
||||
}))
|
||||
));
|
||||
|
Loading…
x
Reference in New Issue
Block a user