mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-26 13:45:13 -07:00
Broken warnings implementation.
This commit is contained in:
@@ -56,6 +56,21 @@ module Liquid
|
|||||||
assert_missing_delimitation!
|
assert_missing_delimitation!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# warnings of this block and all sub-tags
|
||||||
|
def warnings
|
||||||
|
all_warnings = []
|
||||||
|
all_warnings.concat(@warnings) if @warnings
|
||||||
|
|
||||||
|
return all_warnings unless @nodelist
|
||||||
|
@nodelist.each do |node|
|
||||||
|
p node
|
||||||
|
node_warns = node.respond_to?(:warnings) ? node.warnings : nil
|
||||||
|
all_warnings.concat(node_warns) if node_warns
|
||||||
|
end
|
||||||
|
|
||||||
|
all_warnings
|
||||||
|
end
|
||||||
|
|
||||||
def end_tag
|
def end_tag
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -33,6 +33,10 @@ module Liquid
|
|||||||
@blank || true
|
@blank || true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def warnings
|
||||||
|
@warnings
|
||||||
|
end
|
||||||
|
|
||||||
def parse_with_selected_parser(markup)
|
def parse_with_selected_parser(markup)
|
||||||
case @options[:error_mode] || Template.error_mode
|
case @options[:error_mode] || Template.error_mode
|
||||||
when :strict then strict_parse_with_error_context(markup)
|
when :strict then strict_parse_with_error_context(markup)
|
||||||
|
|||||||
@@ -69,9 +69,17 @@ module Liquid
|
|||||||
# Returns self for easy chaining
|
# Returns self for easy chaining
|
||||||
def parse(source, options = {})
|
def parse(source, options = {})
|
||||||
@root = Document.new(tokenize(source), options)
|
@root = Document.new(tokenize(source), options)
|
||||||
|
@warnings = nil
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# memoize because the warnings operation
|
||||||
|
# could be expensive.
|
||||||
|
def warnings
|
||||||
|
return [] unless @root
|
||||||
|
@warnings ||= @root.warnings
|
||||||
|
end
|
||||||
|
|
||||||
def registers
|
def registers
|
||||||
@registers ||= {}
|
@registers ||= {}
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -92,10 +92,10 @@ class ErrorHandlingTest < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_warnings
|
def test_warnings
|
||||||
template = Liquid::Template.parse('{% if ~~~ %}derp{% 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 'Unexpected character ~ in "~~~"', template.warnings.first.message
|
||||||
assert_equal 'wat', template.render
|
assert_equal 'wat', template.render
|
||||||
assert_equal 1, template.errors.size
|
|
||||||
assert_equal 'Unexpected character ~ in "~~~"', template.errors.first.message
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Liquid should not catch Exceptions that are not subclasses of StandardError, like Interrupt and NoMemoryError
|
# Liquid should not catch Exceptions that are not subclasses of StandardError, like Interrupt and NoMemoryError
|
||||||
|
|||||||
Reference in New Issue
Block a user