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

Support runtime compilation

This commit is contained in:
Takashi Kokubun 2015-10-27 01:02:54 +09:00
parent 8f1220c23b
commit 76487a74ed
3 changed files with 20 additions and 6 deletions

View file

@ -4,12 +4,29 @@ module Hamlit
class Filters
class Coffee < TiltBase
def compile(node)
if Haml::Util.contains_interpolation?(node.value[:text])
return runtime_compile(node)
end
temple = [:multi]
temple << [:static, "<script>\n".freeze]
temple << [:static, TiltBase.render('coffee', node.value[:text])]
temple << [:static, "</script>".freeze]
temple
end
private
def runtime_compile(node)
source = Haml::Util.unescape_interpolation(node.value[:text])
code = "::Hamlit::Filters::TiltBase.render('coffee', #{source})"
temple = [:multi]
temple << [:static, "<script>\n".freeze]
temple << [:dynamic, code]
temple << [:static, "</script>".freeze]
temple
end
end
end
end

View file

@ -1,11 +1,9 @@
module Hamlit
class Filters
class TiltBase < Base
class << self
def render(name, source)
text = ::Tilt["t.#{name}"].new { source }.render
text.gsub!(/^/, ' '.freeze)
end
def self.render(name, source)
text = ::Tilt["t.#{name}"].new { source }.render
text.gsub!(/^/, ' '.freeze)
end
end
end

View file

@ -41,7 +41,6 @@ describe Hamlit::Filters do
end
it 'renders coffeescript filter' do
skip
assert_render(<<-'HAML', <<-HTML)
:coffee
foo = ->