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

Implement conditional html comment

This commit is contained in:
Takashi Kokubun 2015-03-29 09:52:33 +09:00
parent 652a20dcb6
commit beea20a761
4 changed files with 25 additions and 10 deletions

View file

@ -1,4 +1,5 @@
require 'hamlit/compilers/attributes'
require 'hamlit/compilers/comment'
require 'hamlit/compilers/doctype'
require 'hamlit/compilers/dynamic'
require 'hamlit/compilers/filter'
@ -11,6 +12,7 @@ require 'temple/html/filter'
module Hamlit
class Compiler < Temple::HTML::Filter
include Compilers::Attributes
include Compilers::Comment
include Compilers::Doctype
include Compilers::Dynamic
include Compilers::Filter

View file

@ -0,0 +1,13 @@
module Hamlit
module Compilers
module Comment
def on_haml_comment(condition, exps)
content = [:multi]
content << [:static, "#{condition}>\n"]
content += exps.map { |exp| compile(exp) }
content << [:static, "<![endif]"]
[:html, :comment, content]
end
end
end
end

View file

@ -202,16 +202,17 @@ module Hamlit
raise SyntaxError unless scanner.scan(/\//)
ast = [:html, :comment]
if scanner.rest.match(/[^ ]/)
ast << [:static, " #{scanner.scan(/.+/).strip} "]
return ast
text = (scanner.scan(/.+/) || '').strip
if text.empty?
content = with_indented { parse_lines }
return ast << [:multi, [:static, "\n"], *content]
elsif !text.match(/\[.*\]/)
return ast << [:static, " #{text} "]
end
# FIXME: parse_lines may not be enough
content = [:multi, [:static, "\n"]]
content += with_indented { parse_lines }
ast << content
ast
content = with_indented { parse_lines }
[:haml, :comment, text, content]
end
def parse_filter(scanner)

View file

@ -659,8 +659,7 @@ describe "haml" do
end
context "conditional comments" do
# FIXME: I'll implement later
pending "a conditional comment" do
specify "a conditional comment" do
haml = %q{/[if IE]
%p a}
html = %q{<!--[if IE]>