Class | Haml::HTML
In: | lib/haml/html/erb.rb lib/haml/html.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"

### Methods

new render to_haml

### Classes and Modules

Module Haml::HTML::Node
Class Haml::HTML::ERB

### Constants

TEXT_REGEXP | = | /^(\s*).*$/

### Public Class methods

new(template, options = {})

@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

[Source]

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

### Public Instance methods

render()

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

[Source]

         # File lib/haml/html.rb, line 144
    144:     def render
    145:       @template.to_haml(0, @options)
    146:     end

to_haml()

Alias for render

[Validate]