| Class | Haml::HTML |
| In: |
lib/haml/html.rb
|
| Parent: | Object |
Converts HTML documents into Haml templates. Depends on [Hpricot](github.com/whymirror/hpricot) for HTML parsing.
Example usage:
Haml::Engine.new("<a href='http://google.com'>Blat</a>").render
#=> "%a{:href => 'http://google.com'} Blat"
| TEXT_REGEXP | = | /^(\s*).*$/ |
@param template [String, Hpricot::Node] The HTML template to convert @option options :rhtml [Boolean] (false) Whether or not to parse
ERB's `<%= %>` and `<% %>` into Haml's `=` and `-`
@option options :xhtml [Boolean] (false) Whether or not to parse
the HTML strictly as XHTML
# File lib/haml/html.rb, line 78
78: def initialize(template, options = {})
79: @options = options
80:
81: if template.is_a? Hpricot::Node
82: @template = template
83: else
84: if template.is_a? IO
85: template = template.read
86: end
87:
88: if @options[:rhtml]
89: match_to_html(template, /<%=(.*?)-?%>/m, 'loud')
90: match_to_html(template, /<%-?(.*?)-?%>/m, 'silent')
91: end
92:
93: method = @options[:xhtml] ? Hpricot.method(:XML) : method(:Hpricot)
94: @template = method.call(template.gsub('&', '&'))
95: end
96: end