Class | Haml::HTML::ERB |
In: |
lib/haml/html/erb.rb
|
Parent: | Erubis::Basic::Engine |
A class for converting ERB code into a format that‘s easier for the {Haml::HTML} Hpricot-based parser to understand.
Uses [Erubis](www.kuwata-lab.com/erubis)'s extensible parsing powers to parse the ERB in a reliable way, and [ruby_parser](parsetree.rubyforge.org/)'s Ruby knowledge to figure out whether a given chunk of Ruby code starts a block or not.
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>`. 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.
Compiles an ERB template into a HTML document containing `haml:` tags.
@param template [String] The ERB template @return [String] The output document @see Haml::HTML::ERB
Concatenates a Ruby expression that‘s printed to the document onto the source buffer. This uses the `<haml:silent>` tag, and may open a Ruby block with the `<haml:block>` tag. An expression never closes a block.
@param src [String] The source buffer @param code [String] The Ruby expression to add to the buffer
Concatenates a silent Ruby statement onto the source buffer. This uses the `<haml:silent>` tag, and may close and/or open a Ruby block with the `<haml:block>` tag.
In particular, a block is closed if this statement is some form of `end`, opened if it‘s a block opener like `do`, `if`, or `begin`, and both closed and opened if it‘s a mid-block keyword like `else` or `when`.
@param src [String] The source buffer @param code [String] The Ruby statement to add to the buffer