diff --git a/lib/liquid/context.rb b/lib/liquid/context.rb index 90e6b7899..fbb4ec18f 100644 --- a/lib/liquid/context.rb +++ b/lib/liquid/context.rb @@ -35,8 +35,6 @@ def initialize(environments = {}, outer_scope = {}, registers = {}, rethrow_erro @base_scope_depth = 0 squash_instance_assigns_with_environments - @this_stack_used = false - self.exception_renderer = Template.default_exception_renderer if rethrow_errors self.exception_renderer = ->(e) { raise } @@ -122,19 +120,11 @@ def pop # end # # context['var] #=> nil - def stack(new_scope = nil) - old_stack_used = @this_stack_used - if new_scope - push(new_scope) - @this_stack_used = true - else - @this_stack_used = false - end - + def stack(new_scope = {}) + push(new_scope) yield ensure - pop if @this_stack_used - @this_stack_used = old_stack_used + pop end # Creates a new context inheriting resource limits, filters, environment etc., @@ -162,10 +152,6 @@ def clear_instance_assigns # Only allow String, Numeric, Hash, Array, Proc, Boolean or Liquid::Drop def []=(key, value) - unless @this_stack_used - @this_stack_used = true - push({}) - end @scopes[0][key] = value end diff --git a/lib/liquid/tags/case.rb b/lib/liquid/tags/case.rb index 92b2ed0d5..e167b9df2 100644 --- a/lib/liquid/tags/case.rb +++ b/lib/liquid/tags/case.rb @@ -39,16 +39,14 @@ def unknown_tag(tag, markup, tokens) end def render_to_output_buffer(context, output) - context.stack do - execute_else_block = true - - @blocks.each do |block| - if block.else? - block.attachment.render_to_output_buffer(context, output) if execute_else_block - elsif block.evaluate(context) - execute_else_block = false - block.attachment.render_to_output_buffer(context, output) - end + execute_else_block = true + + @blocks.each do |block| + if block.else? + block.attachment.render_to_output_buffer(context, output) if execute_else_block + elsif block.evaluate(context) + execute_else_block = false + block.attachment.render_to_output_buffer(context, output) end end diff --git a/lib/liquid/tags/cycle.rb b/lib/liquid/tags/cycle.rb index e42244d4f..8c11d37b9 100644 --- a/lib/liquid/tags/cycle.rb +++ b/lib/liquid/tags/cycle.rb @@ -34,24 +34,22 @@ def initialize(tag_name, markup, options) def render_to_output_buffer(context, output) context.registers[:cycle] ||= {} - context.stack do - key = context.evaluate(@name) - iteration = context.registers[:cycle][key].to_i + key = context.evaluate(@name) + iteration = context.registers[:cycle][key].to_i - val = context.evaluate(@variables[iteration]) + val = context.evaluate(@variables[iteration]) - if val.is_a?(Array) - val = val.join - elsif !val.is_a?(String) - val = val.to_s - end + if val.is_a?(Array) + val = val.join + elsif !val.is_a?(String) + val = val.to_s + end - output << val + output << val - iteration += 1 - iteration = 0 if iteration >= @variables.size - context.registers[:cycle][key] = iteration - end + iteration += 1 + iteration = 0 if iteration >= @variables.size + context.registers[:cycle][key] = iteration output end diff --git a/lib/liquid/tags/if.rb b/lib/liquid/tags/if.rb index 25534a983..709cf7f8c 100644 --- a/lib/liquid/tags/if.rb +++ b/lib/liquid/tags/if.rb @@ -40,11 +40,9 @@ def unknown_tag(tag, markup, tokens) end def render_to_output_buffer(context, output) - context.stack do - @blocks.each do |block| - if block.evaluate(context) - return block.attachment.render_to_output_buffer(context, output) - end + @blocks.each do |block| + if block.evaluate(context) + return block.attachment.render_to_output_buffer(context, output) end end diff --git a/lib/liquid/tags/ifchanged.rb b/lib/liquid/tags/ifchanged.rb index e3040cecf..ddd276cfb 100644 --- a/lib/liquid/tags/ifchanged.rb +++ b/lib/liquid/tags/ifchanged.rb @@ -1,14 +1,12 @@ module Liquid class Ifchanged < Block def render_to_output_buffer(context, output) - context.stack do - block_output = '' - super(context, block_output) + block_output = '' + super(context, block_output) - if block_output != context.registers[:ifchanged] - context.registers[:ifchanged] = block_output - output << block_output - end + if block_output != context.registers[:ifchanged] + context.registers[:ifchanged] = block_output + output << block_output end output diff --git a/lib/liquid/tags/unless.rb b/lib/liquid/tags/unless.rb index 18856c3b0..32aa3a419 100644 --- a/lib/liquid/tags/unless.rb +++ b/lib/liquid/tags/unless.rb @@ -7,18 +7,16 @@ module Liquid # class Unless < If def render_to_output_buffer(context, output) - context.stack do - # First condition is interpreted backwards ( if not ) - first_block = @blocks.first - unless first_block.evaluate(context) - return first_block.attachment.render_to_output_buffer(context, output) - end + # First condition is interpreted backwards ( if not ) + first_block = @blocks.first + unless first_block.evaluate(context) + return first_block.attachment.render_to_output_buffer(context, output) + end - # After the first condition unless works just like if - @blocks[1..-1].each do |block| - if block.evaluate(context) - return block.attachment.render_to_output_buffer(context, output) - end + # After the first condition unless works just like if + @blocks[1..-1].each do |block| + if block.evaluate(context) + return block.attachment.render_to_output_buffer(context, output) end end