Compare commits

..
Author SHA1 Message Date
Guilherme Carreiro 448d98ce2f Bump to 5.10.0 2025-10-30 12:06:41 +01:00
Guilherme CarreiroandGuilherme Carreiro a16ec56a40 Update error handling for keeping backward-compatibility on error messages in the render tag 2025-10-30 12:00:44 +01:00
Julia BoutinandGuilherme Carreiro 12fd93fbe2 Missing inline snippets should display same error as filebased 2025-10-30 12:00:44 +01:00
Julia BoutinandGuilherme Carreiro 5ceb0e9cec Raise error on invalid snippet name 2025-10-30 12:00:44 +01:00
Julia BoutinandGuilherme Carreiro 98fbd985d8 Remove unneeded read method 2025-10-30 12:00:44 +01:00
Julia BoutinandGuilherme Carreiro ae05ba071c Add liquid_public_docs yard tag to snippet tag 2025-10-30 12:00:44 +01:00
Julia BoutinandGuilherme Carreiro 4205131148 Extract snippet resource scoring logic into assign_score_of 2025-10-30 12:00:44 +01:00
Julia BoutinandGuilherme Carreiro db350c54ff Allow render tag to recognize drops that respond to to_partial 2025-10-30 12:00:44 +01:00
Julia BoutinandGuilherme Carreiro 0cc6cdd553 Remove ... syntax references 2025-10-30 12:00:44 +01:00
Julia BoutinandGuilherme Carreiro 40e45e32ac Raise syntax error on incorrect render identifier type 2025-10-30 12:00:44 +01:00
Julia BoutinandGuilherme Carreiro d4d2237b90 Support prop spreading 2025-10-30 12:00:44 +01:00
Julia BoutinandGuilherme Carreiro 0ceeefba02 Implement resource limits and remove leftover string references 2025-10-30 12:00:44 +01:00
Julia BoutinandGuilherme Carreiro 65fb80a347 Render arguments should maintain correct precedence 2025-10-30 12:00:44 +01:00
Julia BoutinandGuilherme Carreiro 489a03118c Remove inline snippet specific example files 2025-10-30 12:00:44 +01:00
Julia BoutinandGuilherme Carreiro 99116638fd Support with, for, and as inline snippet syntax
This commit updates the render method to share parts
of the snippet and block rendering logic to enable
inline snippets to support `with`, `for`, and `as`
syntax
2025-10-30 12:00:44 +01:00
Julia BoutinandGuilherme Carreiro 9bcfd32e65 Support ... inline snippet syntax 2025-10-30 12:00:44 +01:00
Julia BoutinandGuilherme Carreiro c7ad1c90ca Change inline snippet identifier from string to variable
Currently, snippet files identified by strings. This
PR makes changes to render to allow for new inline
snippets to use variables as identifiers instead
2025-10-30 12:00:44 +01:00
Julia BoutinandGuilherme Carreiro 12bbbc4537 Create SnippetDrop and set in scope 2025-10-30 12:00:44 +01:00
1eca707c4a Update inline snippets syntax
Previously, inline snippets syntax looked a bit
different, they:

- used strings as tag identifiers
- defined tag arguments {% snippet "input" |type| %}

This PR updates snippets to better reflect
the currently proposed syntax

