liquid 5.10.0 → 5.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1b12ad70375f0ed9e3a2bab4a0a53ea565f3082af8d5bc06f4dea13a0a4ac574
4
- data.tar.gz: 04c2f7494b1ab0f97a2a33ad9d39c9c573a33b42bd109df8d42bb5e26d245f01
3
+ metadata.gz: 88705bb2e645a541fb76afe0a59c727429aaae33824103fb94178b5edbbda54e
4
+ data.tar.gz: 5982801da2e3431575b2e32edfd0f46a3371b1c74060dc8936470df75c27c630
5
5
  SHA512:
6
- metadata.gz: dc94bd83ae20e716eabf8ab2ce9f1fe9f8ff45dee6e0acac91f9095c32557c94d08e5a3c1b473c268c5a6a6d63a4d4ca10170406f062545545f63c1980a4d392
7
- data.tar.gz: 0f19c1d79039fda7a6e485cf794cde252817dc43bd292351b7bc53d1adabd12919e18cc0870fcf3db3c0018e22ef91a1507ded76b27719fb30b79414e04d3d2f
6
+ metadata.gz: 9c8ddeba605175a534a658c96dc749624ce78171f3df420011b3ac0f525301b29dac63b452e07081a8355f231e4643ee49a087daf0bcf0bb550bf07726c17228
7
+ data.tar.gz: 150dce06c67bc6aa2efddf094e6b2b745b58503436fcfa8784f0f1d88f2d8447f2b8a025915745a5b0b31109b3a8e0887b552e7a7279ff3cb123182ae4188543
data/History.md CHANGED
@@ -1,13 +1,11 @@
1
1
  # Liquid Change Log
2
2
 
