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

match_to_html   new   render   to_haml  

Classes and Modules

Module Haml::HTML::Node

Constants

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

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 78
78:     def initialize(template, options = {})
79:       @options = options
80: 
81:       if template.is_a? Hpricot::Node
82:         @template = template
83:       else
84:         if template.is_a? IO
85:           template = template.read
86:         end
87: 
88:         if @options[:rhtml]
89:           match_to_html(template, /<%=(.*?)-?%>/m, 'loud')
90:           match_to_html(template, /<%-?(.*?)-?%>/m,  'silent')
91:         end
92: 
93:         method = @options[:xhtml] ? Hpricot.method(:XML) : method(:Hpricot)
94:         @template = method.call(template.gsub('&', '&amp;'))
95:       end
96:     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 100
100:     def render
101:       @template.to_haml(0, @options)
102:     end
to_haml()

Alias for render

Private Instance methods

[Source]

     # File lib/haml/html.rb, line 254
254:     def match_to_html(string, regex, tag)
255:       string.gsub!(regex) do
256:         "<haml:#{tag}>#{CGI.escapeHTML($1)}</haml:#{tag}>"
257:       end
258:     end

[Validate]