mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-26 13:45:13 -07:00
Ensure render tag checks for most common type first
Previously, render tag would check if a template responded to `:to_partial` before checking if its name was a string. As `is_a?(String)` instances are more common that `to_partial`, this commit reorders the conditional to follow the common path
This commit is contained in:
@@ -49,14 +49,14 @@ module Liquid
|
|||||||
def render_tag(context, output)
|
def render_tag(context, output)
|
||||||
template = context.evaluate(@template_name_expr)
|
template = context.evaluate(@template_name_expr)
|
||||||
|
|
||||||
if template.respond_to?(:to_partial)
|
if @template_name_expr.is_a?(String)
|
||||||
partial = template.to_partial
|
|
||||||
template_name = template.filename
|
|
||||||
context_variable_name = @alias_name || template.name
|
|
||||||
elsif @template_name_expr.is_a?(String)
|
|
||||||
partial = PartialCache.load(template, context: context, parse_context: parse_context)
|
partial = PartialCache.load(template, context: context, parse_context: parse_context)
|
||||||
template_name = partial.name
|
template_name = partial.name
|
||||||
context_variable_name = @alias_name || template_name.split('/').last
|
context_variable_name = @alias_name || template_name.split('/').last
|
||||||
|
elsif template.respond_to?(:to_partial) && template.respond_to?(:name)
|
||||||
|
partial = template.to_partial
|
||||||
|
template_name = template.filename
|
||||||
|
context_variable_name = @alias_name || template.name
|
||||||
else
|
else
|
||||||
raise ::ArgumentError
|
raise ::ArgumentError
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user