Default to template name

This commit is contained in:
Mike Angell
2019-10-08 06:37:16 +11:00
parent e6a6d2e813
commit efaec29fa6
3 changed files with 13 additions and 23 deletions
+2 -2
View File
@@ -29,7 +29,7 @@ module Liquid
template_name = Regexp.last_match(1) template_name = Regexp.last_match(1)
variable_name = Regexp.last_match(3) variable_name = Regexp.last_match(3)
@alias_name = Regexp.last_match(5) || nil @alias_name = Regexp.last_match(5)
@variable_name_expr = variable_name ? Expression.parse(variable_name) : nil @variable_name_expr = variable_name ? Expression.parse(variable_name) : nil
@template_name_expr = Expression.parse(template_name) @template_name_expr = Expression.parse(template_name)
@attributes = {} @attributes = {}
@@ -56,7 +56,7 @@ module Liquid
parse_context: parse_context parse_context: parse_context
) )
context_variable_name = @alias_name ? @alias_name : template_name.split('/').last context_variable_name = @alias_name || template_name.split('/').last
variable = if @variable_name_expr variable = if @variable_name_expr
context.evaluate(@variable_name_expr) context.evaluate(@variable_name_expr)
+3 -3
View File
@@ -16,7 +16,7 @@ module Liquid
template_name = Regexp.last_match(1) template_name = Regexp.last_match(1)
variable_name = Regexp.last_match(3) variable_name = Regexp.last_match(3)
@alias_name = Regexp.last_match(5) || nil @alias_name = Regexp.last_match(5)
@variable_name_expr = variable_name ? Expression.parse(variable_name) : nil @variable_name_expr = variable_name ? Expression.parse(variable_name) : nil
@template_name_expr = Expression.parse(template_name) @template_name_expr = Expression.parse(template_name)
@@ -41,7 +41,7 @@ module Liquid
parse_context: parse_context parse_context: parse_context
) )
context_variable_name = @alias_name ? @alias_name : "this" context_variable_name = @alias_name || template_name.split('/').last
variable = if @variable_name_expr variable = if @variable_name_expr
context.evaluate(@variable_name_expr) context.evaluate(@variable_name_expr)
@@ -57,7 +57,7 @@ module Liquid
@attributes.each do |key, value| @attributes.each do |key, value|
inner_context[key] = context.evaluate(value) inner_context[key] = context.evaluate(value)
end end
inner_context[context_variable_name] = var inner_context[context_variable_name] = var if @variable_name_expr
partial.render_to_output_buffer(inner_context, output) partial.render_to_output_buffer(inner_context, output)
end end
+8 -18
View File
@@ -166,17 +166,17 @@ class RenderTagTest < Minitest::Test
assert_template_result('include usage is not allowed in this contextinclude usage is not allowed in this context', '{% render "nested_render_with_sibling_include" %}') assert_template_result('include usage is not allowed in this contextinclude usage is not allowed in this context', '{% render "nested_render_with_sibling_include" %}')
end end
def test_include_tag_with def test_render_tag_with
Liquid::Template.file_system = StubFileSystem.new( Liquid::Template.file_system = StubFileSystem.new(
'product' => "Product: {{ this.title }} ", 'product' => "Product: {{ product.title }} ",
'product_alias' => "Product: {{ this.title }} ", 'product_alias' => "Product: {{ product.title }} ",
) )
assert_template_result("Product: Draft 151cm ", assert_template_result("Product: Draft 151cm ",
"{% render 'product' with products[0] %}", "products" => [{ 'title' => 'Draft 151cm' }, { 'title' => 'Element 155cm' }]) "{% render 'product' with products[0] %}", "products" => [{ 'title' => 'Draft 151cm' }, { 'title' => 'Element 155cm' }])
end end
def test_include_tag_with_alias def test_render_tag_with_alias
Liquid::Template.file_system = StubFileSystem.new( Liquid::Template.file_system = StubFileSystem.new(
'product' => "Product: {{ product.title }} ", 'product' => "Product: {{ product.title }} ",
'product_alias' => "Product: {{ product.title }} ", 'product_alias' => "Product: {{ product.title }} ",
@@ -186,7 +186,7 @@ class RenderTagTest < Minitest::Test
"{% render 'product_alias' with products[0] as product %}", "products" => [{ 'title' => 'Draft 151cm' }, { 'title' => 'Element 155cm' }]) "{% render 'product_alias' with products[0] as product %}", "products" => [{ 'title' => 'Draft 151cm' }, { 'title' => 'Element 155cm' }])
end end
def test_include_tag_for_alias def test_render_tag_for_alias
Liquid::Template.file_system = StubFileSystem.new( Liquid::Template.file_system = StubFileSystem.new(
'product' => "Product: {{ product.title }} ", 'product' => "Product: {{ product.title }} ",
'product_alias' => "Product: {{ product.title }} ", 'product_alias' => "Product: {{ product.title }} ",
@@ -196,20 +196,10 @@ class RenderTagTest < Minitest::Test
"{% render 'product_alias' for products as product %}", "products" => [{ 'title' => 'Draft 151cm' }, { 'title' => 'Element 155cm' }]) "{% render 'product_alias' for products as product %}", "products" => [{ 'title' => 'Draft 151cm' }, { 'title' => 'Element 155cm' }])
end end
def test_include_tag_with_default_name def test_render_tag_for
Liquid::Template.file_system = StubFileSystem.new( Liquid::Template.file_system = StubFileSystem.new(
'product' => "Product: {{ this.title }} ", 'product' => "Product: {{ product.title }} ",
'product_alias' => "Product: {{ this.title }} ", 'product_alias' => "Product: {{ product.title }} ",
)
assert_template_result("Product: Draft 151cm ",
"{% render 'product' %}", "product" => { 'title' => 'Draft 151cm' })
end
def test_include_tag_for
Liquid::Template.file_system = StubFileSystem.new(
'product' => "Product: {{ this.title }} ",
'product_alias' => "Product: {{ this.title }} ",
) )
assert_template_result("Product: Draft 151cm Product: Element 155cm ", assert_template_result("Product: Draft 151cm Product: Element 155cm ",