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

Rewrite css filter

This commit is contained in:
Takashi Kokubun 2015-10-26 21:51:19 +09:00
parent 1d39845d88
commit 3cabf19541
2 changed files with 31 additions and 5 deletions

View file

@ -2,14 +2,42 @@ module Hamlit
class Filters
class Css < Base
def compile(node)
text = compile_text(node.value[:text])
case @format
when :xhtml
compile_xhtml('style', 'text/css', text)
compile_xhtml(node)
else
compile_html('style', text)
compile_html(node)
end
end
private
def compile_text!(temple, node, prefix)
(node.value[:text].rstrip << "\n").each_line do |line|
if Haml::Util.contains_interpolation?(line)
temple << [:dynamic, Haml::Util.unescape_interpolation(prefix.dup << line)]
else
temple << [:static, prefix.dup << line]
end
temple << [:newline]
end
end
def compile_html(node)
temple = [:multi]
temple << [:static, "<style>\n".freeze]
compile_text!(temple, node, ' '.freeze)
temple << [:static, '</style>'.freeze]
temple
end
def compile_xhtml(node)
temple = [:multi]
temple << [:static, "<style type='text/css'>\n /*<![CDATA[*/\n".freeze]
compile_text!(temple, node, ' '.freeze)
temple << [:static, " /*]]>*/\n</style>".freeze]
temple
end
end
end
end

View file

@ -3,7 +3,6 @@ describe Hamlit::Filters do
describe '#compile' do
it 'renders css' do
skip
assert_render(<<-HAML, <<-HTML)
:css
.foo {
@ -19,7 +18,6 @@ describe Hamlit::Filters do
end
it 'parses string interpolation' do
skip
assert_render(<<-'HAML', <<-HTML)
:css
.foo {