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

Compile javascript filter for xhtml

This commit is contained in:
Takashi Kokubun 2015-03-29 03:55:49 +09:00
parent 8b0f566ebb
commit da2281473f

View file

@ -4,11 +4,31 @@ module Hamlit
module Filters
class Javascript < Base
def compile(lines)
return compile_xhtml(lines) if options[:format] == :xhtml
compile_html(lines)
end
private
def compile_html(lines)
ast = [:haml, :text, compile_lines(lines, indent_width: 2)]
ast = [:multi, [:static, "\n"], ast]
ast = [:html, :tag, 'script', [:html, :attrs], ast]
ast
end
def compile_xhtml(lines)
attr = [:html, :attr, 'type', [:static, 'text/javascript']]
attrs = [:html, :attrs, attr]
multi = [:multi, [:static, "\n"]]
multi << [:static, " //<![CDATA[\n"]
multi << [:haml, :text, compile_lines(lines, indent_width: 4)]
multi << [:static, " //]]>\n"]
[:html, :tag, 'script', attrs, multi]
end
end
end
end