mirror of
https://github.com/Shopify/liquid.git
synced 2026-10-04 01:25:14 -07:00
Fix warnings and make tags a proper syntax tree.
This commit is contained in:
+9
-4
@@ -14,6 +14,9 @@ module Liquid
|
|||||||
@nodelist ||= []
|
@nodelist ||= []
|
||||||
@nodelist.clear
|
@nodelist.clear
|
||||||
|
|
||||||
|
# All child tags of the current block.
|
||||||
|
@children = []
|
||||||
|
|
||||||
while token = tokens.shift
|
while token = tokens.shift
|
||||||
case token
|
case token
|
||||||
when IsTag
|
when IsTag
|
||||||
@@ -31,6 +34,7 @@ module Liquid
|
|||||||
new_tag = tag.new_with_options($1, $2, tokens, @options || {})
|
new_tag = tag.new_with_options($1, $2, tokens, @options || {})
|
||||||
@blank &&= new_tag.blank?
|
@blank &&= new_tag.blank?
|
||||||
@nodelist << new_tag
|
@nodelist << new_tag
|
||||||
|
@children << new_tag
|
||||||
else
|
else
|
||||||
# this tag is not registered with the system
|
# this tag is not registered with the system
|
||||||
# pass it to the current block for special handling or error reporting
|
# 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} "
|
raise SyntaxError, "Tag '#{token}' was not properly terminated with regexp: #{TagEnd.inspect} "
|
||||||
end
|
end
|
||||||
when IsVariable
|
when IsVariable
|
||||||
@nodelist << create_variable(token)
|
new_var = create_variable(token)
|
||||||
|
@nodelist << new_var
|
||||||
|
@children << new_var
|
||||||
@blank = false
|
@blank = false
|
||||||
when ''
|
when ''
|
||||||
# pass
|
# pass
|
||||||
@@ -61,9 +67,8 @@ module Liquid
|
|||||||
all_warnings = []
|
all_warnings = []
|
||||||
all_warnings.concat(@warnings) if @warnings
|
all_warnings.concat(@warnings) if @warnings
|
||||||
|
|
||||||
return all_warnings unless @nodelist
|
return all_warnings unless @children
|
||||||
@nodelist.each do |node|
|
@children.each do |node|
|
||||||
p node
|
|
||||||
node_warns = node.respond_to?(:warnings) ? node.warnings : nil
|
node_warns = node.respond_to?(:warnings) ? node.warnings : nil
|
||||||
all_warnings.concat(node_warns) if node_warns
|
all_warnings.concat(node_warns) if node_warns
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -13,12 +13,12 @@ module Liquid
|
|||||||
class Variable
|
class Variable
|
||||||
FilterParser = /(?:#{FilterSeparator}|(?:\s*(?:#{QuotedFragment}|#{ArgumentSeparator})\s*)+)/o
|
FilterParser = /(?:#{FilterSeparator}|(?:\s*(?:#{QuotedFragment}|#{ArgumentSeparator})\s*)+)/o
|
||||||
EasyParse = /^ *(\w+(?:\.\w+)*) *$/
|
EasyParse = /^ *(\w+(?:\.\w+)*) *$/
|
||||||
attr_accessor :filters, :name
|
attr_accessor :filters, :name, :warnings
|
||||||
|
|
||||||
def initialize(markup, options = {})
|
def initialize(markup, options = {})
|
||||||
@markup = markup
|
@markup = markup
|
||||||
@name = nil
|
@name = nil
|
||||||
@warning = nil
|
@warnings = []
|
||||||
@options = options || {}
|
@options = options || {}
|
||||||
|
|
||||||
|
|
||||||
@@ -29,7 +29,7 @@ module Liquid
|
|||||||
begin
|
begin
|
||||||
strict_parse(markup)
|
strict_parse(markup)
|
||||||
rescue SyntaxError => e
|
rescue SyntaxError => e
|
||||||
@warning = e
|
@warnings << e
|
||||||
lax_parse(markup)
|
lax_parse(markup)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -95,6 +95,7 @@ class ErrorHandlingTest < Test::Unit::TestCase
|
|||||||
template = Liquid::Template.parse('{% if ~~~ %}{{%%%}}{% else %}wat{% endif %}', :error_mode => :warn)
|
template = Liquid::Template.parse('{% if ~~~ %}{{%%%}}{% else %}wat{% endif %}', :error_mode => :warn)
|
||||||
assert_equal 2, template.warnings.size
|
assert_equal 2, template.warnings.size
|
||||||
assert_equal 'Unexpected character ~ in "~~~"', template.warnings.first.message
|
assert_equal 'Unexpected character ~ in "~~~"', template.warnings.first.message
|
||||||
|
assert_equal 'Unexpected character % in "{{%%%}}"', template.warnings.last.message
|
||||||
assert_equal 'wat', template.render
|
assert_equal 'wat', template.render
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user