mirror of
https://github.com/kemko/liquid.git
synced 2026-01-02 08:15:41 +03:00
Compare commits
9 Commits
context-dr
...
render-for
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
baf21ec3cc | ||
|
|
7f1e25005b | ||
|
|
938ca78be6 | ||
|
|
03a5375c8c | ||
|
|
a46610065a | ||
|
|
1223444738 | ||
|
|
2bfeed2b00 | ||
|
|
04b800d768 | ||
|
|
f1d62978ef |
@@ -7,6 +7,7 @@ module Liquid
|
|||||||
def initialize(tag_name, markup, options)
|
def initialize(tag_name, markup, options)
|
||||||
super
|
super
|
||||||
@blank = true
|
@blank = true
|
||||||
|
@body = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse(tokens)
|
def parse(tokens)
|
||||||
@@ -17,7 +18,7 @@ module Liquid
|
|||||||
|
|
||||||
# For backwards compatibility
|
# For backwards compatibility
|
||||||
def render(context)
|
def render(context)
|
||||||
@body.render(context)
|
@body&.render(context)
|
||||||
end
|
end
|
||||||
|
|
||||||
def blank?
|
def blank?
|
||||||
|
|||||||
@@ -421,13 +421,20 @@ module Liquid
|
|||||||
result.is_a?(BigDecimal) ? result.to_f : result
|
result.is_a?(BigDecimal) ? result.to_f : result
|
||||||
end
|
end
|
||||||
|
|
||||||
def default(input, default_value = '')
|
# Set a default value when the input is nil, false or empty
|
||||||
if !input || input.respond_to?(:empty?) && input.empty?
|
#
|
||||||
Usage.increment("default_filter_received_false_value") if input == false # See https://github.com/Shopify/liquid/issues/1127
|
# Example:
|
||||||
default_value
|
# {{ product.title | default: "No Title" }}
|
||||||
else
|
#
|
||||||
input
|
# Use `allow_false` when an input should only be tested against nil or empty and not false.
|
||||||
end
|
#
|
||||||
|
# Example:
|
||||||
|
# {{ product.title | default: "No Title", allow_false: true }}
|
||||||
|
#
|
||||||
|
def default(input, default_value = '', options = {})
|
||||||
|
options = {} unless options.is_a?(Hash)
|
||||||
|
false_check = options['allow_false'] ? input.nil? : !input
|
||||||
|
false_check || (input.respond_to?(:empty?) && input.empty?) ? default_value : input
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
module Liquid
|
module Liquid
|
||||||
class Tag
|
class Tag
|
||||||
attr_reader :nodelist, :tag_name, :line_number, :parse_context
|
attr_reader :nodelist, :tag_name, :line_number, :parse_context, :markup
|
||||||
alias_method :options, :parse_context
|
alias_method :options, :parse_context
|
||||||
include ParserSwitching
|
include ParserSwitching
|
||||||
|
|
||||||
@@ -17,8 +17,6 @@ module Liquid
|
|||||||
disabled_tags.push(*tags)
|
disabled_tags.push(*tags)
|
||||||
end
|
end
|
||||||
|
|
||||||
private :new
|
|
||||||
|
|
||||||
def disabled_tags
|
def disabled_tags
|
||||||
@disabled_tags ||= []
|
@disabled_tags ||= []
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -18,8 +18,7 @@ module Liquid
|
|||||||
|
|
||||||
attr_reader :to, :from
|
attr_reader :to, :from
|
||||||
|
|
||||||
def initialize(tag_name, markup, options)
|
def parse(_tokens)
|
||||||
super
|
|
||||||
if markup =~ Syntax
|
if markup =~ Syntax
|
||||||
@to = Regexp.last_match(1)
|
@to = Regexp.last_match(1)
|
||||||
@from = Variable.new(Regexp.last_match(2), options)
|
@from = Variable.new(Regexp.last_match(2), options)
|
||||||
|
|||||||
@@ -15,13 +15,13 @@ module Liquid
|
|||||||
class Capture < Block
|
class Capture < Block
|
||||||
Syntax = /(#{VariableSignature}+)/o
|
Syntax = /(#{VariableSignature}+)/o
|
||||||
|
|
||||||
def initialize(tag_name, markup, options)
|
def parse(_tokens)
|
||||||
super
|
|
||||||
if markup =~ Syntax
|
if markup =~ Syntax
|
||||||
@to = Regexp.last_match(1)
|
@to = Regexp.last_match(1)
|
||||||
else
|
else
|
||||||
raise SyntaxError, options[:locale].t("errors.syntax.capture")
|
raise SyntaxError, options[:locale].t("errors.syntax.capture")
|
||||||
end
|
end
|
||||||
|
super
|
||||||
end
|
end
|
||||||
|
|
||||||
def render_to_output_buffer(context, output)
|
def render_to_output_buffer(context, output)
|
||||||
|
|||||||
@@ -7,8 +7,7 @@ module Liquid
|
|||||||
|
|
||||||
attr_reader :blocks, :left
|
attr_reader :blocks, :left
|
||||||
|
|
||||||
def initialize(tag_name, markup, options)
|
def parse(tokens)
|
||||||
super
|
|
||||||
@blocks = []
|
@blocks = []
|
||||||
|
|
||||||
if markup =~ Syntax
|
if markup =~ Syntax
|
||||||
@@ -16,9 +15,7 @@ module Liquid
|
|||||||
else
|
else
|
||||||
raise SyntaxError, options[:locale].t("errors.syntax.case")
|
raise SyntaxError, options[:locale].t("errors.syntax.case")
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def parse(tokens)
|
|
||||||
body = BlockBody.new
|
body = BlockBody.new
|
||||||
body = @blocks.last.attachment while parse_body(body, tokens)
|
body = @blocks.last.attachment while parse_body(body, tokens)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -19,8 +19,7 @@ module Liquid
|
|||||||
|
|
||||||
attr_reader :variables
|
attr_reader :variables
|
||||||
|
|
||||||
def initialize(tag_name, markup, options)
|
def parse(_tokens)
|
||||||
super
|
|
||||||
case markup
|
case markup
|
||||||
when NamedSyntax
|
when NamedSyntax
|
||||||
@variables = variables_from_string(Regexp.last_match(2))
|
@variables = variables_from_string(Regexp.last_match(2))
|
||||||
|
|||||||
@@ -20,8 +20,7 @@ module Liquid
|
|||||||
# Hello: -3
|
# Hello: -3
|
||||||
#
|
#
|
||||||
class Decrement < Tag
|
class Decrement < Tag
|
||||||
def initialize(tag_name, markup, options)
|
def parse(_tokens)
|
||||||
super
|
|
||||||
@variable = markup.strip
|
@variable = markup.strip
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -12,13 +12,14 @@ module Liquid
|
|||||||
# {% echo user | link %}
|
# {% echo user | link %}
|
||||||
#
|
#
|
||||||
class Echo < Tag
|
class Echo < Tag
|
||||||
def initialize(tag_name, markup, parse_context)
|
attr_reader :variable
|
||||||
super
|
|
||||||
|
def parse(_tokens)
|
||||||
@variable = Variable.new(markup, parse_context)
|
@variable = Variable.new(markup, parse_context)
|
||||||
end
|
end
|
||||||
|
|
||||||
def render(context)
|
def render(context)
|
||||||
@variable.render_to_output_buffer(context, +'')
|
variable&.render_to_output_buffer(context, +'')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -50,15 +50,11 @@ module Liquid
|
|||||||
|
|
||||||
attr_reader :collection_name, :variable_name, :limit, :from
|
attr_reader :collection_name, :variable_name, :limit, :from
|
||||||
|
|
||||||
def initialize(tag_name, markup, options)
|
def parse(tokens)
|
||||||
super
|
|
||||||
@from = @limit = nil
|
@from = @limit = nil
|
||||||
parse_with_selected_parser(markup)
|
parse_with_selected_parser(markup)
|
||||||
@for_block = BlockBody.new
|
@for_block = BlockBody.new
|
||||||
@else_block = nil
|
@else_block = nil
|
||||||
end
|
|
||||||
|
|
||||||
def parse(tokens)
|
|
||||||
return unless parse_body(@for_block, tokens)
|
return unless parse_body(@for_block, tokens)
|
||||||
parse_body(@else_block, tokens)
|
parse_body(@else_block, tokens)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -18,17 +18,13 @@ module Liquid
|
|||||||
|
|
||||||
attr_reader :blocks
|
attr_reader :blocks
|
||||||
|
|
||||||
def initialize(tag_name, markup, options)
|
|
||||||
super
|
|
||||||
@blocks = []
|
|
||||||
push_block('if', markup)
|
|
||||||
end
|
|
||||||
|
|
||||||
def nodelist
|
def nodelist
|
||||||
@blocks.map(&:attachment)
|
@blocks.map(&:attachment)
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse(tokens)
|
def parse(tokens)
|
||||||
|
@blocks = []
|
||||||
|
push_block('if', markup)
|
||||||
while parse_body(@blocks.last.attachment, tokens)
|
while parse_body(@blocks.last.attachment, tokens)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -16,18 +16,18 @@ module Liquid
|
|||||||
# {% include 'product' for products %}
|
# {% include 'product' for products %}
|
||||||
#
|
#
|
||||||
class Include < Tag
|
class Include < Tag
|
||||||
Syntax = /(#{QuotedFragment}+)(\s+(?:with|for)\s+(#{QuotedFragment}+))?/o
|
SYNTAX = /(#{QuotedFragment}+)(\s+(?:with|for)\s+(#{QuotedFragment}+))?(\s+(?:as)\s+(#{VariableSegment}+))?/o
|
||||||
|
Syntax = SYNTAX
|
||||||
|
|
||||||
attr_reader :template_name_expr, :variable_name_expr, :attributes
|
attr_reader :template_name_expr, :variable_name_expr, :attributes
|
||||||
|
|
||||||
def initialize(tag_name, markup, options)
|
def parse(_tokens)
|
||||||
super
|
if markup =~ SYNTAX
|
||||||
|
|
||||||
if markup =~ Syntax
|
|
||||||
|
|
||||||
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)
|
||||||
@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 = {}
|
||||||
@@ -41,9 +41,6 @@ module Liquid
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse(_tokens)
|
|
||||||
end
|
|
||||||
|
|
||||||
def render_to_output_buffer(context, output)
|
def render_to_output_buffer(context, output)
|
||||||
template_name = context.evaluate(@template_name_expr)
|
template_name = context.evaluate(@template_name_expr)
|
||||||
raise ArgumentError, options[:locale].t("errors.argument.include") unless template_name
|
raise ArgumentError, options[:locale].t("errors.argument.include") unless template_name
|
||||||
@@ -54,7 +51,7 @@ module Liquid
|
|||||||
parse_context: parse_context
|
parse_context: parse_context
|
||||||
)
|
)
|
||||||
|
|
||||||
context_variable_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)
|
||||||
|
|||||||
@@ -17,8 +17,7 @@ module Liquid
|
|||||||
# Hello: 2
|
# Hello: 2
|
||||||
#
|
#
|
||||||
class Increment < Tag
|
class Increment < Tag
|
||||||
def initialize(tag_name, markup, options)
|
def parse(_tokens)
|
||||||
super
|
|
||||||
@variable = markup.strip
|
@variable = markup.strip
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -5,13 +5,8 @@ module Liquid
|
|||||||
Syntax = /\A\s*\z/
|
Syntax = /\A\s*\z/
|
||||||
FullTokenPossiblyInvalid = /\A(.*)#{TagStart}\s*(\w+)\s*(.*)?#{TagEnd}\z/om
|
FullTokenPossiblyInvalid = /\A(.*)#{TagStart}\s*(\w+)\s*(.*)?#{TagEnd}\z/om
|
||||||
|
|
||||||
def initialize(tag_name, markup, parse_context)
|
|
||||||
super
|
|
||||||
|
|
||||||
ensure_valid_markup(tag_name, markup, parse_context)
|
|
||||||
end
|
|
||||||
|
|
||||||
def parse(tokens)
|
def parse(tokens)
|
||||||
|
ensure_valid_markup(tag_name, markup, parse_context)
|
||||||
@body = +''
|
@body = +''
|
||||||
while (token = tokens.shift)
|
while (token = tokens.shift)
|
||||||
if token =~ FullTokenPossiblyInvalid
|
if token =~ FullTokenPossiblyInvalid
|
||||||
|
|||||||
@@ -2,19 +2,20 @@
|
|||||||
|
|
||||||
module Liquid
|
module Liquid
|
||||||
class Render < Tag
|
class Render < Tag
|
||||||
SYNTAX = /(#{QuotedString})#{QuotedFragment}*/o
|
SYNTAX = /(#{QuotedString}+)(\s+(?:with|for)\s+(#{QuotedFragment}+))?(\s+(?:as)\s+(#{VariableSegment}+))?/o
|
||||||
|
|
||||||
disable_tags "include"
|
disable_tags "include"
|
||||||
|
|
||||||
attr_reader :template_name_expr, :attributes
|
attr_reader :template_name_expr, :attributes
|
||||||
|
|
||||||
def initialize(tag_name, markup, options)
|
def parse(_tokens)
|
||||||
super
|
|
||||||
|
|
||||||
raise SyntaxError, options[:locale].t("errors.syntax.render") unless markup =~ SYNTAX
|
raise SyntaxError, options[:locale].t("errors.syntax.render") unless markup =~ SYNTAX
|
||||||
|
|
||||||
template_name = Regexp.last_match(1)
|
template_name = Regexp.last_match(1)
|
||||||
|
variable_name = Regexp.last_match(3)
|
||||||
|
|
||||||
|
@alias_name = Regexp.last_match(5)
|
||||||
|
@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 = {}
|
||||||
@@ -38,13 +39,21 @@ module Liquid
|
|||||||
parse_context: parse_context
|
parse_context: parse_context
|
||||||
)
|
)
|
||||||
|
|
||||||
inner_context = context.new_isolated_subcontext
|
context_variable_name = @alias_name || template_name.split('/').last
|
||||||
inner_context.template_name = template_name
|
|
||||||
inner_context.partial = true
|
render_partial_func = ->(var) {
|
||||||
@attributes.each do |key, value|
|
inner_context = context.new_isolated_subcontext
|
||||||
inner_context[key] = context.evaluate(value)
|
inner_context.template_name = template_name
|
||||||
end
|
inner_context.partial = true
|
||||||
partial.render_to_output_buffer(inner_context, output)
|
@attributes.each do |key, value|
|
||||||
|
inner_context[key] = context.evaluate(value)
|
||||||
|
end
|
||||||
|
inner_context[context_variable_name] = var unless var.nil?
|
||||||
|
partial.render_to_output_buffer(inner_context, output)
|
||||||
|
}
|
||||||
|
|
||||||
|
variable = @variable_name_expr ? context.evaluate(@variable_name_expr) : nil
|
||||||
|
variable.is_a?(Array) ? variable.each(&render_partial_func) : render_partial_func.call(variable)
|
||||||
|
|
||||||
output
|
output
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -6,8 +6,7 @@ module Liquid
|
|||||||
|
|
||||||
attr_reader :variable_name, :collection_name, :attributes
|
attr_reader :variable_name, :collection_name, :attributes
|
||||||
|
|
||||||
def initialize(tag_name, markup, options)
|
def parse(_tokens)
|
||||||
super
|
|
||||||
if markup =~ Syntax
|
if markup =~ Syntax
|
||||||
@variable_name = Regexp.last_match(1)
|
@variable_name = Regexp.last_match(1)
|
||||||
@collection_name = Expression.parse(Regexp.last_match(2))
|
@collection_name = Expression.parse(Regexp.last_match(2))
|
||||||
@@ -18,6 +17,7 @@ module Liquid
|
|||||||
else
|
else
|
||||||
raise SyntaxError, options[:locale].t("errors.syntax.table_row")
|
raise SyntaxError, options[:locale].t("errors.syntax.table_row")
|
||||||
end
|
end
|
||||||
|
super
|
||||||
end
|
end
|
||||||
|
|
||||||
def render_to_output_buffer(context, output)
|
def render_to_output_buffer(context, output)
|
||||||
|
|||||||
@@ -154,18 +154,18 @@ class RenderProfilingTest < Minitest::Test
|
|||||||
assert_equal(2, t.profiler[0].children.length)
|
assert_equal(2, t.profiler[0].children.length)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_total_time_equals_self_time_in_leaf
|
def test_profiling_supports_self_time
|
||||||
t = Template.parse("{% for item in collection %} {{ item }} {% endfor %}", profile: true)
|
t = Template.parse("{% for item in collection %} {{ item }} {% endfor %}", profile: true)
|
||||||
t.render!("collection" => ["one", "two"])
|
t.render!("collection" => ["one", "two"])
|
||||||
leaf = t.profiler[0].children[0]
|
leaf = t.profiler[0].children[0]
|
||||||
|
|
||||||
assert_equal leaf.total_time, leaf.self_time
|
assert_operator leaf.self_time, :>, 0
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_total_time_greater_than_self_time_in_node
|
def test_profiling_supports_total_time
|
||||||
t = Template.parse("{% if true %} {% increment test %} {{ test }} {% endif %}", profile: true)
|
t = Template.parse("{% if true %} {% increment test %} {{ test }} {% endif %}", profile: true)
|
||||||
t.render!
|
t.render!
|
||||||
|
|
||||||
assert_operator t.profiler[0].total_time, :>, t.profiler[0].self_time
|
assert_operator t.profiler[0].total_time, :>, 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -685,6 +685,17 @@ class StandardFiltersTest < Minitest::Test
|
|||||||
assert_equal("bar", @filters.default(false, "bar"))
|
assert_equal("bar", @filters.default(false, "bar"))
|
||||||
assert_equal("bar", @filters.default([], "bar"))
|
assert_equal("bar", @filters.default([], "bar"))
|
||||||
assert_equal("bar", @filters.default({}, "bar"))
|
assert_equal("bar", @filters.default({}, "bar"))
|
||||||
|
assert_template_result('bar', "{{ false | default: 'bar' }}")
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_default_handle_false
|
||||||
|
assert_equal("foo", @filters.default("foo", "bar", "allow_false" => true))
|
||||||
|
assert_equal("bar", @filters.default(nil, "bar", "allow_false" => true))
|
||||||
|
assert_equal("bar", @filters.default("", "bar", "allow_false" => true))
|
||||||
|
assert_equal(false, @filters.default(false, "bar", "allow_false" => true))
|
||||||
|
assert_equal("bar", @filters.default([], "bar", "allow_false" => true))
|
||||||
|
assert_equal("bar", @filters.default({}, "bar", "allow_false" => true))
|
||||||
|
assert_template_result('false', "{{ false | default: 'bar', allow_false: true }}")
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_cannot_access_private_methods
|
def test_cannot_access_private_methods
|
||||||
|
|||||||
20
test/integration/tag_test.rb
Normal file
20
test/integration/tag_test.rb
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class TagTest < Minitest::Test
|
||||||
|
include Liquid
|
||||||
|
|
||||||
|
def test_all_tags_with_no_parse_can_render
|
||||||
|
Template.tags.each do |key, _tag|
|
||||||
|
Template.tags[key].new(key, '', ParseContext.new).render(Context.new)
|
||||||
|
assert_nil(nil)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_all_tags_are_registered
|
||||||
|
tags = Template.tags.map { |key, _tag| key }
|
||||||
|
expected_tags = %w(assign break capture case comment continue cycle decrement echo for if ifchanged include increment raw render tablerow unless)
|
||||||
|
assert_equal(expected_tags, tags.sort)
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -8,6 +8,9 @@ class TestFileSystem
|
|||||||
when "product"
|
when "product"
|
||||||
"Product: {{ product.title }} "
|
"Product: {{ product.title }} "
|
||||||
|
|
||||||
|
when "product_alias"
|
||||||
|
"Product: {{ product.title }} "
|
||||||
|
|
||||||
when "locale_variables"
|
when "locale_variables"
|
||||||
"Locale: {{echo1}} {{echo2}}"
|
"Locale: {{echo1}} {{echo2}}"
|
||||||
|
|
||||||
@@ -91,6 +94,16 @@ class IncludeTagTest < Minitest::Test
|
|||||||
"{% include 'product' with products[0] %}", "products" => [{ 'title' => 'Draft 151cm' }, { 'title' => 'Element 155cm' }])
|
"{% include 'product' with products[0] %}", "products" => [{ 'title' => 'Draft 151cm' }, { 'title' => 'Element 155cm' }])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_include_tag_with_alias
|
||||||
|
assert_template_result("Product: Draft 151cm ",
|
||||||
|
"{% include 'product_alias' with products[0] as product %}", "products" => [{ 'title' => 'Draft 151cm' }, { 'title' => 'Element 155cm' }])
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_include_tag_for_alias
|
||||||
|
assert_template_result("Product: Draft 151cm Product: Element 155cm ",
|
||||||
|
"{% include 'product_alias' for products as product %}", "products" => [{ 'title' => 'Draft 151cm' }, { 'title' => 'Element 155cm' }])
|
||||||
|
end
|
||||||
|
|
||||||
def test_include_tag_with_default_name
|
def test_include_tag_with_default_name
|
||||||
assert_template_result("Product: Draft 151cm ",
|
assert_template_result("Product: Draft 151cm ",
|
||||||
"{% include 'product' %}", "product" => { 'title' => 'Draft 151cm' })
|
"{% include 'product' %}", "product" => { 'title' => 'Draft 151cm' })
|
||||||
|
|||||||
@@ -165,4 +165,44 @@ 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_render_tag_with
|
||||||
|
Liquid::Template.file_system = StubFileSystem.new(
|
||||||
|
'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_render_tag_with_alias
|
||||||
|
Liquid::Template.file_system = StubFileSystem.new(
|
||||||
|
'product' => "Product: {{ product.title }} ",
|
||||||
|
'product_alias' => "Product: {{ product.title }} ",
|
||||||
|
)
|
||||||
|
|
||||||
|
assert_template_result("Product: Draft 151cm ",
|
||||||
|
"{% render 'product_alias' with products[0] as product %}", "products" => [{ 'title' => 'Draft 151cm' }, { 'title' => 'Element 155cm' }])
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_render_tag_for_alias
|
||||||
|
Liquid::Template.file_system = StubFileSystem.new(
|
||||||
|
'product' => "Product: {{ product.title }} ",
|
||||||
|
'product_alias' => "Product: {{ product.title }} ",
|
||||||
|
)
|
||||||
|
|
||||||
|
assert_template_result("Product: Draft 151cm Product: Element 155cm ",
|
||||||
|
"{% render 'product_alias' for products as product %}", "products" => [{ 'title' => 'Draft 151cm' }, { 'title' => 'Element 155cm' }])
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_render_tag_for
|
||||||
|
Liquid::Template.file_system = StubFileSystem.new(
|
||||||
|
'product' => "Product: {{ product.title }} ",
|
||||||
|
'product_alias' => "Product: {{ product.title }} ",
|
||||||
|
)
|
||||||
|
|
||||||
|
assert_template_result("Product: Draft 151cm Product: Element 155cm ",
|
||||||
|
"{% render 'product' for products %}", "products" => [{ 'title' => 'Draft 151cm' }, { 'title' => 'Element 155cm' }])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user