From 60b4182b7edf2cda7df7626dfc0c48ed94741c20 Mon Sep 17 00:00:00 2001 From: Mike Angell Date: Tue, 8 Oct 2019 07:24:32 +1100 Subject: [PATCH] Improve variable matching --- lib/liquid/tags/include.rb | 2 +- lib/liquid/tags/render.rb | 10 +++------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/liquid/tags/include.rb b/lib/liquid/tags/include.rb index 1a7ba4a..d90c731 100644 --- a/lib/liquid/tags/include.rb +++ b/lib/liquid/tags/include.rb @@ -16,7 +16,7 @@ module Liquid # {% include 'product' for products %} # class Include < Tag - SYNTAX = /(#{QuotedFragment}+)(\s+(?:with|for)\s+(#{QuotedFragment}+))?(\s+(?:as)\s+(#{VariableSignature}+))?/o + SYNTAX = /(#{QuotedFragment}+)(\s+(?:with|for)\s+(#{QuotedFragment}+))?(\s+(?:as)\s+(#{VariableSegment}+))?/o Syntax = SYNTAX attr_reader :template_name_expr, :variable_name_expr, :attributes diff --git a/lib/liquid/tags/render.rb b/lib/liquid/tags/render.rb index 1e0bdcc..9eb3513 100644 --- a/lib/liquid/tags/render.rb +++ b/lib/liquid/tags/render.rb @@ -2,7 +2,7 @@ module Liquid class Render < Tag - SYNTAX = /(#{QuotedString}+)(\s+(?:with|for)\s+(#{QuotedFragment}+))?(\s+(?:as)\s+(#{VariableSignature}+))?/o + SYNTAX = /(#{QuotedString}+)(\s+(?:with|for)\s+(#{QuotedFragment}+))?(\s+(?:as)\s+(#{VariableSegment}+))?/o disable_tags "include" @@ -43,11 +43,7 @@ module Liquid context_variable_name = @alias_name || template_name.split('/').last - variable = if @variable_name_expr - context.evaluate(@variable_name_expr) - else - context.find_variable(template_name, raise_on_not_found: false) - end + variable = @variable_name_expr ? context.evaluate(@variable_name_expr) : nil variable = [variable] unless variable.is_a?(Array) variable.each do |var| @@ -57,7 +53,7 @@ module Liquid @attributes.each do |key, value| inner_context[key] = context.evaluate(value) end - inner_context[context_variable_name] = var if @variable_name_expr + inner_context[context_variable_name] = var unless var.nil? partial.render_to_output_buffer(inner_context, output) end