Class Haml::HTML
In: lib/haml/html.rb
Parent: Object

Converts HTML documents into Haml templates. Depends on [Hpricot](github.com/whymirror/hpricot) for HTML parsing.

Example usage:

    Haml::Engine.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

Constants

TEXT_REGEXP = /^(\s*).*$/   @private

Public Class methods

@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

[Source]

    # File lib/haml/html.rb, line 79
79:     def initialize(template, options = {})
80:       @options = options
81: 
82:       if template.is_a? Hpricot::Node
83:         @template = template
84:       else
85:         if template.is_a? IO
86:           template = template.read
87:         end
88: 
89:         if @options[:rhtml]
90:           match_to_html(template, /<%=(.*?)-?%>/m, 'loud')
91:           match_to_html(template, /<%-?(.*?)-?%>/m,  'silent')
92:         end
93: 
94:         method = @options[:xhtml] ? Hpricot.method(:XML) : method(:Hpricot)
95:         @template = method.call(template.gsub('&', '&amp;'))
96:       end
97:     end

Public Instance methods

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

[Source]

     # File lib/haml/html.rb, line 101
101:     def render
102:       @template.to_haml(0, @options)
103:     end
to_haml()

Alias for render

[Validate]