| Class | Haml::HTML |
| In: |
lib/haml/html.rb
lib/haml/html/erb.rb |
| Parent: | Object |
Converts HTML documents into Haml templates. Depends on [Hpricot](github.com/whymirror/hpricot) for HTML parsing. If ERB conversion is being used, also depends on [Erubis](www.kuwata-lab.com/erubis) to parse the ERB and [ruby_parser](parsetree.rubyforge.org/) to parse the Ruby code.
Example usage:
Haml::HTML.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 :erb [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 144
144: def initialize(template, options = {})
145: @options = options
146:
147: if template.is_a? Hpricot::Node
148: @template = template
149: else
150: if template.is_a? IO
151: template = template.read
152: end
153:
154: template = Haml::Util.check_encoding(template) {|msg, line| raise Haml::Error.new(msg, line)}
155:
156: if @options[:erb]
157: require 'haml/html/erb'
158: template = ERB.compile(template)
159: end
160:
161: method = @options[:xhtml] ? Hpricot.method(:XML) : method(:Hpricot)
162: @template = method.call(template.gsub('&', '&'))
163: end
164: end