From c023c35a1a4795ebe7e700823c880566007c4c76 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Mon, 2 Apr 2018 21:31:46 +0200 Subject: Fix whitespace handling for include blocks (fixes #69) --- askama_shared/src/generator.rs | 4 ++-- testing/templates/include.html | 2 +- testing/tests/include.rs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/askama_shared/src/generator.rs b/askama_shared/src/generator.rs index 7462af9..bec3437 100644 --- a/askama_shared/src/generator.rs +++ b/askama_shared/src/generator.rs @@ -512,7 +512,7 @@ impl<'a> Generator<'a> { } fn handle_include(&mut self, state: &'a State, ws: &WS, path: &str) { - self.prepare_ws(ws); + self.flush_ws(ws); let path = path::find_template_from_path(path, Some(&state.input.path)); let src = path::get_template_source(&path); let nodes = parser::parse(&src); @@ -522,7 +522,7 @@ impl<'a> Generator<'a> { gen.buf }; self.buf.push_str(&nested); - self.flush_ws(ws); + self.prepare_ws(ws); } fn write_let_decl(&mut self, ws: &WS, var: &'a Target) { diff --git a/testing/templates/include.html b/testing/templates/include.html index cdafbad..561bcac 100644 --- a/testing/templates/include.html +++ b/testing/templates/include.html @@ -1,3 +1,3 @@ -{% for s in strs -%} +{% for s in strs %} {% include "included.html" %} {%- endfor %} diff --git a/testing/tests/include.rs b/testing/tests/include.rs index f474c55..f0158d7 100644 --- a/testing/tests/include.rs +++ b/testing/tests/include.rs @@ -13,5 +13,5 @@ struct IncludeTemplate<'a> { fn test_include() { let strs = vec!["foo", "bar"]; let s = IncludeTemplate { strs: &strs }; - assert_eq!(s.render().unwrap(), "INCLUDED: fooINCLUDED: bar") + assert_eq!(s.render().unwrap(), "\n INCLUDED: foo\n INCLUDED: bar") } -- cgit