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:
parent
8b0f566ebb
commit
da2281473f
1 changed files with 20 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue