[Haml] [html2haml] Expand ERB-to-interpolation to include CDATA.
This commit is contained in:
parent
0138b212c5
commit
a630df6860
|
@ -41,6 +41,19 @@ module Haml
|
|||
|
||||
private
|
||||
|
||||
def erb_to_interpolation(text, options)
|
||||
return text unless options[:erb]
|
||||
text = CGI.escapeHTML(uninterp(text))
|
||||
%w[<haml:loud> </haml:loud>].each {|str| text.gsub!(CGI.escapeHTML(str), str)}
|
||||
::Hpricot::XML(text).children.inject("") do |str, elem|
|
||||
if elem.is_a?(::Hpricot::Text)
|
||||
str + CGI.unescapeHTML(elem.to_s)
|
||||
else # <haml:loud> element
|
||||
str + '#{' + CGI.unescapeHTML(elem.innerText.strip) + '}'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def tabulate(tabs)
|
||||
' ' * tabs
|
||||
end
|
||||
|
@ -147,7 +160,9 @@ module Haml
|
|||
class ::Hpricot::CData
|
||||
# @see Haml::HTML::Node#to_haml
|
||||
def to_haml(tabs, options)
|
||||
"#{tabulate(tabs)}:cdata\n#{parse_text(self.content, tabs + 1)}"
|
||||
content = parse_text_with_interpolation(
|
||||
erb_to_interpolation(self.content, options), tabs + 1)
|
||||
"#{tabulate(tabs)}:cdata\n#{content}"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -122,6 +122,15 @@ HAML
|
|||
HTML
|
||||
end
|
||||
|
||||
def test_erb_in_cdata
|
||||
assert_equal(<<HAML.rstrip, render_erb(<<HTML))
|
||||
:cdata
|
||||
Foo \#{bar} baz
|
||||
HAML
|
||||
<![CDATA[Foo <%= bar %> baz]]>
|
||||
HTML
|
||||
end
|
||||
|
||||
def test_erb_in_line
|
||||
assert_equal 'foo bar #{baz}', render_erb('foo bar <%= baz %>')
|
||||
assert_equal 'foo bar #{baz}! Bang.', render_erb('foo bar <%= baz %>! Bang.')
|
||||
|
|
Loading…
Reference in New Issue