Move disabled check to block_body

This commit is contained in:
Mike Angell
2019-09-24 00:07:59 +10:00
parent 7f136c8fa6
commit 9f03dff79a
4 changed files with 37 additions and 2 deletions

View File

@@ -154,6 +154,7 @@ module Liquid
private
def render_node(context, output, node)
node.disabled?(context, output) && return if node.is_a?(Tag)
node.render_to_output_buffer(context, output)
rescue UndefinedVariable, UndefinedDropMethod, UndefinedFilter => e
context.handle_error(e, node.line_number)

View File

@@ -45,7 +45,6 @@ module Liquid
end
def render_to_output_buffer(context, output)
disabled?(context, output) && return
template_name = context.evaluate(@template_name_expr)
raise ArgumentError, options[:locale].t("errors.argument.include") unless template_name

View File

@@ -0,0 +1,35 @@
# frozen_string_literal: true
require 'test_helper'
class DisabledTagsTest < Minitest::Test
include Liquid
class DisableRaw < Block
def render(context)
disable_tags(context, ["raw"]) do
@body.render(context)
end
end
end
class DisableRawEcho < Block
def render(context)
disable_tags(context, ["raw", "echo"]) do
@body.render(context)
end
end
end
def test_disables_raw
with_custom_tag('disable', DisableRaw) do
assert_template_result 'raw usage has been disabled in this context.foo', '{% disable %}{% raw %}Foobar{% endraw %}{% echo "foo" %}{% enddisable %}'
end
end
def test_disables_echo_and_raw
with_custom_tag('disable', DisableRawEcho) do
assert_template_result 'raw usage has been disabled in this context.echo usage has been disabled in this context.', '{% disable %}{% raw %}Foobar{% endraw %}{% echo "foo" %}{% enddisable %}'
end
end
end

View File

@@ -2,7 +2,7 @@
require 'test_helper'
class DisabledTagsTest < Minitest::Test
class DisabledTagsUnitTest < Minitest::Test
include Liquid
def test_disables_tag_specified