| 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::HTML.new("<a href='http://google.com'>Blat</a>").render
#=> "%a{:href => 'http://google.com'} Blat"
| TEXT_REGEXP | = | /^(\s*).*$/ | @private |
@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 79
79: def initialize(template, options = {})
80: @options = options
81:
82: if template.is_a? Hpricot::Node
83: @template = template
84: else
85: if template.is_a? IO
86: template = template.read
87: end
88:
89: if @options[:rhtml]
90: match_to_html(template, /<%=(.*?)-?%>/m, 'loud')
91: match_to_html(template, /<%-?(.*?)-?%>/m, 'silent')
92: end
93:
94: method = @options[:xhtml] ? Hpricot.method(:XML) : method(:Hpricot)
95: @template = method.call(template.gsub('&', '&'))
96: end
97: end