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

Support haml-like recursive nuking

This commit is contained in:
Takashi Kokubun 2015-10-25 23:20:28 +09:00
parent d9da2a0c3c
commit ed1c9edb37
3 changed files with 16 additions and 36 deletions

View file

@ -56,8 +56,15 @@ module Hamlit
end
def nuke_inner_whitespace?(node)
return false if node.type != :tag
node.value[:nuke_inner_whitespace]
case
when node.type == :tag
node.value[:nuke_inner_whitespace] ||
(node.parent && nuke_inner_whitespace?(node.parent))
when node.parent.nil?
false
else
nuke_inner_whitespace?(node.parent)
end
end
def nuke_prev_whitespace?(node)
@ -91,7 +98,7 @@ module Hamlit
when :comment, :filter, :plain, :tag
true
when :script
node.children.empty?
node.children.empty? && !nuke_inner_whitespace?(node)
else
false
end

View file

@ -65,7 +65,7 @@ describe Hamlit::Engine do
HTML
end
it 'skips empty lines' do
it 'ignores empty lines' do
assert_render(<<-HAML, <<-HTML)
%span
@ -237,7 +237,6 @@ describe Hamlit::Engine do
end
it 'removes whitespaces inside block script' do
skip
assert_render(<<-HAML, <<-HTML)
%span<
= 2.times do
@ -249,7 +248,6 @@ describe Hamlit::Engine do
end
it 'removes whitespace inside script inside silent script' do
skip
assert_render(<<-HAML, <<-HTML)
.bar<
- 3.times do
@ -260,7 +258,6 @@ describe Hamlit::Engine do
end
it 'removes whitespace inside script recursively' do
skip
assert_render(<<-HAML, <<-HTML)
.foo<
- 1.times do
@ -274,26 +271,23 @@ describe Hamlit::Engine do
end
it 'does not remove whitespace after string interpolation' do
assert_render(<<-'HAML', <<-HTML, compatible_only: :faml)
assert_render(<<-'HAML', <<-HTML, compatible_only: :haml)
%div<
#{'hello'}
world
HAML
<div>hello
world</div>
<div>helloworld</div>
HTML
end
it 'removes whitespace inside script inside silent script' do
skip
assert_render(<<-HAML, <<-HTML, compatible_only: :faml)
assert_render(<<-HAML, <<-HTML, compatible_only: :haml)
.bar<
- 1.times do
= '1'
= '2'
HAML
<div class='bar'>1
2</div>
<div class='bar'>12</div>
HTML
end
end

View file

@ -3,7 +3,6 @@ describe Hamlit::Engine do
describe 'text' do
it 'renders string interpolation' do
skip
assert_render(<<-'HAML', <<-HTML)
#{ "a#{3}a" }a" #{["1", 2]} b " !
a#{{ a: 3 }}
@ -29,7 +28,6 @@ describe Hamlit::Engine do
end
it 'renders == operator' do
skip
assert_render(<<-'HAML', <<-HTML)
===
== =
@ -44,7 +42,6 @@ describe Hamlit::Engine do
end
it 'renders !== operator' do
skip
assert_render(<<-'HAML', <<-HTML)
== #{'<a>'}
!== #{'<a>'}
@ -206,25 +203,7 @@ describe Hamlit::Engine do
specify { assert_render(%q{'"!@$%^&*|=#{1}1#{1}2}, %Q{'"!@$%^&*|=1112\n}) }
specify { assert_render('あ#{1}', "あ1\n") }
specify { assert_render('あ#{"い"}う', "あいう\n") }
specify { skip; assert_render('a#{"<b>"}c', "a&lt;b&gt;c\n") }
end
describe 'illegal inputs' do
it 'rejects an invalid tag' do
skip
expect { render_string(<<-HAML.unindent) }.
% a
HAML
to raise_error(Hamlit::SyntaxError, 'Invalid tag: "% a".')
end
it 'rejects an invalid tag' do
skip
expect { render_string(<<-HAML.unindent) }.
%.foo
HAML
to raise_error(Hamlit::SyntaxError, 'Invalid tag: "%.foo".')
end
specify { assert_render('a#{"<b>"}c', "a&lt;b&gt;c\n") }
end
end
end