From 1a30396d30f6875b4e541de7736b5316dcbe79dc Mon Sep 17 00:00:00 2001 From: Richard Michael Date: Tue, 7 Feb 2012 14:50:54 -0500 Subject: [PATCH] Make inner whitespace nuke consistent with loops. %ul< - for str in %w[foo bar baz] = str See #465 for discussion. Closes #489. Signed-off-by: Norman Clarke --- CHANGELOG.md | 3 +++ lib/haml/compiler.rb | 16 ++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d83271fc..bcbb587e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,9 @@ * html2haml now includes an `--html-attributes` option. (thanks [Stefan Natchev](https://github.com/snatchev)) +* Fix for inner whitespace removal in loops. + (thanks [Richard Michael](https://github.com/richardkmichael)) + ## 3.1.5 (Unreleased) * Respect Rails' `html_safe` flag when escaping attribute values diff --git a/lib/haml/compiler.rb b/lib/haml/compiler.rb index dee806c0..fbf5a365 100755 --- a/lib/haml/compiler.rb +++ b/lib/haml/compiler.rb @@ -53,10 +53,22 @@ END push_text @node.value[:text] end + def nuke_inner_whitespace?(node) + if node.value && node.value[:nuke_inner_whitespace] + true + elsif node.parent + nuke_inner_whitespace?(node.parent) + else + false + end + end + def compile_script(&block) push_script(@node.value[:text], - :preserve_script => @node.value[:preserve], - :escape_html => @node.value[:escape_html], &block) + :preserve_script => @node.value[:preserve], + :escape_html => @node.value[:escape_html], + :nuke_inner_whitespace => nuke_inner_whitespace?(@node), + &block) end def compile_silent_script