Add ability to pass tags to parse_context

This commit is contained in:
Matt Rose
2022-09-29 10:31:39 -04:00
committed by Dylan Thacker-Smith
parent c8f3cfa8fc
commit 6bdf88a32c
4 changed files with 41 additions and 5 deletions
+5 -4
View File
@@ -45,7 +45,7 @@ module Liquid
end
tag_name = Regexp.last_match(1)
markup = Regexp.last_match(2)
unless (tag = registered_tags[tag_name])
unless (tag = registered_tag(tag_name, parse_context))
# end parsing if we reach an unknown tag and let the caller decide
# determine how to proceed
return yield tag_name, markup
@@ -132,7 +132,7 @@ module Liquid
next
end
unless (tag = registered_tags[tag_name])
unless (tag = registered_tag(tag_name, parse_context))
# end parsing if we reach an unknown tag and let the caller decide
# determine how to proceed
return yield tag_name, markup
@@ -248,8 +248,9 @@ module Liquid
BlockBody.raise_missing_variable_terminator(token, parse_context)
end
def registered_tags
Template.tags
def registered_tag(tag_name, parse_context)
context_tag = parse_context.tags[tag_name] if parse_context.tags.respond_to?(:[])
context_tag || Template.tags[tag_name]
end
end
end
+2 -1
View File
@@ -2,7 +2,7 @@
module Liquid
class ParseContext
attr_accessor :locale, :line_number, :trim_whitespace, :depth
attr_accessor :locale, :line_number, :trim_whitespace, :depth, :tags
attr_reader :partial, :warnings, :error_mode
def initialize(options = {})
@@ -10,6 +10,7 @@ module Liquid
@locale = @template_options[:locale] ||= I18n.new
@warnings = []
@tags = @template_options[:tags]
self.depth = 0
self.partial = false