ahc 0.2.6 → 0.2.7
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/ahcx_template_handler.rb +2 -13
- metadata +1 -1
@@ -3,10 +3,6 @@ require 'htmlcompressor'
|
|
3
3
|
|
4
4
|
class AhcxTemplateHandler
|
5
5
|
|
6
|
-
ESCAPED_SYMBOLS = {
|
7
|
-
'&' => '(|escapeahx|and|)'
|
8
|
-
}
|
9
|
-
|
10
6
|
def self.call(template)
|
11
7
|
erb = ActionView::Template.registered_template_handler(:erb)
|
12
8
|
source = erb.call(template)
|
@@ -21,9 +17,8 @@ class AhcxTemplateHandler
|
|
21
17
|
end
|
22
18
|
node.children.each do |child_node|
|
23
19
|
child_node_tag, child_node_attr = child_node.name.split(':')
|
24
|
-
|
25
|
-
|
26
|
-
params[child_node_attr] = child_node.children.to_html(:encoding => 'utf-8')
|
20
|
+
if child_node.children.length == 1 && child_node.children.first.name == 'text'
|
21
|
+
params[child_node_attr] = child_node.children.text
|
27
22
|
else
|
28
23
|
attr_value = ''
|
29
24
|
child_node.children.each do |inside_node|
|
@@ -33,17 +28,11 @@ class AhcxTemplateHandler
|
|
33
28
|
end
|
34
29
|
end
|
35
30
|
html = Ahc.render(tag, params)
|
36
|
-
ESCAPED_SYMBOLS.each do |sym, escaped_sym|
|
37
|
-
html.gsub!(escaped_sym, sym)
|
38
|
-
end
|
39
31
|
html
|
40
32
|
end
|
41
33
|
|
42
34
|
def self.render(xml)
|
43
35
|
ahcx_source = "<document>#{xml}</document>"
|
44
|
-
ESCAPED_SYMBOLS.each do |sym, escaped_sym|
|
45
|
-
ahcx_source.gsub!(sym, escaped_sym)
|
46
|
-
end
|
47
36
|
ahcx = Nokogiri::XML.parse(ahcx_source)
|
48
37
|
content = ''
|
49
38
|
ahcx.children.first.children.each do |node|
|