class Haml::HTML::ERB

that is, everything that should be indented beneath the previous silent or loud tag.
‘<haml:block> … </haml:block>` will wrap the entire contents of the block -
Finally, if either of these opens a Ruby block,
`<%= … %>` is converted into `<haml:loud> … </haml:loud>`.
`<% … %>` is converted into `<haml:silent> … </haml:silent>`.
The ERB tags are converted to HTML tags in the following way.
to figure out whether a given chunk of Ruby code starts a block or not.
and [ruby_parser](parsetree.rubyforge.org/)’s Ruby knowledge
to parse the ERB in a reliable way,
Uses [Erubis](www.kuwata-lab.com/erubis)‘s extensible parsing powers
for the {Haml::HTML} Hpricot-based parser to understand.
A class for converting ERB code into a format that’s easier

def self.compile(template)

Other tags:
    See: Haml::HTML::ERB -

Returns:
  • (String) - The output document

Parameters:
  • template (String) -- The ERB template
def self.compile(template)
  new(template).src
end

def add_expr_debug(src, code)

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

def add_expr_literal(src, code)

Parameters:
  • code (String) -- The Ruby expression to add to the buffer
  • src (String) -- The source buffer
def add_expr_literal(src, code)
  src << '<haml:loud>' << h(code) << '</haml:loud>'
  src << '<haml:block>' if block_opener?(code)
end

def add_postamble(src); end

The ERB-to-Hamlized-HTML conversion has no postamble.
def add_postamble(src); end

def add_preamble(src); end

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

def add_stmt(src, code)

Parameters:
  • code (String) -- The Ruby statement to add to the buffer
  • src (String) -- The source buffer
def add_stmt(src, code)
  src << '</haml:block>' if block_closer?(code) || mid_block?(code)
  src << '<haml:silent>' << h(code) << '</haml:silent>' unless code.strip == "end"
  src << '<haml:block>' if block_opener?(code) || mid_block?(code)
end

def add_text(src, text)

Parameters:
  • text (String) -- The raw text to add to the buffer
  • src (String) -- The source buffer
def add_text(src, text)
  src << text
end

def block_closer?(code)

Returns:
  • (Boolean) -

Parameters:
  • code (String) -- Ruby code to check
def block_closer?(code)
  valid_ruby?("begin\n" + code)
end

def block_opener?(code)

Returns:
  • (Boolean) -

Parameters:
  • code (String) -- Ruby code to check
def block_opener?(code)
  valid_ruby?(code + "\nend") ||
    valid_ruby?(code + "\nwhen foo\nend")
end

def escaped_expr(code)

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

def h(text)

Returns:
  • (String) - The escaped text

Parameters:
  • text (String) -- The text to escape
def h(text)
  CGI.escapeHTML(text)
end

def mid_block?(code)

Returns:
  • (Boolean) -

Parameters:
  • code (String) -- Ruby code to check
def mid_block?(code)
  return if valid_ruby?(code)
  valid_ruby?("if foo\n#{code}\nend") || # else, elsif
    valid_ruby?("begin\n#{code}\nend") || # rescue, ensure
    valid_ruby?("case foo\n#{code}\nend") # when
end

def valid_ruby?(code)

Returns:
  • (Boolean) -

Parameters:
  • code (String) -- Ruby code to check
def valid_ruby?(code)
  RubyParser.new.parse(code)
rescue Racc::ParseError => e
  false
end