mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-15 00:40:40 -07:00
Default to template name
This commit is contained in:
@@ -29,7 +29,7 @@ module Liquid
|
||||
template_name = Regexp.last_match(1)
|
||||
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
|
||||
@template_name_expr = Expression.parse(template_name)
|
||||
@attributes = {}
|
||||
@@ -56,7 +56,7 @@ module Liquid
|
||||
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
|
||||
context.evaluate(@variable_name_expr)
|
||||
|
||||
@@ -16,7 +16,7 @@ module Liquid
|
||||
template_name = Regexp.last_match(1)
|
||||
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
|
||||
@template_name_expr = Expression.parse(template_name)
|
||||
|
||||
@@ -41,7 +41,7 @@ module Liquid
|
||||
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
|
||||
context.evaluate(@variable_name_expr)
|
||||
@@ -57,7 +57,7 @@ module Liquid
|
||||
@attributes.each do |key, value|
|
||||
inner_context[key] = context.evaluate(value)
|
||||
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)
|
||||
end
|
||||
|
||||
|
||||
@@ -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" %}')
|
||||
end
|
||||
|
||||
def test_include_tag_with
|
||||
def test_render_tag_with
|
||||
Liquid::Template.file_system = StubFileSystem.new(
|
||||
'product' => "Product: {{ this.title }} ",
|
||||
'product_alias' => "Product: {{ this.title }} ",
|
||||
'product' => "Product: {{ product.title }} ",
|
||||
'product_alias' => "Product: {{ product.title }} ",
|
||||
)
|
||||
|
||||
assert_template_result("Product: Draft 151cm ",
|
||||
"{% render 'product' with products[0] %}", "products" => [{ 'title' => 'Draft 151cm' }, { 'title' => 'Element 155cm' }])
|
||||
end
|
||||
|
||||
def test_include_tag_with_alias
|
||||
def test_render_tag_with_alias
|
||||
Liquid::Template.file_system = StubFileSystem.new(
|
||||
'product' => "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' }])
|
||||
end
|
||||
|
||||
def test_include_tag_for_alias
|
||||
def test_render_tag_for_alias
|
||||
Liquid::Template.file_system = StubFileSystem.new(
|
||||
'product' => "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' }])
|
||||
end
|
||||
|
||||
def test_include_tag_with_default_name
|
||||
def test_render_tag_for
|
||||
Liquid::Template.file_system = StubFileSystem.new(
|
||||
'product' => "Product: {{ this.title }} ",
|
||||
'product_alias' => "Product: {{ this.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 }} ",
|
||||
'product' => "Product: {{ product.title }} ",
|
||||
'product_alias' => "Product: {{ product.title }} ",
|
||||
)
|
||||
|
||||
assert_template_result("Product: Draft 151cm Product: Element 155cm ",
|
||||
|
||||
Reference in New Issue
Block a user