From 83495979704fb8e8b818dc41db4a1801067daac2 Mon Sep 17 00:00:00 2001 From: Pieter van de Bruggen Date: Sun, 20 Mar 2011 11:41:43 -0700 Subject: [PATCH] Passing v1.1.2 of the Mustache spec. --- ext/spec | 2 +- lib/mustache/generator.rb | 12 +++++++++--- lib/mustache/parser.rb | 2 +- test/parser_test.rb | 15 ++++++++++----- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/ext/spec b/ext/spec index bf563828..bf6288ed 160000 --- a/ext/spec +++ b/ext/spec @@ -1 +1 @@ -Subproject commit bf563828a51a489483b39ff9c6aaff7e75305492 +Subproject commit bf6288ed6bd0ce8ccea6f1dac070b3d779132c3b diff --git a/lib/mustache/generator.rb b/lib/mustache/generator.rb index 0c88d48c..43554ef0 100644 --- a/lib/mustache/generator.rb +++ b/lib/mustache/generator.rb @@ -90,7 +90,7 @@ def compile!(exp) # Callback fired when the compiler finds a section token. We're # passed the section name and the array of tokens. - def on_section(name, content, raw) + def on_section(name, content, raw, delims) # Convert the tokenized content of this section into a Ruby # string we can use. code = compile(content) @@ -102,7 +102,13 @@ def on_section(name, content, raw) if v == true #{code} elsif v.is_a?(Proc) - Mustache::Template.new(v.call(#{raw.inspect}).to_s).render(ctx.dup) + t = Mustache::Template.new(v.call(#{raw.inspect}).to_s) + def t.tokens(src=@source) + p = Parser.new + p.otag, p.ctag = #{delims.inspect} + p.compile(src) + end + t.render(ctx.dup) else # Shortcut when passed non-array v = [v] unless v.is_a?(Array) || defined?(Enumerator) && v.is_a?(Enumerator) @@ -115,7 +121,7 @@ def on_section(name, content, raw) # Fired when we find an inverted section. Just like `on_section`, # we're passed the inverted section name and the array of tokens. - def on_inverted_section(name, content, raw) + def on_inverted_section(name, content, raw, _) # Convert the tokenized content of this section into a Ruby # string we can use. code = compile(content) diff --git a/lib/mustache/parser.rb b/lib/mustache/parser.rb index 25ce1be4..705419ba 100644 --- a/lib/mustache/parser.rb +++ b/lib/mustache/parser.rb @@ -157,7 +157,7 @@ def scan_tags when '/' section, pos, result = @sections.pop raw = @scanner.pre_match[pos[3]...pre_match_position] + padding - (@result = result).last << raw + (@result = result).last << raw << [self.otag, self.ctag] if section.nil? error "Closing unopened #{content.inspect}" diff --git a/test/parser_test.rb b/test/parser_test.rb index e59bf9c5..48111d1c 100644 --- a/test/parser_test.rb +++ b/test/parser_test.rb @@ -35,7 +35,8 @@ def test_parser [:static, "
  • "], [:mustache, :etag, [:mustache, :fetch, ["name"]]], [:static, "
  • \n"]], - %Q'
  • {{name}}
  • \n'], + %Q'
  • {{name}}
  • \n', + %w[{{ }}]], [:mustache, :section, [:mustache, :fetch, ["link"]], @@ -45,14 +46,17 @@ def test_parser [:static, "\">"], [:mustache, :etag, [:mustache, :fetch, ["name"]]], [:static, "\n"]], - %Q'
  • {{name}}
  • \n']], - %Q'{{#first}}\n
  • {{name}}
  • \n{{/first}}\n{{#link}}\n
  • {{name}}
  • \n{{/link}}\n'], + %Q'
  • {{name}}
  • \n', + %w[{{ }}]]], + %Q'{{#first}}\n
  • {{name}}
  • \n{{/first}}\n{{#link}}\n
  • {{name}}
  • \n{{/link}}\n', + %w[{{ }}]], [:static, "\n"], [:mustache, :section, [:mustache, :fetch, ["empty"]], [:multi, [:static, "

    The list is empty.

    \n"]], - %Q'

    The list is empty.

    \n']] + %Q'

    The list is empty.

    \n', + %w[{{ }}]]] assert_equal expected, tokens end @@ -66,7 +70,8 @@ def test_raw_content_and_whitespace :section, [:mustache, :fetch, ["list"]], [:multi, [:static, "\t"]], - "\t"]] + "\t", + %w[{{ }}]]] assert_equal expected, tokens end