16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
# File 'lib/wunderbar/jquery/filter.rb', line 16
def on_send(node)
return super if @react
if node.children[0] == nil and node.children[1] =~ /^_\w/
tag = node.children[1].to_s[1..-1]
if Node::VOID.include? tag
element = s(:send, s(:str, "<#{tag}/>"), :~)
else
element = s(:send, s(:str, "<#{tag}></#{tag}>"), :~)
end
node.children[2..-1].each do |child|
if child.type == :hash
pairs = child.children.map do |pair|
key, value = pair.children
if key.type == :sym
s(:pair, s(:str, key.children[0].to_s.gsub('_', '-')), value)
else
pair
end
end
element = s(:send, element, :attr, s(:hash, *pairs))
elsif child.type == :addClass
element = s(:send, element, :addClass, s(:sym, *child.children))
elsif child.type == :block
element = s(:block, s(:send, element, :each!),
*node.children.last.children[1..-1])
else
element = s(:send, element, :text, child)
end
end
begin
jqchild, @_jqchild = @_jqchild, true
if jqchild
element = s(:send, element, :appendTo,
s(:send, s(:lvar, :_parent), :~))
end
process element
ensure
@_jqchild = jqchild
end
elsif node.children[0] and node.children[0].type == :send
child = node
test = child.children.first
while test and test.type == :send and not test.is_method?
child, test = test, test.children.first
end
if child.children[0] == nil and child.children[1] =~ /^_\w/
children = node.children[2..-1]
prefix = []
while node != child
if node.children[1] !~ /!$/
prefix.unshift s(:addClass, node.children[1].to_s.gsub('_','-'))
else
pair = s(:pair, s(:sym, :id),
s(:str, node.children[1].to_s[0..-2].gsub('_','-')))
hash = children.find_index {|cnode| cnode.type == :hash}
if hash
children[hash] = s(:hash, pair, *children[hash].children)
else
prefix.unshift s(:hash, pair)
end
end
node = node.children.first
end
return process(s(:send, *node.children[0..1], *prefix, *children))
else
super
end
else
super
end
end
|