Class | Haml::HTML |
In: |
lib/haml/html.rb
|
Parent: | Object |
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"
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 73 73: def initialize(template, options = {}) 74: @options = options 75: 76: if template.is_a? Hpricot::Node 77: @template = template 78: else 79: if template.is_a? IO 80: template = template.read 81: end 82: 83: if @options[:rhtml] 84: match_to_html(template, /<%=(.*?)-?%>/m, 'loud') 85: match_to_html(template, /<%-?(.*?)-?%>/m, 'silent') 86: end 87: 88: method = @options[:xhtml] ? Hpricot.method(:XML) : method(:Hpricot) 89: @template = method.call(template.gsub('&', '&')) 90: end 91: end