Skip to content

Commit

Permalink
Ensure strings are not enumerated in Ruby 1.8
Browse files Browse the repository at this point in the history
  • Loading branch information
defunkt committed Mar 1, 2011
1 parent 9c74f2e commit 006c37a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/mustache/generator.rb
Expand Up @@ -105,7 +105,7 @@ def on_section(name, content, raw)
Mustache::Template.new(v.call(#{raw.inspect}).to_s).render(ctx.dup) Mustache::Template.new(v.call(#{raw.inspect}).to_s).render(ctx.dup)
else else
# Shortcut when passed non-array # Shortcut when passed non-array
v = [v] if v.respond_to?(:has_key?) || !v.respond_to?(:map) || v.is_a?(Struct) v = [v] unless v.is_a?(Array) || defined?(Enumerator) && v.is_a?(Enumerator)
v.map { |h| ctx.push(h); r = #{code}; ctx.pop; r }.join v.map { |h| ctx.push(h); r = #{code}; ctx.pop; r }.join
end end
Expand Down
9 changes: 9 additions & 0 deletions test/mustache_test.rb
Expand Up @@ -57,6 +57,15 @@ def test_single_line_sections
assert_equal %Q'<p class="flash-notice" style="display: none;">', instance.render assert_equal %Q'<p class="flash-notice" style="display: none;">', instance.render
end end


def test_strings_as_sections_do_not_enumerate
instance = Mustache.new
instance[:contact] = "Call 1-888-FLOWERS\nAsk for Johnson."
instance.template = "{{#contact}}<div id='contact'>{{contact}}</div>{{/contact}}"

assert_equal "<div id='contact'>Call 1-888-FLOWERS\nAsk for Johnson.</div>",
instance.render
end

def test_sassy_single_line_sections def test_sassy_single_line_sections
instance = Mustache.new instance = Mustache.new
instance[:full_time] = true instance[:full_time] = true
Expand Down

0 comments on commit 006c37a

Please sign in to comment.