Class: Haml::HTML
Overview
Converts HTML documents into Haml templates. Depends on [Hpricot](code.whytheluckystiff.net/hpricot/) for HTML parsing.
Example usage:
Haml::Engine.new("<a href='http://google.com'>Blat</a>").render
#=> "%a{:href => 'http://google.com'} Blat"
Constant Summary collapse
- TEXT_REGEXP =
/^(\s*).*$/
Instance Method Summary collapse
-
#initialize(template, options = {}) ⇒ HTML
constructor
A new instance of HTML.
-
#render ⇒ Object
(also: #to_haml)
Processes the document and returns the result as a string containing the Haml template.
Constructor Details
#initialize(template, options = {}) ⇒ HTML
Returns a new instance of HTML.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/haml/html.rb', line 22 def initialize(template, = {}) @options = if template.is_a? Hpricot::Node @template = template else if template.is_a? IO template = template.read end if @options[:rhtml] match_to_html(template, /<%=(.*?)-?%>/m, 'loud') match_to_html(template, /<%-?(.*?)-?%>/m, 'silent') end method = @options[:xhtml] ? Hpricot.method(:XML) : method(:Hpricot) @template = method.call(template.gsub('&', '&')) end end |
Instance Method Details
#render ⇒ Object Also known as: to_haml
Processes the document and returns the result as a string containing the Haml template.
44 45 46 |
# File 'lib/haml/html.rb', line 44 def render @template.to_haml(0, @options) end |