Permalink
Browse files

Padding in front of sections should not be placed inside the section

  • Loading branch information...
1 parent 0f89d73 commit 69dcd253450c2756a4570fedea4c60f20b9fe726 @judofyr judofyr committed Mar 5, 2011
Showing with 10 additions and 3 deletions.
  1. +3 −3 lib/mustache/parser.rb
  2. +7 −0 test/mustache_test.rb
@@ -139,6 +139,8 @@ def scan_tags
error "Illegal content in tag" if content.empty?
fetch = [:mustache, :fetch, content.split('.')]
+ prev = @result
+ last_index = @result.size
# Based on the sigil, do what needs to be done.
case type
@@ -147,13 +149,11 @@ def scan_tags
@result << [:mustache, :section, fetch, block]
@sections << [content, position, @result]
@result = block
- last_index = 1
when '^'
block = [:multi]
@result << [:mustache, :inverted_section, fetch, block]
@sections << [content, position, @result]
@result = block
- last_index = 1
when '/'
section, pos, result = @sections.pop
raw = @scanner.pre_match[pos[3]...pre_match_position] + padding
@@ -196,7 +196,7 @@ def scan_tags
if @scanner.peek(1) == "\n" && SKIP_WHITESPACE.include?(type)
@scanner.skip(/[ \t]*\n/)
else
- @result.insert(last_index, [:static, padding]) unless padding.empty?
+ prev.insert(last_index, [:static, padding]) unless padding.empty?
end
end
@@ -81,6 +81,13 @@ def test_sassier_single_line_sections
assert_equal "", instance.render
end
+ def test_padding_before_section
+ instance = Mustache.new
+ instance.template = "\t{{#list}}a{{/list}}"
+
+ assert_equal "\taa", instance.render(:list => [1, 2])
+ end
+
def test_two_line_sections
html = %(<p class="flash-notice" {{# no_flash }}style="display: none;"\n{{/ no_flash }}>)

0 comments on commit 69dcd25

Please sign in to comment.