haml 3.1.0.alpha.141 → 3.1.0.alpha.144
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of haml might be problematic. Click here for more details.
- data/REVISION +1 -1
- data/VERSION +1 -1
- data/lib/haml/html.rb +67 -90
- metadata +1 -1
data/REVISION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
391004898bc81800e98a3801e5efafbf1dd42d64
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.1.0.alpha.
|
1
|
+
3.1.0.alpha.144
|
data/lib/haml/html.rb
CHANGED
@@ -5,105 +5,82 @@ require 'rubygems'
|
|
5
5
|
require 'cgi'
|
6
6
|
require 'hpricot'
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
if node.next_node.is_a?(::Hpricot::Text)
|
39
|
-
node = node.next_node
|
40
|
-
text << uninterp(node.to_s)
|
41
|
-
node.converted_to_haml = true
|
42
|
-
end
|
43
|
-
|
44
|
-
node = node.next_node
|
45
|
-
end
|
46
|
-
return parse_text_with_interpolation(text, tabs)
|
47
|
-
end
|
48
|
-
|
49
|
-
private
|
50
|
-
|
51
|
-
def erb_to_interpolation(text, options)
|
52
|
-
return text unless options[:erb]
|
53
|
-
text = CGI.escapeHTML(uninterp(text))
|
54
|
-
%w[<haml:loud> </haml:loud>].each {|str| text.gsub!(CGI.escapeHTML(str), str)}
|
55
|
-
::Hpricot::XML(text).children.inject("") do |str, elem|
|
56
|
-
if elem.is_a?(::Hpricot::Text)
|
57
|
-
str + CGI.unescapeHTML(elem.to_s)
|
58
|
-
else # <haml:loud> element
|
59
|
-
str + '#{' + CGI.unescapeHTML(elem.innerText.strip) + '}'
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
8
|
+
# Haml monkeypatches various Hpricot classes
|
9
|
+
# to add methods for conversion to Haml.
|
10
|
+
# @private
|
11
|
+
module Hpricot
|
12
|
+
# @see Hpricot
|
13
|
+
module Node
|
14
|
+
# Whether this node has already been converted to Haml.
|
15
|
+
# Only used for text nodes and elements.
|
16
|
+
#
|
17
|
+
# @return [Boolean]
|
18
|
+
attr_accessor :converted_to_haml
|
19
|
+
|
20
|
+
# Returns the Haml representation of the given node.
|
21
|
+
#
|
22
|
+
# @param tabs [Fixnum] The indentation level of the resulting Haml.
|
23
|
+
# @option options (see Haml::HTML#initialize)
|
24
|
+
def to_haml(tabs, options)
|
25
|
+
return "" if converted_to_haml || to_s.strip.empty?
|
26
|
+
text = uninterp(self.to_s)
|
27
|
+
node = next_node
|
28
|
+
while node.is_a?(::Hpricot::Elem) && node.name == "haml:loud"
|
29
|
+
node.converted_to_haml = true
|
30
|
+
text << '#{' <<
|
31
|
+
CGI.unescapeHTML(node.inner_text).gsub(/\n\s*/, ' ').strip << '}'
|
32
|
+
|
33
|
+
if node.next_node.is_a?(::Hpricot::Text)
|
34
|
+
node = node.next_node
|
35
|
+
text << uninterp(node.to_s)
|
36
|
+
node.converted_to_haml = true
|
37
|
+
end
|
63
38
|
|
64
|
-
|
65
|
-
|
66
|
-
|
39
|
+
node = node.next_node
|
40
|
+
end
|
41
|
+
return parse_text_with_interpolation(text, tabs)
|
42
|
+
end
|
67
43
|
|
68
|
-
|
69
|
-
|
70
|
-
|
44
|
+
private
|
45
|
+
|
46
|
+
def erb_to_interpolation(text, options)
|
47
|
+
return text unless options[:erb]
|
48
|
+
text = CGI.escapeHTML(uninterp(text))
|
49
|
+
%w[<haml:loud> </haml:loud>].each {|str| text.gsub!(CGI.escapeHTML(str), str)}
|
50
|
+
::Hpricot::XML(text).children.inject("") do |str, elem|
|
51
|
+
if elem.is_a?(::Hpricot::Text)
|
52
|
+
str + CGI.unescapeHTML(elem.to_s)
|
53
|
+
else # <haml:loud> element
|
54
|
+
str + '#{' + CGI.unescapeHTML(elem.innerText.strip) + '}'
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
71
58
|
|
72
|
-
|
73
|
-
|
74
|
-
|
59
|
+
def tabulate(tabs)
|
60
|
+
' ' * tabs
|
61
|
+
end
|
75
62
|
|
76
|
-
|
77
|
-
|
78
|
-
|
63
|
+
def uninterp(text)
|
64
|
+
text.gsub('#{', '\#{') #'
|
65
|
+
end
|
79
66
|
|
80
|
-
|
81
|
-
|
82
|
-
|
67
|
+
def attr_hash
|
68
|
+
attributes.to_hash
|
69
|
+
end
|
83
70
|
|
84
|
-
|
85
|
-
|
86
|
-
"#{tabulate(tabs)}#{'\\' if Haml::Engine::SPECIAL_CHARACTERS.include?(line[0])}#{line}\n"
|
87
|
-
end.join
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
71
|
+
def parse_text(text, tabs)
|
72
|
+
parse_text_with_interpolation(uninterp(text), tabs)
|
91
73
|
end
|
92
|
-
end
|
93
|
-
end
|
94
74
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
module Hpricot
|
99
|
-
# @see Hpricot
|
100
|
-
module Node
|
101
|
-
include Haml::HTML::Node
|
102
|
-
end
|
75
|
+
def parse_text_with_interpolation(text, tabs)
|
76
|
+
text.strip!
|
77
|
+
return "" if text.empty?
|
103
78
|
|
104
|
-
|
105
|
-
|
106
|
-
|
79
|
+
text.split("\n").map do |line|
|
80
|
+
line.strip!
|
81
|
+
"#{tabulate(tabs)}#{'\\' if Haml::Engine::SPECIAL_CHARACTERS.include?(line[0])}#{line}\n"
|
82
|
+
end.join
|
83
|
+
end
|
107
84
|
end
|
108
85
|
end
|
109
86
|
|