Skip to content

Commit

Permalink
Merge pull request #933 from zetaben/listof-strip
Browse files Browse the repository at this point in the history
Fix list_of helper with multi-line content
  • Loading branch information
k0kubun committed May 25, 2017
2 parents 47d88fc + 5e9be5e commit b61c6bc
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/haml/helpers.rb
Expand Up @@ -206,7 +206,7 @@ def list_of(enum, opts={}, &block)

if result.count("\n") > 1
result.gsub!("\n", "\n ")
result = "\n #{result.strip!}\n"
result = "\n #{result.strip}\n"
else
result.strip!
end
Expand Down
2 changes: 2 additions & 0 deletions test/helper_test.rb
Expand Up @@ -83,6 +83,8 @@ def test_list_of_should_render_correctly
assert_equal("<li>[1]</li>", render("= list_of([[1]]) do |i|\n = i.inspect"))
assert_equal("<li>\n <h1>Fee</h1>\n <p>A word!</p>\n</li>\n<li>\n <h1>Fi</h1>\n <p>A word!</p>\n</li>\n<li>\n <h1>Fo</h1>\n <p>A word!</p>\n</li>\n<li>\n <h1>Fum</h1>\n <p>A word!</p>\n</li>",
render("= list_of(['Fee', 'Fi', 'Fo', 'Fum']) do |title|\n %h1= title\n %p A word!"))
assert_equal("<li>\n <f>a\n \n a</f>\n</li>\n<li>\n <f>a\n \n a</f>\n</li>",
render("= list_of(['Fee', 'Fi']) do |title|\n %f>= \"a\\n\\na\""))
assert_equal("<li c='3'>1</li>\n<li c='3'>2</li>", render("= list_of([1, 2], {:c => 3}) do |i|\n = i"))
assert_equal("<li c='3'>[1]</li>", render("= list_of([[1]], {:c => 3}) do |i|\n = i.inspect"))
assert_equal("<li c='3'>\n <h1>Fee</h1>\n <p>A word!</p>\n</li>\n<li c='3'>\n <h1>Fi</h1>\n <p>A word!</p>\n</li>\n<li c='3'>\n <h1>Fo</h1>\n <p>A word!</p>\n</li>\n<li c='3'>\n <h1>Fum</h1>\n <p>A word!</p>\n</li>",
Expand Down

0 comments on commit b61c6bc

Please sign in to comment.