mirror of
https://github.com/kemko/liquid.git
synced 2026-01-03 16:55:40 +03:00
Compare commits
2 Commits
shopify_ru
...
remove-laz
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dafbb4ae90 | ||
|
|
2324564743 |
@@ -25,8 +25,6 @@ module Liquid
|
|||||||
@resource_limits = resource_limits || ResourceLimits.new(Template.default_resource_limits)
|
@resource_limits = resource_limits || ResourceLimits.new(Template.default_resource_limits)
|
||||||
squash_instance_assigns_with_environments
|
squash_instance_assigns_with_environments
|
||||||
|
|
||||||
@this_stack_used = false
|
|
||||||
|
|
||||||
self.exception_renderer = Template.default_exception_renderer
|
self.exception_renderer = Template.default_exception_renderer
|
||||||
if rethrow_errors
|
if rethrow_errors
|
||||||
self.exception_renderer = ->(e) { raise }
|
self.exception_renderer = ->(e) { raise }
|
||||||
@@ -111,19 +109,11 @@ module Liquid
|
|||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
# context['var] #=> nil
|
# context['var] #=> nil
|
||||||
def stack(new_scope = nil)
|
def stack(new_scope = {})
|
||||||
old_stack_used = @this_stack_used
|
push(new_scope)
|
||||||
if new_scope
|
|
||||||
push(new_scope)
|
|
||||||
@this_stack_used = true
|
|
||||||
else
|
|
||||||
@this_stack_used = false
|
|
||||||
end
|
|
||||||
|
|
||||||
yield
|
yield
|
||||||
ensure
|
ensure
|
||||||
pop if @this_stack_used
|
pop
|
||||||
@this_stack_used = old_stack_used
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def clear_instance_assigns
|
def clear_instance_assigns
|
||||||
@@ -132,10 +122,6 @@ module Liquid
|
|||||||
|
|
||||||
# Only allow String, Numeric, Hash, Array, Proc, Boolean or <tt>Liquid::Drop</tt>
|
# Only allow String, Numeric, Hash, Array, Proc, Boolean or <tt>Liquid::Drop</tt>
|
||||||
def []=(key, value)
|
def []=(key, value)
|
||||||
unless @this_stack_used
|
|
||||||
@this_stack_used = true
|
|
||||||
push({})
|
|
||||||
end
|
|
||||||
@scopes[0][key] = value
|
@scopes[0][key] = value
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -39,16 +39,14 @@ module Liquid
|
|||||||
end
|
end
|
||||||
|
|
||||||
def render_to_output_buffer(context, output)
|
def render_to_output_buffer(context, output)
|
||||||
context.stack do
|
execute_else_block = true
|
||||||
execute_else_block = true
|
|
||||||
|
|
||||||
@blocks.each do |block|
|
@blocks.each do |block|
|
||||||
if block.else?
|
if block.else?
|
||||||
block.attachment.render_to_output_buffer(context, output) if execute_else_block
|
block.attachment.render_to_output_buffer(context, output) if execute_else_block
|
||||||
elsif block.evaluate(context)
|
elsif block.evaluate(context)
|
||||||
execute_else_block = false
|
execute_else_block = false
|
||||||
block.attachment.render_to_output_buffer(context, output)
|
block.attachment.render_to_output_buffer(context, output)
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -34,25 +34,23 @@ module Liquid
|
|||||||
def render_to_output_buffer(context, output)
|
def render_to_output_buffer(context, output)
|
||||||
context.registers[:cycle] ||= {}
|
context.registers[:cycle] ||= {}
|
||||||
|
|
||||||
context.stack do
|
key = context.evaluate(@name)
|
||||||
key = context.evaluate(@name)
|
iteration = context.registers[:cycle][key].to_i
|
||||||
iteration = context.registers[:cycle][key].to_i
|
|
||||||
|
|
||||||
val = context.evaluate(@variables[iteration])
|
val = context.evaluate(@variables[iteration])
|
||||||
|
|
||||||
if val.is_a?(Array)
|
if val.is_a?(Array)
|
||||||
val = val.join
|
val = val.join
|
||||||
elsif !val.is_a?(String)
|
elsif !val.is_a?(String)
|
||||||
val = val.to_s
|
val = val.to_s
|
||||||
end
|
|
||||||
|
|
||||||
output << val
|
|
||||||
|
|
||||||
iteration += 1
|
|
||||||
iteration = 0 if iteration >= @variables.size
|
|
||||||
context.registers[:cycle][key] = iteration
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
output << val
|
||||||
|
|
||||||
|
iteration += 1
|
||||||
|
iteration = 0 if iteration >= @variables.size
|
||||||
|
context.registers[:cycle][key] = iteration
|
||||||
|
|
||||||
output
|
output
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -40,11 +40,9 @@ module Liquid
|
|||||||
end
|
end
|
||||||
|
|
||||||
def render_to_output_buffer(context, output)
|
def render_to_output_buffer(context, output)
|
||||||
context.stack do
|
@blocks.each do |block|
|
||||||
@blocks.each do |block|
|
if block.evaluate(context)
|
||||||
if block.evaluate(context)
|
return block.attachment.render_to_output_buffer(context, output)
|
||||||
return block.attachment.render_to_output_buffer(context, output)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,12 @@
|
|||||||
module Liquid
|
module Liquid
|
||||||
class Ifchanged < Block
|
class Ifchanged < Block
|
||||||
def render_to_output_buffer(context, output)
|
def render_to_output_buffer(context, output)
|
||||||
context.stack do
|
block_output = ''
|
||||||
block_output = ''
|
super(context, block_output)
|
||||||
super(context, block_output)
|
|
||||||
|
|
||||||
if block_output != context.registers[:ifchanged]
|
if block_output != context.registers[:ifchanged]
|
||||||
context.registers[:ifchanged] = block_output
|
context.registers[:ifchanged] = block_output
|
||||||
output << block_output
|
output << block_output
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
output
|
output
|
||||||
|
|||||||
@@ -7,18 +7,16 @@ module Liquid
|
|||||||
#
|
#
|
||||||
class Unless < If
|
class Unless < If
|
||||||
def render_to_output_buffer(context, output)
|
def render_to_output_buffer(context, output)
|
||||||
context.stack do
|
# First condition is interpreted backwards ( if not )
|
||||||
# First condition is interpreted backwards ( if not )
|
first_block = @blocks.first
|
||||||
first_block = @blocks.first
|
unless first_block.evaluate(context)
|
||||||
unless first_block.evaluate(context)
|
return first_block.attachment.render_to_output_buffer(context, output)
|
||||||
return first_block.attachment.render_to_output_buffer(context, output)
|
end
|
||||||
end
|
|
||||||
|
|
||||||
# After the first condition unless works just like if
|
# After the first condition unless works just like if
|
||||||
@blocks[1..-1].each do |block|
|
@blocks[1..-1].each do |block|
|
||||||
if block.evaluate(context)
|
if block.evaluate(context)
|
||||||
return block.attachment.render_to_output_buffer(context, output)
|
return block.attachment.render_to_output_buffer(context, output)
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user