[Haml] [html2haml] Support inline comments.

This commit is contained in:
Nathan Weizenbaum 2009-10-05 19:56:40 -07:00
parent 98cae30c97
commit ca96e0f559
3 changed files with 22 additions and 6 deletions

View File

@ -37,7 +37,8 @@ including the line number and the offending character.
%p
foo
The same is true for inline ERB when running in ERB mode.
The same is true for inline comments,
and inline ERB when running in ERB mode:
`<p><%= foo %></p>` will now become `%p= foo`.
* ERB included within text is now transformed into Ruby interpolation.

View File

@ -204,7 +204,11 @@ module Haml
class ::Hpricot::Comment
# @see Haml::HTML::Node#to_haml
def to_haml(tabs, options)
"#{tabulate(tabs)}/\n#{parse_text(self.content, tabs + 1)}"
if self.content.include?("\n")
"#{tabulate(tabs)}/\n#{parse_text(self.content, tabs + 1)}"
else
"#{tabulate(tabs)}/ #{self.content.strip}"
end
end
end

View File

@ -27,10 +27,6 @@ class Html2HamlTest < Test::Unit::TestCase
render('<meta http-equiv="Content-Type" content="text/html" />'))
end
def test_sqml_comment
assert_equal "/\n IE sucks", render('<!-- IE sucks -->')
end
def test_interpolation
assert_equal('Foo \#{bar} baz', render('Foo #{bar} baz'))
end
@ -59,6 +55,21 @@ HTML
assert_equal("%p foo", render("<p>foo</p>"))
end
def test_inline_comment
assert_equal("/ foo", render("<!-- foo -->"))
end
def test_non_inline_comment
assert_equal(<<HAML.rstrip, render(<<HTML))
/
Foo
Bar
HAML
<!-- Foo
Bar -->
HTML
end
def test_non_inline_text
assert_equal(<<HAML.rstrip, render(<<HTML))
%p