Skip to content

Commit

Permalink
add output of escaped erb <%== into haml's !=
Browse files Browse the repository at this point in the history
issue #44
  • Loading branch information
snatchev committed Feb 14, 2014
1 parent 0884a58 commit 51ccddc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
7 changes: 6 additions & 1 deletion lib/html2haml/html.rb
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,12 @@ def to_haml(tabs, options)
when "haml_loud"
lines = CGI.unescapeHTML(inner_text).split("\n").
map {|s| s.rstrip}.reject {|s| s.strip.empty?}
lines.first.gsub!(/^[ \t]*/, "= ")

if attribute("raw")
lines.first.gsub!(/^[ \t]*/, "!= ")
else
lines.first.gsub!(/^[ \t]*/, "= ")
end

if lines.size > 1 # Multiline script block
# Normalize the indentation so that the last line is the base
Expand Down
10 changes: 5 additions & 5 deletions lib/html2haml/html/erb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class HTML
# The ERB tags are converted to HTML tags in the following way.
# `<% ... %>` is converted into `<haml_silent> ... </haml_silent>`.
# `<%= ... %>` is converted into `<haml_loud> ... </haml_loud>`.
# `<%== ... %>` is converted into `<haml_loud raw=raw> ... </haml_loud>`.
# Finally, if either of these opens a Ruby block,
# `<haml_block> ... </haml_block>` will wrap the entire contents of the block -
# that is, everything that should be indented beneath the previous silent or loud tag.
Expand All @@ -28,11 +29,6 @@ def self.compile(template)
new(template).src
end

# `html2haml` doesn't support HTML-escaped expressions.
def escaped_expr(code)
raise Haml::Error.new("html2haml doesn't support escaped expressions.")
end

# The ERB-to-Hamlized-HTML conversion has no preamble.
def add_preamble(src); end

Expand Down Expand Up @@ -77,6 +73,10 @@ def add_expr_literal(src, code)
src << '<haml_block>' if block_opener?(code)
end

def add_expr_escaped(src, code)
src << "<haml_loud raw=raw>" << h(code) << "</haml_loud>"
end

# `html2haml` doesn't support debugging expressions.
def add_expr_debug(src, code)
raise Haml::Error.new("html2haml doesn't support debugging expressions.")
Expand Down

0 comments on commit 51ccddc

Please sign in to comment.