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
|
# File 'lib/rux/default_visitor.rb', line 17
def visit_tag(node)
''.tap do |result|
block_arg = if (as = node.attrs['as'])
visit(as)
end
at = node.attrs.each_with_object([]) do |(k, v), ret|
next if k == 'as'
ret << Utils.attr_to_hash_elem(k, visit(v))
end
if node.name.start_with?(/[A-Z]/)
result << "render(#{node.name}.new"
unless node.attrs.empty?
result << "(#{at.join(', ')})"
end
else
result << "Rux.tag('#{node.name}'"
unless node.attrs.empty?
result << ", { #{at.join(', ')} }"
end
end
result << ')'
if node.children.size > 1
result << " { "
result << "|#{block_arg}| " if block_arg
result << "Rux.create_buffer.tap { |_rux_buf_| "
node.children.each do |child|
result << "_rux_buf_ << #{visit(child).strip};"
end
result << " }.to_s }"
elsif node.children.size == 1
result << ' { '
result << "|#{block_arg}| " if block_arg
result << visit(node.children.first).strip
result << ' }'
end
end
end
|