3
+ ## 5.11.0
4
+ * Revert the Inline Snippets tag (#2001), treat its inclusion in the latest Liquid release as a bug, and allow for feedback on RFC#1916 to better support Liquid developers [Guilherme Carreiro]
5
+ * Rename the `:rigid` error mode to `:strict2` and display a warning when users attempt to use the `:rigid` mode [Guilherme Carreiro]
6
+
3
7
  ## 5.10.0
4
8
  * Introduce support for Inline Snippets [Julia Boutin]
5
- ```
6
- {%- snippet snowdevil -%}
7
- Snowdevil
8
- {%- endsnippet -%}
9
- {% render snowdevil %}
10
- ```
11
9
 
12
10
  ## 5.9.0
13
11
  * Introduce `:rigid` error mode for stricter, safer parsing of all tags [CP Clermont, Guilherme Carreiro]
data/README.md CHANGED
@@ -103,10 +103,10 @@ Liquid also comes with different parsers that can be used when editing templates
103
103
  when templates are invalid. You can enable this new parser like this:
104
104
 
105
105
  ```ruby
106
- Liquid::Environment.default.error_mode = :rigid # Raises a SyntaxError when invalid syntax is used in all tags
107
- Liquid::Environment.default.error_mode = :strict # Raises a SyntaxError when invalid syntax is used in some tags
108
- Liquid::Environment.default.error_mode = :warn # Adds strict errors to template.errors but continues as normal
109
- Liquid::Environment.default.error_mode = :lax # The default mode, accepts almost anything.
106
+ Liquid::Environment.default.error_mode = :strict2 # Raises a SyntaxError when invalid syntax is used in all tags
107
+ Liquid::Environment.default.error_mode = :strict # Raises a SyntaxError when invalid syntax is used in some tags
108
+ Liquid::Environment.default.error_mode = :warn # Adds strict errors to template.errors but continues as normal
109
+ Liquid::Environment.default.error_mode = :lax # The default mode, accepts almost anything.
110
110
  ```
111
111
 
112
112
  If you want to set the error mode only on specific templates you can pass `:error_mode` as an option to `parse`:
@@ -184,7 +184,7 @@ module Liquid
184
184
  end
185
185
 
186
186
  def key?(key)
187
- self[key] != nil
187
+ find_variable(key, raise_on_not_found: false) != nil
188
188
  end
189
189
 
190
190
  def evaluate(object)
@@ -34,7 +34,7 @@ module Liquid
34
34
  # @param file_system The default file system that is used
35
35
  # to load templates from.
36
36
  # @param error_mode [Symbol] The default error mode for all templates
37
- # (either :rigid, :strict, :warn, or :lax).
37
+ # (either :strict2, :strict, :warn, or :lax).
38
38
  # @param exception_renderer [Proc] The exception renderer that is used to
39
39
  # render exceptions.
40
40
  # @yieldparam environment [Environment] The environment instance that is being built.
@@ -5,7 +5,6 @@
5
5
  block_tag_unexpected_args: "Syntax Error in '%{tag}' - Valid syntax: {% %{tag} %}{% end%{tag} %}"
6
6
  assign: "Syntax Error in 'assign' - Valid syntax: assign [var] = [source]"
7
7
  capture: "Syntax Error in 'capture' - Valid syntax: capture [var]"
8
- snippet: "Syntax Error in 'snippet' - Valid syntax: snippet [var]"
9
8
  case: "Syntax Error in 'case' - Valid syntax: case [condition]"
10
9
  case_invalid_when: "Syntax Error in tag 'case' - Valid when condition: {% when [condition] [or condition2...] %}"
11
10
  case_invalid_else: "Syntax Error in tag 'case' - Valid else condition: {% else %} (no parameters) "
@@ -20,7 +19,6 @@
20
19
  invalid_delimiter: "'%{tag}' is not a valid delimiter for %{block_name} tags. use %{block_delimiter}"
21
20
  invalid_template_encoding: "Invalid template encoding"
22
21
  render: "Syntax error in tag 'render' - Template name must be a quoted string"
23
- render_invalid_template_name: "Syntax error in tag 'render' - Expected a string or identifier, found %{found}"
24
22
  table_row: "Syntax Error in 'table_row loop' - Valid syntax: table_row [item] in [collection] cols=3"
25
23
  table_row_invalid_attribute: "Invalid attribute '%{attribute}' in tablerow loop. Valid attributes are cols, limit, offset, and range"
26
24
  tag_never_closed: "'%{block_name}' tag was never closed"
@@ -31,6 +29,5 @@
31
29
  variable_termination: "Variable '%{token}' was not properly terminated with regexp: %{tag_end}"
32
30
  argument:
33
31
  include: "Argument error in tag 'include' - Illegal template name"
34
- render: "Argument error in tag 'render' - Dynamically chosen templates are not allowed"
35
32
  disabled:
36
33
  tag: "usage is not allowed in this context"
@@ -55,15 +55,15 @@ module Liquid
55
55
  end
56
56
 
57
57
  def parse_expression(markup, safe: false)
58
- if !safe && @error_mode == :rigid
58
+ if !safe && @error_mode == :strict2
59
59
  # parse_expression is a widely used API. To maintain backward
60
- # compatibility while raising awareness about rigid parser standards,
60
+ # compatibility while raising awareness about strict2 parser standards,
61
61
  # the safe flag supports API users make a deliberate decision.
62
62
  #
63
- # In rigid mode, markup MUST come from a string returned by the parser
63
+ # In strict2 mode, markup MUST come from a string returned by the parser
64
64
  # (e.g., parser.expression). We're not calling the parser here to
65
65
  # prevent redundant parser overhead.
66
- raise Liquid::InternalError, "unsafe parse_expression cannot be used in rigid mode"
66
+ raise Liquid::InternalError, "unsafe parse_expression cannot be used in strict2 mode"
67
67
  end
68
68
 
69
69
  Expression.parse(markup, @string_scanner, @expression_cache)
@@ -7,16 +7,19 @@ module Liquid
7
7
  # It's basically doing the same thing the {#parse_with_selected_parser},
8
8
  # except this will try the strict parser regardless of the error mode,
9
9
  # and fall back to the lax parser if the error mode is lax or warn,
10
- # except when in rigid mode where it uses the rigid parser.
10
+ # except when in strict2 mode where it uses the strict2 parser.
11
11
  #
12
12
  # @deprecated Use {#parse_with_selected_parser} instead.
13
13
  def strict_parse_with_error_mode_fallback(markup)
14
- return rigid_parse_with_error_context(markup) if rigid_mode?
14
+ return strict2_parse_with_error_context(markup) if strict2_mode?
15
15
 
16
16
  strict_parse_with_error_context(markup)
17
17
  rescue SyntaxError => e
18
18
  case parse_context.error_mode
19
19
  when :rigid
20
+ rigid_warn
21
+ raise
22
+ when :strict2
20
23
  raise
21
24
  when :strict
22
25
  raise
@@ -28,12 +31,13 @@ module Liquid
28
31
 
29
32
  def parse_with_selected_parser(markup)
30
33
  case parse_context.error_mode
31
- when :rigid then rigid_parse_with_error_context(markup)
32
- when :strict then strict_parse_with_error_context(markup)
33
- when :lax then lax_parse(markup)
34
+ when :rigid then rigid_warn && strict2_parse_with_error_context(markup)
35
+ when :strict2 then strict2_parse_with_error_context(markup)
36
+ when :strict then strict_parse_with_error_context(markup)
37
+ when :lax then lax_parse(markup)
34
38
  when :warn
35
39
  begin
36
- rigid_parse_with_error_context(markup)
40
+ strict2_parse_with_error_context(markup)
37
41
  rescue SyntaxError => e
38
42
  parse_context.warnings << e
39
43
  lax_parse(markup)
@@ -41,14 +45,18 @@ module Liquid
41
45
  end
42
46
  end
43
47
 
44
- def rigid_mode?
45
- parse_context.error_mode == :rigid
48
+ def strict2_mode?
49
+ parse_context.error_mode == :strict2 || parse_context.error_mode == :rigid
46
50
  end
47
51
 
48
52
  private
49
53
 
50
- def rigid_parse_with_error_context(markup)
51
- rigid_parse(markup)
54
+ def rigid_warn
55
+ Deprecations.warn(':rigid', ':strict2')
56
+ end
57
+
58
+ def strict2_parse_with_error_context(markup)
59
+ strict2_parse(markup)
52
60
  rescue SyntaxError => e
53
61
  e.line_number = line_number
54
62
  e.markup_context = markup_context(markup)
@@ -86,7 +86,7 @@ module Liquid
86
86
 
87
87
  private
88
88
 
89
- def rigid_parse(markup)
89
+ def strict2_parse(markup)
90
90
  parser = @parse_context.new_parser(markup)
91
91
  @left = safe_parse_expression(parser)
92
92
  parser.consume(:end_of_string)
@@ -107,14 +107,14 @@ module Liquid
107
107
  def record_when_condition(markup)
108
108
  body = new_body
109
109
 
110
- if rigid_mode?
111
- parse_rigid_when(markup, body)
110
+ if strict2_mode?
111
+ parse_strict2_when(markup, body)
112
112
  else
113
113
  parse_lax_when(markup, body)
114
114
  end
115
115
  end
116
116
 
117
- def parse_rigid_when(markup, body)
117
+ def parse_strict2_when(markup, body)
118
118
  parser = @parse_context.new_parser(markup)
119
119
 
120
120
  loop do
@@ -56,7 +56,7 @@ module Liquid
56
56
  private
57
57
 
58
58
  # cycle [name:] expression(, expression)*
59
- def rigid_parse(markup)
59
+ def strict2_parse(markup)
60
60
  p = @parse_context.new_parser(markup)
61
61
 
62
62
  @variables = []
@@ -111,7 +111,7 @@ module Liquid
111
111
 
112
112
  private
113
113
 
114
- def rigid_parse(markup)
114
+ def strict2_parse(markup)
115
115
  strict_parse(markup)
116
116
  end
117
117
 
@@ -66,7 +66,7 @@ module Liquid
66
66
 
67
67
  private
68
68
 
69
- def rigid_parse(markup)
69
+ def strict2_parse(markup)
70
70
  strict_parse(markup)
71
71
  end
72
72
 
@@ -84,7 +84,7 @@ module Liquid
84
84
  alias_method :parse_context, :options
85
85
  private :parse_context
86
86
 
87
- def rigid_parse(markup)
87
+ def strict2_parse(markup)
88
88
  p = @parse_context.new_parser(markup)
89
89
 
90
90
  @template_name_expr = safe_parse_expression(p)
@@ -27,7 +27,7 @@ module Liquid
27
27
  # @liquid_syntax_keyword filename The name of the snippet to render, without the `.liquid` extension.
28
28
  class Render < Tag
29
29
  FOR = 'for'
30
- SYNTAX = /(#{QuotedString}+|#{VariableSegment}+)(\s+(with|#{FOR})\s+(#{QuotedFragment}+))?(\s+(?:as)\s+(#{VariableSegment}+))?/o
30
+ SYNTAX = /(#{QuotedString}+)(\s+(with|#{FOR})\s+(#{QuotedFragment}+))?(\s+(?:as)\s+(#{VariableSegment}+))?/o
31
31
 
32
32
  disable_tags "include"
33
33
 
@@ -47,23 +47,21 @@ module Liquid
47
47
  end
48
48
 
49
49
  def render_tag(context, output)
50
- template = context.evaluate(@template_name_expr)
51
-
52
- if template.respond_to?(:to_partial)
53
- partial = template.to_partial
54
- template_name = template.filename
55
- context_variable_name = @alias_name || template.name
56
- elsif @template_name_expr.is_a?(String)
57
- partial = PartialCache.load(template, context: context, parse_context: parse_context)
58
- template_name = partial.name
59
- context_variable_name = @alias_name || template_name.split('/').last
60
- else
61
- raise ::ArgumentError
62
- end
50
+ # The expression should be a String literal, which parses to a String object
51
+ template_name = @template_name_expr
52
+ raise ::ArgumentError unless template_name.is_a?(String)
53
+
54
+ partial = PartialCache.load(
55
+ template_name,
56
+ context: context,
57
+ parse_context: parse_context,
58
+ )
59
+
60
+ context_variable_name = @alias_name || template_name.split('/').last
63
61
 
64
62
  render_partial_func = ->(var, forloop) {
65
63
  inner_context = context.new_isolated_subcontext
66
- inner_context.template_name = template_name
64
+ inner_context.template_name = partial.name
67
65
  inner_context.partial = true
68
66
  inner_context['forloop'] = forloop if forloop
69
67
 
@@ -87,10 +85,10 @@ module Liquid
87
85
  end
88
86
 
89
87
  # render (string) (with|for expression)? (as id)? (key: value)*
90
- def rigid_parse(markup)
88
+ def strict2_parse(markup)
91
89
  p = @parse_context.new_parser(markup)
92
90
 
93
- @template_name_expr = parse_expression(rigid_template_name(p), safe: true)
91
+ @template_name_expr = parse_expression(strict2_template_name(p), safe: true)
94
92
  with_or_for = p.id?("for") || p.id?("with")
95
93
  @variable_name_expr = safe_parse_expression(p) if with_or_for
96
94
  @alias_name = p.consume(:id) if p.id?("as")
@@ -103,18 +101,14 @@ module Liquid
103
101
  key = p.consume
104
102
  p.consume(:colon)
105
103
  @attributes[key] = safe_parse_expression(p)
106
- p.consume?(:comma) # optional comma
104
+ p.consume?(:comma)
107
105
  end
108
106
 
109
107
  p.consume(:end_of_string)
110
108
  end
111
109
 
112
- def rigid_template_name(p)
113
- return p.consume(:string) if p.look(:string)
114
- return p.consume(:id) if p.look(:id)
115
-
116
- found = p.consume || "nothing"
117
- raise SyntaxError, options[:locale].t("errors.syntax.render_invalid_template_name", found: found)
110
+ def strict2_template_name(p)
111
+ p.consume(:string)
118
112
  end
119
113
 
120
114
  def strict_parse(markup)
@@ -34,7 +34,7 @@ module Liquid
34
34
  parse_with_selected_parser(markup)
35
35
  end
36
36
 
37
- def rigid_parse(markup)
37
+ def strict2_parse(markup)
38
38
  p = @parse_context.new_parser(markup)
39
39
 
40
40
  @variable_name = p.consume(:id)
data/lib/liquid/tags.rb CHANGED
@@ -20,7 +20,6 @@ require_relative "tags/raw"
20
20
  require_relative "tags/render"
21
21
  require_relative "tags/cycle"
22
22
  require_relative "tags/doc"
23
- require_relative "tags/snippet"
24
23
 
25
24
  module Liquid
26
25
  module Tags
@@ -45,7 +44,6 @@ module Liquid
45
44
  'echo' => Echo,
46
45
  'tablerow' => TableRow,
47
46
  'doc' => Doc,
48
- 'snippet' => Snippet,
49
47
  }.freeze
50
48
  end
51
49
  end
@@ -25,7 +25,7 @@ module Liquid
25
25
  # :lax acts like liquid 2.5 and silently ignores malformed tags in most cases.
26
26
  # :warn is the default and will give deprecation warnings when invalid syntax is used.
27
27
  # :strict enforces correct syntax for most tags
28
- # :rigid enforces correct syntax for all tags
28
+ # :strict2 enforces correct syntax for all tags
29
29
  def error_mode=(mode)
30
30
  Deprecations.warn("Template.error_mode=", "Environment#error_mode=")
31
31
  Environment.default.error_mode = mode
@@ -74,14 +74,14 @@ module Liquid
74
74
  p.consume(:end_of_string)
75
75
  end
76
76
 
77
- def rigid_parse(markup)
77
+ def strict2_parse(markup)
78
78
  @filters = []
79
79
  p = @parse_context.new_parser(markup)
80
80
 
81
81
  return if p.look(:end_of_string)
82
82
 
83
83
  @name = parse_context.safe_parse_expression(p)
84
- @filters << rigid_parse_filter_expressions(p) while p.consume?(:pipe)
84
+ @filters << strict2_parse_filter_expressions(p) while p.consume?(:pipe)
85
85
  p.consume(:end_of_string)
86
86
  end
87
87
 
@@ -156,7 +156,7 @@ module Liquid
156
156
  # argument = (positional_argument | keyword_argument)
157
157
  # positional_argument = expression
158
158
  # keyword_argument = id ":" expression
159
- def rigid_parse_filter_expressions(p)
159
+ def strict2_parse_filter_expressions(p)
160
160
  filtername = p.consume(:id)
161
161
  filter_args = []
162
162
  keyword_args = {}
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Liquid
5
- VERSION = "5.10.0"
5
+ VERSION = "5.11.0"
6
6
  end
data/lib/liquid.rb CHANGED
@@ -67,7 +67,6 @@ require 'liquid/i18n'
67
67
  require 'liquid/drop'
68
68
  require 'liquid/tablerowloop_drop'
69
69
  require 'liquid/forloop_drop'
70
- require 'liquid/snippet_drop'
71
70
  require 'liquid/extensions'
72
71
  require 'liquid/errors'
73
72
  require 'liquid/interrupts'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: liquid
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.10.0
4
+ version: 5.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Lütke
@@ -105,7 +105,6 @@ files:
105
105
  - lib/liquid/range_lookup.rb
106
106
  - lib/liquid/registers.rb
107
107
  - lib/liquid/resource_limits.rb
108
- - lib/liquid/snippet_drop.rb
109
108
  - lib/liquid/standardfilters.rb
110
109
  - lib/liquid/strainer_template.rb
111
110
  - lib/liquid/tablerowloop_drop.rb
@@ -131,7 +130,6 @@ files:
131
130
  - lib/liquid/tags/inline_comment.rb
132
131
  - lib/liquid/tags/raw.rb
133
132
  - lib/liquid/tags/render.rb
134
- - lib/liquid/tags/snippet.rb
135
133
  - lib/liquid/tags/table_row.rb
136
134
  - lib/liquid/tags/unless.rb
137
135
  - lib/liquid/template.rb
@@ -1,22 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Liquid
4
- class SnippetDrop < Drop
5
- attr_reader :body, :name, :filename
6
-
7
- def initialize(body, name, filename)
8
- super()
9
- @body = body
10
- @name = name
11
- @filename = filename
12
- end
13
-
14
- def to_partial
15
- @body
16
- end
17
-
18
- def to_s
19
- 'SnippetDrop'
20
- end
21
- end
22
- end
@@ -1,45 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Liquid
4
- # @liquid_public_docs
5
- # @liquid_type tag
6
- # @liquid_category variable
7
- # @liquid_name snippet
8
- # @liquid_summary
9
- # Creates a new inline snippet.
10
- # @liquid_description
11
- # You can create inline snippets to make your Liquid code more modular.
12
- # @liquid_syntax
13
- # {% snippet snippet_name %}
14
- # value
15
- # {% endsnippet %}
16
- class Snippet < Block
17
- def initialize(tag_name, markup, options)
18
- super
19
- p = @parse_context.new_parser(markup)
20
- if p.look(:id)
21
- @to = p.consume(:id)
22
- p.consume(:end_of_string)
23
- else
24
- raise SyntaxError, options[:locale].t("errors.syntax.snippet")
25
- end
26
- end
27
-
28
- def render_to_output_buffer(context, output)
29
- snippet_drop = SnippetDrop.new(@body, @to, context.template_name)
30
- context.scopes.last[@to] = snippet_drop
31
- context.resource_limits.increment_assign_score(assign_score_of(snippet_drop))
32
- output
33
- end
34
-
35
- def blank?
36
- true
37
- end
38
-
39
- private
40
-
41
- def assign_score_of(snippet_drop)
42
- snippet_drop.body.nodelist.sum { |node| node.to_s.bytesize }
43
- end
44
- end
45
- end