diff --git a/lib/liquid/block.rb b/lib/liquid/block.rb index e4b2398..f898d6c 100644 --- a/lib/liquid/block.rb +++ b/lib/liquid/block.rb @@ -14,6 +14,9 @@ module Liquid @nodelist ||= [] @nodelist.clear + # All child tags of the current block. + @children = [] + while token = tokens.shift case token when IsTag @@ -31,6 +34,7 @@ module Liquid new_tag = tag.new_with_options($1, $2, tokens, @options || {}) @blank &&= new_tag.blank? @nodelist << new_tag + @children << new_tag else # this tag is not registered with the system # pass it to the current block for special handling or error reporting @@ -40,7 +44,9 @@ module Liquid raise SyntaxError, "Tag '#{token}' was not properly terminated with regexp: #{TagEnd.inspect} " end when IsVariable - @nodelist << create_variable(token) + new_var = create_variable(token) + @nodelist << new_var + @children << new_var @blank = false when '' # pass @@ -61,9 +67,8 @@ module Liquid all_warnings = [] all_warnings.concat(@warnings) if @warnings - return all_warnings unless @nodelist - @nodelist.each do |node| - p node + return all_warnings unless @children + @children.each do |node| node_warns = node.respond_to?(:warnings) ? node.warnings : nil all_warnings.concat(node_warns) if node_warns end diff --git a/lib/liquid/variable.rb b/lib/liquid/variable.rb index 7aa2999..d572d66 100644 --- a/lib/liquid/variable.rb +++ b/lib/liquid/variable.rb @@ -13,12 +13,12 @@ module Liquid class Variable FilterParser = /(?:#{FilterSeparator}|(?:\s*(?:#{QuotedFragment}|#{ArgumentSeparator})\s*)+)/o EasyParse = /^ *(\w+(?:\.\w+)*) *$/ - attr_accessor :filters, :name + attr_accessor :filters, :name, :warnings def initialize(markup, options = {}) @markup = markup @name = nil - @warning = nil + @warnings = [] @options = options || {} @@ -29,7 +29,7 @@ module Liquid begin strict_parse(markup) rescue SyntaxError => e - @warning = e + @warnings << e lax_parse(markup) end end diff --git a/test/liquid/error_handling_test.rb b/test/liquid/error_handling_test.rb index 6ac2e49..aa41b58 100644 --- a/test/liquid/error_handling_test.rb +++ b/test/liquid/error_handling_test.rb @@ -95,6 +95,7 @@ class ErrorHandlingTest < Test::Unit::TestCase template = Liquid::Template.parse('{% if ~~~ %}{{%%%}}{% else %}wat{% endif %}', :error_mode => :warn) assert_equal 2, template.warnings.size assert_equal 'Unexpected character ~ in "~~~"', template.warnings.first.message + assert_equal 'Unexpected character % in "{{%%%}}"', template.warnings.last.message assert_equal 'wat', template.render end