diff options
-rw-r--r-- | askama/src/generator.rs | 29 | ||||
-rw-r--r-- | testing/templates/comparison.html | 4 |
2 files changed, 24 insertions, 9 deletions
diff --git a/askama/src/generator.rs b/askama/src/generator.rs index 8441bca..fbfec83 100644 --- a/askama/src/generator.rs +++ b/askama/src/generator.rs @@ -124,9 +124,13 @@ impl<'a> Generator<'a> { fn flush_ws(&mut self, ws: &WS) { if self.next_ws.is_some() && !ws.0 { let val = self.next_ws.unwrap(); - self.write(&format!("writer.write_str({:#?}).unwrap();", val)); - self.next_ws = None; + if !val.is_empty() { + self.write(&format!("writer.write_str({:#?}).unwrap();", + val)); + } + } else if self.next_ws.is_some() { } + self.next_ws = None; } fn prepare_ws(&mut self, ws: &WS) { @@ -138,13 +142,24 @@ impl<'a> Generator<'a> { self.prepare_ws(ws); } - fn write_lit(&mut self, lws: &str, val: &str, rws: &'a str) { + fn write_lit(&mut self, lws: &'a str, val: &str, rws: &'a str) { assert!(self.next_ws.is_none()); - if !self.skip_ws { - self.write(&format!("writer.write_str({:#?}).unwrap();", lws)); + if !lws.is_empty() { + if self.skip_ws { + self.skip_ws = false; + } else if val.is_empty() { + assert!(rws.is_empty()); + self.next_ws = Some(lws); + } else { + self.write(&format!("writer.write_str({:#?}).unwrap();", lws)); + } + } + if !val.is_empty() { + self.write(&format!("writer.write_str({:#?}).unwrap();", val)); + } + if !rws.is_empty() { + self.next_ws = Some(rws); } - self.write(&format!("writer.write_str({:#?}).unwrap();", val)); - self.next_ws = Some(rws); } fn write_expr(&mut self, ws: &WS, s: &Expr) { diff --git a/testing/templates/comparison.html b/testing/templates/comparison.html index 71a4a7b..ea22546 100644 --- a/testing/templates/comparison.html +++ b/testing/templates/comparison.html @@ -30,9 +30,9 @@ {%- else -%} f {%- endif %} -{% if a <= b %} +{% if a <= b -%} t -{% endif -%} +{%- endif -%} {% if c <= b -%} t {%- else -%} |