diff --git a/example/server/templates/index.liquid b/example/server/templates/index.liquid
index d0f6730a..1197b103 100644
--- a/example/server/templates/index.liquid
+++ b/example/server/templates/index.liquid
@@ -36,8 +36,14 @@
{% # Snippet input %}
{% snippet "input" %}
-
-
+
+
+
+
+ {% endsnippet %}
+
+ {% snippet "league" %}
+ Welcome to the {{ team }} of super {{ name }}
{% endsnippet %}
@@ -48,8 +54,9 @@
{% endsnippet %}
- {% render 'input' %}
- {% render 'input' %}
+ {% render 'league', team: "league", name: "Evil" %}
+ {% render 'input', label: "User", type: "text" %}
+ {% render 'input', label: "Pass", type: "password" %}
{% render 'banner' %}
{% endsnippet %}
diff --git a/lib/liquid/tags/render.rb b/lib/liquid/tags/render.rb
index b40700c8..51211e17 100644
--- a/lib/liquid/tags/render.rb
+++ b/lib/liquid/tags/render.rb
@@ -68,7 +68,13 @@ module Liquid
# Inline snippets take precedence over external snippets
if (inline_snippet = context.registers[:inline_snippet][template_name])
- return output << inline_snippet.render(context)
+ inner_context = context.new_isolated_subcontext
+
+ @attributes.each do |key, value|
+ inner_context[key] = context.evaluate(value)
+ end
+
+ return output << inline_snippet.render(inner_context)
end
partial = PartialCache.load(
diff --git a/lib/liquid/tags/snippet.rb b/lib/liquid/tags/snippet.rb
index 8998e820..2f913754 100644
--- a/lib/liquid/tags/snippet.rb
+++ b/lib/liquid/tags/snippet.rb
@@ -14,12 +14,17 @@ module Liquid
# value
# {% endsnippet %}
class Snippet < Block
+ # SYNTAX = /(#{QuotedString}+) +\|(#{VariableSegment}*)\|/o
SYNTAX = /(#{QuotedString}+)/o
-
def initialize(tag_name, markup, options)
super
if markup =~ SYNTAX
+ # binding.irb
@to = Regexp.last_match(1)
+ # arg = Regexp.last_match(2)
+
+ # @args = []
+ # @args << arg if arg
else
raise SyntaxError, options[:locale].t("errors.syntax.snippet")
end
@@ -38,7 +43,8 @@ module Liquid
end
def snippet_body
- @body
+ body = @body
+ body
end
end
end
diff --git a/test/integration/tags/snippet_test.rb b/test/integration/tags/snippet_test.rb
index 9844fd6e..b3e0959f 100644
--- a/test/integration/tags/snippet_test.rb
+++ b/test/integration/tags/snippet_test.rb
@@ -71,4 +71,37 @@ class SnippetTest < Minitest::Test
assert_template_result(expected, template)
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, value| %}
+
+ {% endsnippet %}
+
+ {%- render "input", type: "text" -%}
+ LIQUID
+ expected = <<~OUTPUT
+
+
+ OUTPUT
+
+ assert_template_result(expected, template)
+ end
+
+ def test_render_inline_snippet_with_multiple_arguments
+ template = <<~LIQUID.strip
+ {% snippet "input" |type, value| %}
+
+ {% endsnippet %}
+
+ {%- render "input", type: "text", value: "Hello" -%}
+ LIQUID
+ expected = <<~OUTPUT
+
+
+ OUTPUT
+
+ assert_template_result(expected, template)
+ end
end