In Files

Class Index [+]

Quicksearch

Haml::HTML::Node

A module containing utility methods that every Hpricot node should have.

Attributes

converted_to_haml[RW]

Whether this node has already been converted to Haml. Only used for text nodes and elements.

@return [Boolean]

Public Instance Methods

to_haml(tabs, options) click to toggle source

Returns the Haml representation of the given node.

@param tabs [Fixnum] The indentation level of the resulting Haml. @option options (see Haml::HTML#initialize)

    # File lib/haml/html.rb, line 22
22:       def to_haml(tabs, options)
23:         return "" if converted_to_haml || to_s.strip.empty?
24:         text = uninterp(self.to_s)
25:         node = next_node
26:         while node.is_a?(::Hpricot::Elem) && node.name == "haml:loud"
27:           node.converted_to_haml = true
28:           text << '#{' <<
29:             CGI.unescapeHTML(node.inner_text).gsub(/\n\s*/, ' ').strip << '}'
30: 
31:           if node.next_node.is_a?(::Hpricot::Text)
32:             node = node.next_node
33:             text << uninterp(node.to_s)
34:             node.converted_to_haml = true
35:           end
36: 
37:           node = node.next_node
38:         end
39:         return parse_text_with_interpolation(text, tabs)
40:       end

Private Instance Methods

attr_hash() click to toggle source
    # File lib/haml/html.rb, line 65
65:       def attr_hash
66:         attributes.to_hash
67:       end
erb_to_interpolation(text, options) click to toggle source
    # File lib/haml/html.rb, line 44
44:       def erb_to_interpolation(text, options)
45:         return text unless options[:erb]
46:         text = CGI.escapeHTML(uninterp(text))
47:         ]<haml:loud> </haml:loud>].each {|str| text.gsub!(CGI.escapeHTML(str), str)}
48:         ::Hpricot::XML(text).children.inject("") do |str, elem|
49:           if elem.is_a?(::Hpricot::Text)
50:             str + CGI.unescapeHTML(elem.to_s)
51:           else # <haml:loud> element
52:             str + '#{' + CGI.unescapeHTML(elem.innerText.strip) + '}'
53:           end
54:         end
55:       end
parse_text(text, tabs) click to toggle source
    # File lib/haml/html.rb, line 69
69:       def parse_text(text, tabs)
70:         parse_text_with_interpolation(uninterp(text), tabs)
71:       end
parse_text_with_interpolation(text, tabs) click to toggle source
    # File lib/haml/html.rb, line 73
73:       def parse_text_with_interpolation(text, tabs)
74:         text.strip!
75:         return "" if text.empty?
76: 
77:         text.split("\n").map do |line|
78:           line.strip!
79:           "#{tabulate(tabs)}#{'\\' if Haml::Engine::SPECIAL_CHARACTERS.include?(line[0])}#{line}\n"
80:         end.join
81:       end
tabulate(tabs) click to toggle source
    # File lib/haml/html.rb, line 57
57:       def tabulate(tabs)
58:         '  ' * tabs
59:       end
uninterp(text) click to toggle source
    # File lib/haml/html.rb, line 61
61:       def uninterp(text)
62:         text.gsub('#{', '\#{') #'
63:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.