Clean up whitespace collapsing a bit

This commit is contained in:
Florian Weingarten
2013-06-27 13:56:33 +02:00
parent f01d0dbea6
commit c16697746b
6 changed files with 14 additions and 9 deletions

View File

@@ -7,8 +7,8 @@ module Liquid
FullToken = /^#{TagStart}\s*(\w+)\s*(.*)?#{TagEnd}$/o
ContentOfVariable = /^#{VariableStart}(.*)#{VariableEnd}$/o
def self.blank?
false
def blank?
@blank || false
end
def parse(tokens)
@@ -25,14 +25,13 @@ module Liquid
# proceed
if block_delimiter == $1
end_tag
@blank = true if self.class.blank?
return
end
# fetch the tag from registered blocks
if tag = Template.tags[$1]
new_tag = tag.new($1, $2, tokens)
@blank = false if new_tag.is_a?(Block) && !new_tag.blank
@blank = false unless new_tag.blank?
@nodelist << new_tag
else
# this tag is not registered with the system

View File

@@ -19,8 +19,8 @@ module Liquid
''
end
def self.blank?
true
def blank?
@blank || true
end
end # Tag
end # Tag

View File

@@ -31,7 +31,7 @@ module Liquid
''
end
def self.blank?
def blank?
true
end
end

View File

@@ -4,7 +4,7 @@ module Liquid
''
end
def self.blank?
def blank?
true
end
end

View File

@@ -28,7 +28,9 @@ module Liquid
value.to_s
end
private
def blank?
false
end
end
Template.register_tag('increment', Increment)

View File

@@ -61,6 +61,10 @@ class BlankTest < Test::Unit::TestCase
assert_template_result(body*(N+1), wrap(body))
end
def test_increment_is_not_blank
assert_template_result(" 0"*2*(N+1), wrap("{% assign foo = 0 %} {% increment foo %} {% decrement foo %}"))
end
def test_raw_is_not_blank
assert_template_result(" "*(N+1), wrap(" {% raw %} {% endraw %}"))
end