diff --git a/lib/liquid/block_body.rb b/lib/liquid/block_body.rb index 515bd85..2fb4519 100644 --- a/lib/liquid/block_body.rb +++ b/lib/liquid/block_body.rb @@ -155,7 +155,9 @@ module Liquid def render_node(context, output, node) return if node.is_a?(Tag) && node.disabled?(context, output) - node.render_to_output_buffer(context, output) + disable_tags(context, node.is_a?(Tag) ? node.disabled_tags : nil) do + node.render_to_output_buffer(context, output) + end rescue UndefinedVariable, UndefinedDropMethod, UndefinedFilter => e context.handle_error(e, node.line_number) rescue ::StandardError => e @@ -163,6 +165,11 @@ module Liquid output << context.handle_error(e, line_number) end + def disable_tags(context, tags, &block) + return yield unless tags + context.registers['disabled_tags'].disable(tags, &block) + end + def raise_if_resource_limits_reached(context, length) context.resource_limits.render_length += length return unless context.resource_limits.reached? diff --git a/lib/liquid/tag.rb b/lib/liquid/tag.rb index 73d289c..c13b004 100644 --- a/lib/liquid/tag.rb +++ b/lib/liquid/tag.rb @@ -13,7 +13,15 @@ module Liquid tag end + def disable_nested_tags(*tags) + @disabled_tags = tags + end + private :new + + def disabled_tags + @disabled_tags ||= [] + end end def initialize(tag_name, markup, parse_context) @@ -48,10 +56,6 @@ module Liquid "#{tag_name} #{options[:locale].t('errors.disabled.tag')}" end - def disable_tags(context, tags, &block) - context.registers['disabled_tags'].disable(tags, &block) - end - # For backwards compatibility with custom tags. In a future release, the semantics # of the `render_to_output_buffer` method will become the default and the `render` # method will be removed. @@ -63,5 +67,9 @@ module Liquid def blank? false end + + def disabled_tags + self.class.disabled_tags + end end end diff --git a/lib/liquid/tags/render.rb b/lib/liquid/tags/render.rb index 8e88448..16e8921 100644 --- a/lib/liquid/tags/render.rb +++ b/lib/liquid/tags/render.rb @@ -3,7 +3,8 @@ module Liquid class Render < Tag SYNTAX = /(#{QuotedString})#{QuotedFragment}*/o - DISABLED_TAGS = %w(include).freeze + + disable_nested_tags "include" attr_reader :template_name_expr, :attributes @@ -23,9 +24,7 @@ module Liquid end def render_to_output_buffer(context, output) - disable_tags(context, DISABLED_TAGS) do - render_tag(context, output) - end + render_tag(context, output) end def render_tag(context, output) diff --git a/test/integration/registers/disabled_tags_test.rb b/test/integration/registers/disabled_tags_test.rb index b784888..08a3047 100644 --- a/test/integration/registers/disabled_tags_test.rb +++ b/test/integration/registers/disabled_tags_test.rb @@ -6,19 +6,11 @@ class DisabledTagsTest < Minitest::Test include Liquid class DisableRaw < Block - def render(context) - disable_tags(context, ["raw"]) do - @body.render(context) - end - end + disable_nested_tags "raw" end class DisableRawEcho < Block - def render(context) - disable_tags(context, ["raw", "echo"]) do - @body.render(context) - end - end + disable_nested_tags "raw", "echo" end def test_disables_raw