Parent

Namespace

Haml::HTML

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"

Constants

TEXT_REGEXP

Public Class Methods

new(template, options = {}) click to toggle source

@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 121
121:     def initialize(template, options = {})
122:       @options = options
123: 
124:       if template.is_a? Hpricot::Node
125:         @template = template
126:       else
127:         if template.is_a? IO
128:           template = template.read
129:         end
130: 
131:         template = Haml::Util.check_encoding(template) {|msg, line| raise Haml::Error.new(msg, line)}
132: 
133:         if @options[:erb]
134:           require 'haml/html/erb'
135:           template = ERB.compile(template)
136:         end
137: 
138:         method = @options[:xhtml] ? Hpricot.method(:XML) : method(:Hpricot)
139:         @template = method.call(template.gsub('&', '&amp;'))
140:       end
141:     end

Public Instance Methods

render() click to toggle source

Processes the document and returns the result as a string containing the Haml template.

     # File lib/haml/html.rb, line 145
145:     def render
146:       @template.to_haml(0, @options)
147:     end
Also aliased as: to_haml
to_haml() click to toggle source
Alias for: render

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.