Class: Haml::HTML
Overview
Converts HTML documents into Haml templates. Depends on Hpricot for HTML parsing.
Example usage:
Haml::Engine.new("<a href='http://google.com'>Blat</a>").render
#=> "%a{:href => 'http://google.com'} Blat"
Defined Under Namespace
Modules: Node
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.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/haml/html.rb', line 79
def initialize(template, options = {})
@options = options
if template.is_a? Hpricot::Node
@template = template
else
if template.is_a? IO
template = template.read
end
Haml::Util.check_encoding(template) {|msg, line| raise Haml::Error.new(msg, line)}
if @options[:rhtml]
template = convert_to_hamlified_markup(template)
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.
102 103 104 |
# File 'lib/haml/html.rb', line 102
def render
@template.to_haml(0, @options)
end
|