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

Static may be enough

This commit is contained in:
Takashi Kokubun 2015-03-17 08:31:19 +09:00
parent 74561f3ee3
commit c039559f00
3 changed files with 27 additions and 9 deletions

View file

@ -1,17 +1,9 @@
require 'temple/html/filter'
# NOTE: This compiler has an extremely bad effect for performance.
# We should optimize this.
module Hamlit
class TextCompiler < Temple::HTML::Filter
def on_haml_text(exp)
compile_text(exp)
end
private
def compile_text(exp)
[:dynamic, %Q{"#{exp.gsub(/"/, '\"')}"}]
[:static, exp]
end
end
end

View file

@ -14,5 +14,20 @@ describe Hamlit::Filters::Css do
</style>
HTML
end
it 'parses string interpolation' do
assert_render(<<-HAML, <<-HTML)
:css
.foo {
width: #{100 * 3}px;
}
HAML
<style>
.foo {
width: 300px;
}
</style>
HTML
end
end
end

View file

@ -67,5 +67,16 @@ describe Hamlit::Filters::Javascript do
</script>
HTML
end
it 'parses string interpolation' do
assert_render(<<-HAML, <<-HTML)
:javascript
var a = #{[1, 2]};
HAML
<script>
var a = [1, 2];
</script>
HTML
end
end
end