From 21852a33bc3c1fb6ed816ba95c5f95f88f5aa941 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Tue, 14 Feb 2017 20:38:12 +0100 Subject: Move code for whitespace handling around --- askama/src/generator.rs | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/askama/src/generator.rs b/askama/src/generator.rs index eee8bc5..f327d26 100644 --- a/askama/src/generator.rs +++ b/askama/src/generator.rs @@ -77,6 +77,26 @@ impl<'a> Generator<'a> { self.start = true; } + fn flush_ws(&mut self, ws: &WS) { + if self.next_ws.is_some() && !ws.0 { + let val = self.next_ws.unwrap(); + if !val.is_empty() { + self.writeln(&format!("writer.write_str({:#?}).unwrap();", + val)); + } + } + self.next_ws = None; + } + + fn prepare_ws(&mut self, ws: &WS) { + self.skip_ws = ws.1; + } + + fn handle_ws(&mut self, ws: &WS) { + self.flush_ws(ws); + self.prepare_ws(ws); + } + fn visit_str_lit(&mut self, s: &str) { self.write(&format!("\"{}\"", s)); } @@ -121,26 +141,6 @@ 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(); - if !val.is_empty() { - self.writeln(&format!("writer.write_str({:#?}).unwrap();", - val)); - } - } - self.next_ws = None; - } - - fn prepare_ws(&mut self, ws: &WS) { - self.skip_ws = ws.1; - } - - fn handle_ws(&mut self, ws: &WS) { - self.flush_ws(ws); - self.prepare_ws(ws); - } - fn write_lit(&mut self, lws: &'a str, val: &str, rws: &'a str) { assert!(self.next_ws.is_none()); if !lws.is_empty() { -- cgit