1
0
Fork 0
mirror of https://github.com/haml/haml.git synced 2022-11-09 12:33:31 -05:00
haml--haml/lib/hamlit/compiler.rb

38 lines
708 B
Ruby
Raw Normal View History

2015-10-06 23:14:45 +09:00
module Hamlit
class Compiler
def initialize(options = {})
@options = options
end
2015-10-11 11:58:52 +09:00
def call(ast)
compile(ast)
end
private
2015-10-11 11:50:22 +09:00
def compile(node)
2015-10-07 00:33:20 +09:00
case node.type
2015-10-11 11:50:22 +09:00
when :root
compile_children(node)
2015-10-07 00:33:20 +09:00
when :tag
2015-10-11 11:58:14 +09:00
compile_tag(node)
2015-10-07 00:33:20 +09:00
else
[:static, "\n"]
end
2015-10-06 23:14:45 +09:00
end
2015-10-11 11:50:22 +09:00
def compile_children(node)
temple = node.children.map { |n| compile(n) }
[:multi, *temple]
end
2015-10-11 11:58:14 +09:00
def compile_tag(node)
attrs = [:html, :attrs]
node.value[:attributes].each do |name, value|
attrs << [:html, :attr, name, [:static, value]]
end
[:html, :tag, node.value[:name], attrs, [:multi]]
end
2015-10-06 23:14:45 +09:00
end
end