mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-19 19:00:39 -07:00
Move disabled check to block_body
This commit is contained in:
@@ -154,6 +154,7 @@ module Liquid
|
|||||||
private
|
private
|
||||||
|
|
||||||
def render_node(context, output, node)
|
def render_node(context, output, node)
|
||||||
|
node.disabled?(context, output) && return if node.is_a?(Tag)
|
||||||
node.render_to_output_buffer(context, output)
|
node.render_to_output_buffer(context, output)
|
||||||
rescue UndefinedVariable, UndefinedDropMethod, UndefinedFilter => e
|
rescue UndefinedVariable, UndefinedDropMethod, UndefinedFilter => e
|
||||||
context.handle_error(e, node.line_number)
|
context.handle_error(e, node.line_number)
|
||||||
|
|||||||
@@ -45,7 +45,6 @@ module Liquid
|
|||||||
end
|
end
|
||||||
|
|
||||||
def render_to_output_buffer(context, output)
|
def render_to_output_buffer(context, output)
|
||||||
disabled?(context, output) && return
|
|
||||||
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
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
+1
-1
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
class DisabledTagsTest < Minitest::Test
|
class DisabledTagsUnitTest < Minitest::Test
|
||||||
include Liquid
|
include Liquid
|
||||||
|
|
||||||
def test_disables_tag_specified
|
def test_disables_tag_specified
|
||||||
Reference in New Issue
Block a user