Co-authored-by: Orlando Qiu <[email protected]>
2025-10-30 12:00:44 +01:00
Josh FaiganandGuilherme Carreiro ed9c4e31c4 Introduce new inline snippets tag
Inline snippets will reduce code duplication and
improve the developer experience, eliminating the
need for one-off snippet files
2025-10-30 12:00:44 +01:00
Guilherme CarreiroandGuilherme Carreiro c357f91e0c Bump to 5.9.0 2025-10-27 17:25:36 +01:00
6 changed files with 79 additions and 38 deletions
+9
View File
@@ -1,5 +1,14 @@
# Liquid Change Log
## 5.10.0
* Introduce support for Inline Snippets [Julia Boutin]
```
{%- snippet snowdevil -%}
Snowdevil
{%- endsnippet -%}
{% render snowdevil %}
```
## 5.9.0
* Introduce `:rigid` error mode for stricter, safer parsing of all tags [CP Clermont, Guilherme Carreiro]
+3 -3
View File
@@ -2,13 +2,13 @@
module Liquid
class SnippetDrop < Drop
attr_reader :body, :name, :parent_name
attr_reader :body, :name, :filename
def initialize(body, name, parent_name)
def initialize(body, name, filename)
super()
@body = body
@name = name
@parent_name = parent_name
@filename = filename
end
def to_partial
+3 -5
View File
@@ -51,16 +51,14 @@ module Liquid
if template.respond_to?(:to_partial)
partial = template.to_partial
template_name = template.parent_name
context_variable_name = @alias_name || template.name.split('/').last
template_name = template.filename
context_variable_name = @alias_name || template.name
elsif @template_name_expr.is_a?(String)
partial = PartialCache.load(template, context: context, parse_context: parse_context)
template_name = partial.name
context_variable_name = @alias_name || template_name.split('/').last
else
raise ::ArgumentError, parse_context.locale.t("errors.argument.render")
raise ::ArgumentError
end
render_partial_func = ->(var, forloop) {
+1 -1
View File
@@ -2,5 +2,5 @@
# frozen_string_literal: true
module Liquid
VERSION = "5.8.7"
VERSION = "5.10.0"
end
-7
View File
@@ -101,13 +101,6 @@ class RenderTagTest < Minitest::Test
end
end
def test_dynamically_chosen_templates_are_not_allowed
error = assert_raises(::ArgumentError) do
Template.parse('{% assign name = "snippet" %}{% render name %}').render!
end
assert_equal("Argument error in tag 'render' - Dynamically chosen templates are not allowed", error.message)
end
def test_rigid_parsing_errors
with_error_modes(:lax, :strict) do
assert_template_result(
+63 -22
View File
@@ -482,39 +482,51 @@ class SnippetTest < Minitest::Test
end
def test_render_with_non_existent_tag
template = <<-LIQUID
template = Liquid::Template.parse(<<~LIQUID.chomp, line_numbers: true)
{% snippet foo %}
Hello,
{{ errors.standard_error }} will raise a standard error.
Bla bla test.
{{ errors.syntax_error }} will raise a syntax error.
This is an argument error: {{ errors.argument_error }}
Bla.
{% render non_existent %}
{% endsnippet %}
{%- render foo -%}
{% render foo %}
LIQUID
expected = <<-TEXT
Hello,
expected = <<~TEXT
Liquid error (line 3): standard error will raise a standard error.
Liquid error (index line 2): internal
TEXT
template.name = "index"
assert_equal(expected, template.render('errors' => ErrorDrop.new))
end
def test_render_handles_errors
template = Liquid::Template.parse(<<~LIQUID.chomp, line_numbers: true)
{% snippet foo %}
{% render non_existent %} will raise an error.
Bla bla test.
Liquid syntax error (line 7): syntax error will raise a syntax error.
This is an argument error: {{ 'test' | slice: 'not a number' }}
{% endsnippet %}
This is an argument error: Liquid error (line 9): argument error
{% render foo %}
LIQUID
Bla.
expected = <<~TEXT
Liquid error (index line 2): internal will raise an error.
Bla bla test.
This is an argument error: Liquid error (index line 6): invalid integer
TEXT
template.name = "index"
output = Liquid::Template.parse(template, line_numbers: true).render('errors' => ErrorDrop.new)
assert_equal(expected, output)
assert_equal(expected, template.render('errors' => ErrorDrop.new))
end
end
@@ -1005,8 +1017,37 @@ class SnippetTest < Minitest::Test
Liquid error (foo line 2): No such template 'non_existent'
Liquid error (index line 2): internal
TEXT
template.name = "index"
assert_equal(expected, template.render('errors' => ErrorDrop.new))
end
def test_render_handles_errors
template = Liquid::Template.parse(<<~LIQUID.chomp, line_numbers: true, error_mode: :rigid)
{% snippet foo %}
{% render non_existent %} will raise an error.
Bla bla test.
This is an argument error: {{ 'test' | slice: 'not a number' }}
{% endsnippet %}
{% render foo %}
LIQUID
expected = <<~TEXT
Liquid error (index line 2): internal will raise an error.
Bla bla test.
This is an argument error: Liquid error (index line 6): invalid integer
TEXT
template.name = "index"
assert_equal(expected, template.render('errors' => ErrorDrop.new))
end