snippet using inner context

This commit is contained in:
Josh Faigan
2024-09-30 15:58:00 -04:00
parent 404d71613c
commit 3399981b89
4 changed files with 89 additions and 52 deletions
+66 -27
View File
@@ -73,7 +73,6 @@ class SnippetTest < Minitest::Test
end
def test_render_inline_snippet_with_argument
# This passes whether or not we have the new or old SYNTAX
template = <<~LIQUID.strip
{% snippet "input" |type| %}
<input type="{{ type }}" />
@@ -89,38 +88,78 @@ class SnippetTest < Minitest::Test
assert_template_result(expected, template)
end
# def test_render_inline_snippet_with_multiple_arguments
# template = <<~LIQUID.strip
# {% snippet "input" |type, value| %}
# <input type="{{ type }}" value="{{ value }}" />
# {% endsnippet %}
def test_render_inline_snippet_with_multiple_arguments
template = <<~LIQUID.strip
{% snippet "input" |type, value| %}
<input type="{{ type }}" value="{{ value }}" />
{% endsnippet %}
# {%- render "input", type: "text", value: "Hello" -%}
# LIQUID
# expected = <<~OUTPUT
{%- render "input", type: "text", value: "Hello" -%}
LIQUID
expected = <<~OUTPUT
# <input type="text" value="Hello" />
# OUTPUT
<input type="text" value="Hello" />
OUTPUT
# assert_template_result(expected, template)
# end
assert_template_result(expected, template)
end
# def test_render_inline_snippet_shouldnt_leak_context
# template = <<~LIQUID.strip
# {% snippet "input" |type, value| %}
# <input type="{{ type }}" value="{{ value }}" />
# {% endsnippet %}
def test_render_inline_snippet_empty_string_when_missing_argument
template = <<~LIQUID.strip
{% snippet "input" |type| %}
<input type="{{ type }}" value="{{ value }}" />
{% endsnippet %}
# {%- render "input", type: "text", value: "Hello" -%}
{%- render "input", type: "text" -%}
LIQUID
expected = <<~OUTPUT
# {{ type }}
# {{ value }}
# LIQUID
# expected = <<~OUTPUT
<input type="text" value="" />
OUTPUT
# <input type="text" value="Hello" />
# OUTPUT
assert_template_result(expected, template)
end
# assert_template_result(expected, template)
# end
def test_render_inline_snippet_shouldnt_leak_context
template = <<~LIQUID.strip
{% snippet "input" |type, value| %}
<input type="{{ type }}" value="{{ value }}" />
{% endsnippet %}
{%- render "input", type: "text", value: "Hello" -%}
{{ type }}
{{ value }}
LIQUID
expected = <<~OUTPUT
<input type="text" value="Hello" />
OUTPUT
assert_template_result(expected, template)
end
def test_render_multiple_inline_snippets_without_leaking_context
template = <<~LIQUID.strip
{% snippet "input" |type| %}
<input type="{{ type }}" />
{% endsnippet %}
{% snippet "banner"%}
{{ type }}
{% endsnippet %}
{%- render "input", type: "text" -%}
{%- render "banner" -%}
LIQUID
expected = <<~OUTPUT.strip
<input type="text" />
OUTPUT
assert_template_result(expected, template)
end
end