mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-12 23:40:45 -07:00
Change inline snippet identifier from string to variable
Currently, snippet files identified by strings. This PR makes changes to render to allow for new inline snippets to use variables as identifiers instead
This commit is contained in:
committed by
Guilherme Carreiro
parent
12bbbc4537
commit
c7ad1c90ca
@@ -27,7 +27,7 @@ module Liquid
|
||||
# @liquid_syntax_keyword filename The name of the snippet to render, without the `.liquid` extension.
|
||||
class Render < Tag
|
||||
FOR = 'for'
|
||||
SYNTAX = /(#{QuotedString}+)(\s+(with|#{FOR})\s+(#{QuotedFragment}+))?(\s+(?:as)\s+(#{VariableSegment}+))?/o
|
||||
SYNTAX = /(#{QuotedString}+|#{VariableSegment}+)(\s+(with|#{FOR})\s+(#{QuotedFragment}+))?(\s+(?:as)\s+(#{VariableSegment}+))?/o
|
||||
|
||||
disable_tags "include"
|
||||
|
||||
@@ -51,12 +51,15 @@ module Liquid
|
||||
end
|
||||
|
||||
def render_tag(context, output)
|
||||
# The expression should be a String literal, which parses to a String object
|
||||
template_name = @template_name_expr
|
||||
raise ::ArgumentError unless template_name.is_a?(String)
|
||||
|
||||
if context[template_name].is_a?(Liquid::SnippetDrop)
|
||||
snippet_drop = context[template_name]
|
||||
# For inline snippets, @template_name_expr is a VariableLookup
|
||||
if template_name.is_a?(VariableLookup)
|
||||
|
||||
snippet_drop = context[template_name.name]
|
||||
|
||||
raise ::ArgumentError unless snippet_drop.is_a?(Liquid::SnippetDrop)
|
||||
|
||||
inner_context = context.new_isolated_subcontext
|
||||
|
||||
if inherit_context?
|
||||
@@ -74,6 +77,9 @@ module Liquid
|
||||
return output << snippet_drop.body.render(inner_context)
|
||||
end
|
||||
|
||||
# Otherwise, the expression should be a String literal, which parses to a String object
|
||||
raise ::ArgumentError unless template_name.is_a?(String)
|
||||
|
||||
partial = PartialCache.load(
|
||||
template_name,
|
||||
context: context,
|
||||
|
||||
Reference in New Issue
Block a user