aboutsummaryrefslogtreecommitdiffstats
path: root/askama_shared/src
diff options
context:
space:
mode:
authorLibravatar larros <larserik.rosengren@gmail.com>2017-10-01 18:00:05 +0200
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2017-10-01 18:00:05 +0200
commit614ed6d16ff5aa71d0522bc819cce59a91f7164c (patch)
tree153f50a8be1ae3d4d091590dd0b97c6ff9aca44f /askama_shared/src
parent8882ec000ddbf37465afbdb337222f113bceffcd (diff)
downloadaskama-614ed6d16ff5aa71d0522bc819cce59a91f7164c.tar.gz
askama-614ed6d16ff5aa71d0522bc819cce59a91f7164c.tar.bz2
askama-614ed6d16ff5aa71d0522bc819cce59a91f7164c.zip
Fix whitespace handling for macros and imports (#55)
Resolves https://github.com/djc/askama/issues/52. * Fix of review comments
Diffstat (limited to '')
-rw-r--r--askama_shared/src/generator.rs20
1 files changed, 16 insertions, 4 deletions
diff --git a/askama_shared/src/generator.rs b/askama_shared/src/generator.rs
index a37b51f..acb3f15 100644
--- a/askama_shared/src/generator.rs
+++ b/askama_shared/src/generator.rs
@@ -353,11 +353,22 @@ impl<'a> Generator<'a> {
self.handle_include(state, ws, path);
},
Node::Call(ref ws, name, ref args) => self.write_call(state, ws, name, args),
- Node::Macro(_, _) |
- Node::Import(_, _) |
+ Node::Macro(_, ref m) => {
+ if let AstLevel::Nested = level {
+ panic!("macro blocks only allowed at the top level");
+ }
+ self.flush_ws(&m.ws1);
+ self.prepare_ws(&m.ws2);
+ },
+ Node::Import(ref ws, _) => {
+ if let AstLevel::Nested = level {
+ panic!("import blocks only allowed at the top level");
+ }
+ self.handle_ws(ws);
+ },
Node::Extends(_) => {
if let AstLevel::Nested = level {
- panic!("macro or extend blocks only allowed at the top level");
+ panic!("extend blocks only allowed at the top level");
}
},
}
@@ -436,7 +447,7 @@ impl<'a> Generator<'a> {
fn write_call(&mut self, state: &'a State, ws: &WS, name: &str, args: &[Expr]) {
let def = state.macros.get(name).expect(&format!("macro '{}' not found", name));
- self.handle_ws(ws);
+ self.flush_ws(ws);
self.locals.push();
self.writeln("{");
self.prepare_ws(&def.ws1);
@@ -451,6 +462,7 @@ impl<'a> Generator<'a> {
self.flush_ws(&def.ws2);
self.writeln("}");
self.locals.pop();
+ self.prepare_ws(ws);
}
fn handle_include(&mut self, state: &'a State, ws: &WS, path: &str) {