liquid 3.0.6 → 4.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/History.md +149 -58
- data/{MIT-LICENSE → LICENSE} +0 -0
- data/README.md +33 -0
- data/lib/liquid/block.rb +42 -125
- data/lib/liquid/block_body.rb +98 -79
- data/lib/liquid/condition.rb +52 -32
- data/lib/liquid/context.rb +57 -51
- data/lib/liquid/document.rb +19 -9
- data/lib/liquid/drop.rb +17 -16
- data/lib/liquid/errors.rb +20 -24
- data/lib/liquid/expression.rb +26 -10
- data/lib/liquid/extensions.rb +19 -7
- data/lib/liquid/file_system.rb +11 -11
- data/lib/liquid/forloop_drop.rb +42 -0
- data/lib/liquid/i18n.rb +6 -6
- data/lib/liquid/interrupts.rb +1 -2
- data/lib/liquid/lexer.rb +12 -8
- data/lib/liquid/locales/en.yml +6 -2
- data/lib/liquid/parse_context.rb +38 -0
- data/lib/liquid/parse_tree_visitor.rb +42 -0
- data/lib/liquid/parser_switching.rb +4 -4
- data/lib/liquid/profiler/hooks.rb +7 -7
- data/lib/liquid/profiler.rb +18 -19
- data/lib/liquid/range_lookup.rb +16 -1
- data/lib/liquid/resource_limits.rb +23 -0
- data/lib/liquid/standardfilters.rb +207 -61
- data/lib/liquid/strainer.rb +15 -8
- data/lib/liquid/tablerowloop_drop.rb +62 -0
- data/lib/liquid/tag.rb +9 -8
- data/lib/liquid/tags/assign.rb +25 -4
- data/lib/liquid/tags/break.rb +0 -3
- data/lib/liquid/tags/capture.rb +1 -1
- data/lib/liquid/tags/case.rb +27 -12
- data/lib/liquid/tags/comment.rb +2 -2
- data/lib/liquid/tags/cycle.rb +16 -8
- data/lib/liquid/tags/decrement.rb +1 -4
- data/lib/liquid/tags/for.rb +103 -75
- data/lib/liquid/tags/if.rb +60 -44
- data/lib/liquid/tags/ifchanged.rb +0 -2
- data/lib/liquid/tags/include.rb +71 -51
- data/lib/liquid/tags/raw.rb +32 -4
- data/lib/liquid/tags/table_row.rb +21 -31
- data/lib/liquid/tags/unless.rb +3 -4
- data/lib/liquid/template.rb +42 -54
- data/lib/liquid/tokenizer.rb +31 -0
- data/lib/liquid/truffle.rb +5 -0
- data/lib/liquid/utils.rb +52 -8
- data/lib/liquid/variable.rb +59 -46
- data/lib/liquid/variable_lookup.rb +14 -6
- data/lib/liquid/version.rb +2 -1
- data/lib/liquid.rb +10 -7
- data/test/integration/assign_test.rb +8 -8
- data/test/integration/blank_test.rb +14 -14
- data/test/integration/block_test.rb +12 -0
- data/test/integration/context_test.rb +2 -2
- data/test/integration/document_test.rb +19 -0
- data/test/integration/drop_test.rb +42 -40
- data/test/integration/error_handling_test.rb +96 -43
- data/test/integration/filter_test.rb +60 -20
- data/test/integration/hash_ordering_test.rb +9 -9
- data/test/integration/output_test.rb +26 -27
- data/test/integration/parse_tree_visitor_test.rb +247 -0
- data/test/integration/parsing_quirks_test.rb +19 -13
- data/test/integration/render_profiling_test.rb +20 -20
- data/test/integration/security_test.rb +23 -7
- data/test/integration/standard_filter_test.rb +426 -46
- data/test/integration/tags/break_tag_test.rb +1 -2
- data/test/integration/tags/continue_tag_test.rb +0 -1
- data/test/integration/tags/for_tag_test.rb +135 -100
- data/test/integration/tags/if_else_tag_test.rb +75 -77
- data/test/integration/tags/include_tag_test.rb +42 -31
- data/test/integration/tags/increment_tag_test.rb +10 -11
- data/test/integration/tags/raw_tag_test.rb +7 -1
- data/test/integration/tags/standard_tag_test.rb +121 -122
- data/test/integration/tags/statements_test.rb +3 -5
- data/test/integration/tags/table_row_test.rb +20 -19
- data/test/integration/tags/unless_else_tag_test.rb +6 -6
- data/test/integration/template_test.rb +199 -49
- data/test/integration/trim_mode_test.rb +529 -0
- data/test/integration/variable_test.rb +27 -13
- data/test/test_helper.rb +33 -6
- data/test/truffle/truffle_test.rb +9 -0
- data/test/unit/block_unit_test.rb +8 -5
- data/test/unit/condition_unit_test.rb +94 -77
- data/test/unit/context_unit_test.rb +69 -72
- data/test/unit/file_system_unit_test.rb +3 -3
- data/test/unit/i18n_unit_test.rb +2 -2
- data/test/unit/lexer_unit_test.rb +12 -9
- data/test/unit/parser_unit_test.rb +2 -2
- data/test/unit/regexp_unit_test.rb +1 -1
- data/test/unit/strainer_unit_test.rb +96 -1
- data/test/unit/tag_unit_test.rb +7 -2
- data/test/unit/tags/case_tag_unit_test.rb +1 -1
- data/test/unit/tags/for_tag_unit_test.rb +2 -2
- data/test/unit/tags/if_tag_unit_test.rb +1 -1
- data/test/unit/template_unit_test.rb +14 -5
- data/test/unit/tokenizer_unit_test.rb +24 -7
- data/test/unit/variable_unit_test.rb +60 -43
- metadata +62 -50
- data/lib/liquid/module_ex.rb +0 -62
- data/lib/liquid/token.rb +0 -18
- data/test/unit/module_ex_unit_test.rb +0 -87
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e3124f91e43cab43cf6782b093c0387d9189bd951b911ab1ade84024e5b84bf3
|
4
|
+
data.tar.gz: 40c04d46b3a1a51a775832cabf161fc870bde43b72d2857a8a8cf736e1909a43
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 71deb80c6d970684e424fb8e4ca0a817399dc0b6564a7308093158a94ace0e24cac5d8e08a8b015327937b8dd45be25532dd8d9e02de0c3677f08297a08638dd
|
7
|
+
data.tar.gz: 79490a2f0db69914e01c69fdcf135cc3541609cfca29017154d3c33325c57f682c3d90bbfa0bca1a7f3d82e4cbe4af5259a77cf42861c142921491e21949bddf
|
data/History.md
CHANGED
@@ -1,4 +1,95 @@
|
|
1
|
-
# Liquid
|
1
|
+
# Liquid Change Log
|
2
|
+
|
3
|
+
## 4.0.2 / 2019-03-08
|
4
|
+
|
5
|
+
### Changed
|
6
|
+
* Add `where` filter (#1026) [Samuel Doiron]
|
7
|
+
* Add `ParseTreeVisitor` to iterate the Liquid AST (#1025) [Stephen Paul Weber]
|
8
|
+
* Improve `strip_html` performance (#1032) [printercu]
|
9
|
+
|
10
|
+
### Fixed
|
11
|
+
* Add error checking for invalid combinations of inputs to sort, sort_natural, where, uniq, map, compact filters (#1059) [Garland Zhang]
|
12
|
+
* Validate the character encoding in url_decode (#1070) [Clayton Smith]
|
13
|
+
|
14
|
+
## 4.0.1 / 2018-10-09
|
15
|
+
|
16
|
+
### Changed
|
17
|
+
* Add benchmark group in Gemfile (#855) [Jerry Liu]
|
18
|
+
* Allow benchmarks to benchmark render by itself (#851) [Jerry Liu]
|
19
|
+
* Avoid calling `line_number` on String node when rescuing a render error. (#860) [Dylan Thacker-Smith]
|
20
|
+
* Avoid duck typing to detect whether to call render on a node. [Dylan Thacker-Smith]
|
21
|
+
* Clarify spelling of `reversed` on `for` block tag (#843) [Mark Crossfield]
|
22
|
+
* Replace recursion with loop to avoid potential stack overflow from malicious input (#891, #892) [Dylan Thacker-Smith]
|
23
|
+
* Limit block tag nesting to 100 (#894) [Dylan Thacker-Smith]
|
24
|
+
* Replace `assert_equal nil` with `assert_nil` (#895) [Dylan Thacker-Smith]
|
25
|
+
* Remove Spy Gem (#896) [Dylan Thacker-Smith]
|
26
|
+
* Add `collection_name` and `variable_name` reader to `For` block (#909)
|
27
|
+
* Symbols render as strings (#920) [Justin Li]
|
28
|
+
* Remove default value from Hash objects (#932) [Maxime Bedard]
|
29
|
+
* Remove one level of nesting (#944) [Dylan Thacker-Smith]
|
30
|
+
* Update Rubocop version (#952) [Justin Li]
|
31
|
+
* Add `at_least` and `at_most` filters (#954, #958) [Nithin Bekal]
|
32
|
+
* Add a regression test for a liquid-c trim mode bug (#972) [Dylan Thacker-Smith]
|
33
|
+
* Use https rather than git protocol to fetch liquid-c [Dylan Thacker-Smith]
|
34
|
+
* Add tests against Ruby 2.4 (#963) and 2.5 (#981)
|
35
|
+
* Replace RegExp literals with constants (#988) [Ashwin Maroli]
|
36
|
+
* Replace unnecessary `#each_with_index` with `#each` (#992) [Ashwin Maroli]
|
37
|
+
* Improve the unexpected end delimiter message for block tags. (#1003) [Dylan Thacker-Smith]
|
38
|
+
* Refactor and optimize rendering (#1005) [Christopher Aue]
|
39
|
+
* Add installation instruction (#1006) [Ben Gift]
|
40
|
+
* Remove Circle CI (#1010)
|
41
|
+
* Rename deprecated `BigDecimal.new` to `BigDecimal` (#1024) [Koichi ITO]
|
42
|
+
* Rename deprecated Rubocop name (#1027) [Justin Li]
|
43
|
+
|
44
|
+
### Fixed
|
45
|
+
* Handle `join` filter on non String joiners (#857) [Richard Monette]
|
46
|
+
* Fix duplicate inclusion condition logic error of `Liquid::Strainer.add_filter` method (#861)
|
47
|
+
* Fix `escape`, `url_encode`, `url_decode` not handling non-string values (#898) [Thierry Joyal]
|
48
|
+
* Fix raise when variable is defined but nil when using `strict_variables` [Pascal Betz]
|
49
|
+
* Fix `sort` and `sort_natural` to handle arrays with nils (#930) [Eric Chan]
|
50
|
+
|
51
|
+
## 4.0.0 / 2016-12-14 / branch "4-0-stable"
|
52
|
+
|
53
|
+
### Changed
|
54
|
+
* Render an opaque internal error by default for non-Liquid::Error (#835) [Dylan Thacker-Smith]
|
55
|
+
* Ruby 2.0 support dropped (#832) [Dylan Thacker-Smith]
|
56
|
+
* Add to_number Drop method to allow custom drops to work with number filters (#731)
|
57
|
+
* Add strict_variables and strict_filters options to detect undefined references (#691)
|
58
|
+
* Improve loop performance (#681) [Florian Weingarten]
|
59
|
+
* Rename Drop method `before_method` to `liquid_method_missing` (#661) [Thierry Joyal]
|
60
|
+
* Add url_decode filter to invert url_encode (#645) [Larry Archer]
|
61
|
+
* Add global_filter to apply a filter to all output (#610) [Loren Hale]
|
62
|
+
* Add compact filter (#600) [Carson Reinke]
|
63
|
+
* Rename deprecated "has_key?" and "has_interrupt?" methods (#593) [Florian Weingarten]
|
64
|
+
* Include template name with line numbers in render errors (574) [Dylan Thacker-Smith]
|
65
|
+
* Add sort_natural filter (#554) [Martin Hanzel]
|
66
|
+
* Add forloop.parentloop as a reference to the parent loop (#520) [Justin Li]
|
67
|
+
* Block parsing moved to BlockBody class (#458) [Dylan Thacker-Smith]
|
68
|
+
* Add concat filter to concatenate arrays (#429) [Diogo Beato]
|
69
|
+
* Ruby 1.9 support dropped (#491) [Justin Li]
|
70
|
+
* Liquid::Template.file_system's read_template_file method is no longer passed the context. (#441) [James Reid-Smith]
|
71
|
+
* Remove `liquid_methods` (See https://github.com/Shopify/liquid/pull/568 for replacement)
|
72
|
+
* Liquid::Template.register_filter raises when the module overrides registered public methods as private or protected (#705) [Gaurav Chande]
|
73
|
+
|
74
|
+
### Fixed
|
75
|
+
|
76
|
+
* Fix variable names being detected as an operator when starting with contains (#788) [Michael Angell]
|
77
|
+
* Fix include tag used with strict_variables (#828) [QuickPay]
|
78
|
+
* Fix map filter when value is a Proc (#672) [Guillaume Malette]
|
79
|
+
* Fix truncate filter when value is not a string (#672) [Guillaume Malette]
|
80
|
+
* Fix behaviour of escape filter when input is nil (#665) [Tanel Jakobsoo]
|
81
|
+
* Fix sort filter behaviour with empty array input (#652) [Marcel Cary]
|
82
|
+
* Fix test failure under certain timezones (#631) [Dylan Thacker-Smith]
|
83
|
+
* Fix bug in uniq filter (#595) [Florian Weingarten]
|
84
|
+
* Fix bug when "blank" and "empty" are used as variable names (#592) [Florian Weingarten]
|
85
|
+
* Fix condition parse order in strict mode (#569) [Justin Li]
|
86
|
+
* Fix naming of the "context variable" when dynamically including a template (#559) [Justin Li]
|
87
|
+
* Gracefully accept empty strings in the date filter (#555) [Loren Hale]
|
88
|
+
* Fix capturing into variables with a hyphen in the name (#505) [Florian Weingarten]
|
89
|
+
* Fix case sensitivity regression in date standard filter (#499) [Kelley Reynolds]
|
90
|
+
* Disallow filters with no variable in strict mode (#475) [Justin Li]
|
91
|
+
* Disallow variable names in the strict parser that are not valid in the lax parser (#463) [Justin Li]
|
92
|
+
* Fix BlockBody#warnings taking exponential time to compute (#486) [Justin Li]
|
2
93
|
|
3
94
|
## 3.0.5 / 2015-07-23 / branch "3-0-stable"
|
4
95
|
|
@@ -10,11 +101,11 @@
|
|
10
101
|
|
11
102
|
## 3.0.3 / 2015-05-28
|
12
103
|
|
13
|
-
* Fix condition parse order in strict mode (#569) [Justin Li
|
104
|
+
* Fix condition parse order in strict mode (#569) [Justin Li]
|
14
105
|
|
15
106
|
## 3.0.2 / 2015-04-24
|
16
107
|
|
17
|
-
* Expose VariableLookup private members (#551) [Justin Li
|
108
|
+
* Expose VariableLookup private members (#551) [Justin Li]
|
18
109
|
* Documentation fixes
|
19
110
|
|
20
111
|
## 3.0.1 / 2015-01-23
|
@@ -23,38 +114,38 @@
|
|
23
114
|
|
24
115
|
## 3.0.0 / 2014-11-12
|
25
116
|
|
26
|
-
* Removed Block#end_tag. Instead, override parse with `super` followed by your code. See #446 [Dylan Thacker-Smith
|
27
|
-
* Fixed condition with wrong data types
|
28
|
-
* Add url_encode to standard filters
|
29
|
-
* Add uniq to standard filters [Florian Weingarten
|
30
|
-
* Add exception_handler feature
|
31
|
-
* Optimize variable parsing to avoid repeated regex evaluation during template rendering #383 [Jason Hiltz-Laforge
|
32
|
-
* Optimize checking for block interrupts to reduce object allocation #380 [Jason Hiltz-Laforge
|
33
|
-
* Properly set context rethrow_errors on render! #349 [Thierry Joyal
|
34
|
-
* Fix broken rendering of variables which are equal to false
|
35
|
-
* Remove ActionView template handler [Dylan Thacker-Smith
|
36
|
-
* Freeze lots of string literals for new Ruby 2.1 optimization
|
37
|
-
* Allow newlines in tags and variables
|
38
|
-
* Tag#parse is called after initialize, which now takes options instead of tokens as the 3rd argument. See #321 [Dylan Thacker-Smith
|
39
|
-
* Raise `Liquid::ArgumentError` instead of `::ArgumentError` when filter has wrong number of arguments #309 [Bogdan Gusiev
|
40
|
-
* Add a to_s default for liquid drops
|
41
|
-
* Add strip, lstrip, and rstrip to standard filters [Florian Weingarten
|
42
|
-
* Make if, for & case tags return complete and consistent nodelists
|
43
|
-
* Prevent arbitrary method invocation on condition objects
|
44
|
-
* Don't call to_sym when creating conditions for security reasons
|
45
|
-
* Fix resource counting bug with respond_to?(:length)
|
46
|
-
* Allow specifying custom patterns for template filenames
|
47
|
-
* Allow drops to optimize loading a slice of elements
|
48
|
-
* Support for passing variables to snippets in subdirs
|
49
|
-
* Add a class cache to avoid runtime extend calls
|
50
|
-
* Remove some legacy Ruby 1.8 compatibility code
|
51
|
-
* Add default filter to standard filters
|
52
|
-
* Add optional strict parsing and warn parsing
|
53
|
-
* Add I18n syntax error translation
|
54
|
-
* Make sort filter work on enumerable drops
|
55
|
-
* Fix clashing method names in enumerable drops
|
56
|
-
* Make map filter work on enumerable drops
|
57
|
-
* Improved whitespace stripping for blank blocks, related to #216 [Florian Weingarten
|
117
|
+
* Removed Block#end_tag. Instead, override parse with `super` followed by your code. See #446 [Dylan Thacker-Smith]
|
118
|
+
* Fixed condition with wrong data types (#423) [Bogdan Gusiev]
|
119
|
+
* Add url_encode to standard filters (#421) [Derrick Reimer]
|
120
|
+
* Add uniq to standard filters [Florian Weingarten]
|
121
|
+
* Add exception_handler feature (#397) and #254 [Bogdan Gusiev, Florian Weingarten]
|
122
|
+
* Optimize variable parsing to avoid repeated regex evaluation during template rendering #383 [Jason Hiltz-Laforge]
|
123
|
+
* Optimize checking for block interrupts to reduce object allocation #380 [Jason Hiltz-Laforge]
|
124
|
+
* Properly set context rethrow_errors on render! #349 [Thierry Joyal]
|
125
|
+
* Fix broken rendering of variables which are equal to false (#345) [Florian Weingarten]
|
126
|
+
* Remove ActionView template handler [Dylan Thacker-Smith]
|
127
|
+
* Freeze lots of string literals for new Ruby 2.1 optimization (#297) [Florian Weingarten]
|
128
|
+
* Allow newlines in tags and variables (#324) [Dylan Thacker-Smith]
|
129
|
+
* Tag#parse is called after initialize, which now takes options instead of tokens as the 3rd argument. See #321 [Dylan Thacker-Smith]
|
130
|
+
* Raise `Liquid::ArgumentError` instead of `::ArgumentError` when filter has wrong number of arguments #309 [Bogdan Gusiev]
|
131
|
+
* Add a to_s default for liquid drops (#306) [Adam Doeler]
|
132
|
+
* Add strip, lstrip, and rstrip to standard filters [Florian Weingarten]
|
133
|
+
* Make if, for & case tags return complete and consistent nodelists (#250) [Nick Jones]
|
134
|
+
* Prevent arbitrary method invocation on condition objects (#274) [Dylan Thacker-Smith]
|
135
|
+
* Don't call to_sym when creating conditions for security reasons (#273) [Bouke van der Bijl]
|
136
|
+
* Fix resource counting bug with respond_to?(:length) (#263) [Florian Weingarten]
|
137
|
+
* Allow specifying custom patterns for template filenames (#284) [Andrei Gladkyi]
|
138
|
+
* Allow drops to optimize loading a slice of elements (#282) [Tom Burns]
|
139
|
+
* Support for passing variables to snippets in subdirs (#271) [Joost Hietbrink]
|
140
|
+
* Add a class cache to avoid runtime extend calls (#249) [James Tucker]
|
141
|
+
* Remove some legacy Ruby 1.8 compatibility code (#276) [Florian Weingarten]
|
142
|
+
* Add default filter to standard filters (#267) [Derrick Reimer]
|
143
|
+
* Add optional strict parsing and warn parsing (#235) [Tristan Hume]
|
144
|
+
* Add I18n syntax error translation (#241) [Simon Hørup Eskildsen, Sirupsen]
|
145
|
+
* Make sort filter work on enumerable drops (#239) [Florian Weingarten]
|
146
|
+
* Fix clashing method names in enumerable drops (#238) [Florian Weingarten]
|
147
|
+
* Make map filter work on enumerable drops (#233) [Florian Weingarten]
|
148
|
+
* Improved whitespace stripping for blank blocks, related to #216 [Florian Weingarten]
|
58
149
|
|
59
150
|
## 2.6.3 / 2015-07-23 / branch "2-6-stable"
|
60
151
|
|
@@ -67,8 +158,8 @@
|
|
67
158
|
## 2.6.1 / 2014-01-10
|
68
159
|
|
69
160
|
Security fix, cherry-picked from master (4e14a65):
|
70
|
-
* Don't call to_sym when creating conditions for security reasons
|
71
|
-
* Prevent arbitrary method invocation on condition objects
|
161
|
+
* Don't call to_sym when creating conditions for security reasons (#273) [Bouke van der Bijl]
|
162
|
+
* Prevent arbitrary method invocation on condition objects (#274) [Dylan Thacker-Smith]
|
72
163
|
|
73
164
|
## 2.6.0 / 2013-11-25
|
74
165
|
|
@@ -76,37 +167,37 @@ IMPORTANT: Liquid 2.6 is going to be the last version of Liquid which maintains
|
|
76
167
|
The following releases will only be tested against Ruby 1.9 and Ruby 2.0 and are likely to break on Ruby 1.8.
|
77
168
|
|
78
169
|
* Bugfix for #106: fix example servlet [gnowoel]
|
79
|
-
* Bugfix for #97: strip_html filter supports multi-line tags [Jo Liss
|
80
|
-
* Bugfix for #114: strip_html filter supports style tags [James Allardice
|
81
|
-
* Bugfix for #117: 'now' support for date filter in Ruby 1.9 [Notre Dame Webgroup
|
82
|
-
* Bugfix for #166: truncate filter on UTF-8 strings with Ruby 1.8 [Florian Weingarten
|
83
|
-
* Bugfix for #204: 'raw' parsing bug [Florian Weingarten
|
84
|
-
* Bugfix for #150: 'for' parsing bug [Peter Schröder
|
85
|
-
* Bugfix for #126: Strip CRLF in strip_newline [Peter Schröder
|
86
|
-
* Bugfix for #174, "can't convert Fixnum into String" for "replace" [
|
87
|
-
* Allow a Liquid::Drop to be passed into Template#render [Daniel Huckstep
|
88
|
-
* Resource limits [Florian Weingarten
|
89
|
-
* Add reverse filter [Jay Strybis
|
170
|
+
* Bugfix for #97: strip_html filter supports multi-line tags [Jo Liss]
|
171
|
+
* Bugfix for #114: strip_html filter supports style tags [James Allardice]
|
172
|
+
* Bugfix for #117: 'now' support for date filter in Ruby 1.9 [Notre Dame Webgroup]
|
173
|
+
* Bugfix for #166: truncate filter on UTF-8 strings with Ruby 1.8 [Florian Weingarten]
|
174
|
+
* Bugfix for #204: 'raw' parsing bug [Florian Weingarten]
|
175
|
+
* Bugfix for #150: 'for' parsing bug [Peter Schröder]
|
176
|
+
* Bugfix for #126: Strip CRLF in strip_newline [Peter Schröder]
|
177
|
+
* Bugfix for #174, "can't convert Fixnum into String" for "replace" [jsw0528]
|
178
|
+
* Allow a Liquid::Drop to be passed into Template#render [Daniel Huckstep]
|
179
|
+
* Resource limits [Florian Weingarten]
|
180
|
+
* Add reverse filter [Jay Strybis]
|
90
181
|
* Add utf-8 support
|
91
|
-
* Use array instead of Hash to keep the registered filters [Tasos Stathopoulos
|
92
|
-
* Cache tokenized partial templates [Tom Burns
|
93
|
-
* Avoid warnings in Ruby 1.9.3 [Marcus Stollsteimer
|
94
|
-
* Better documentation for 'include' tag (closes #163) [Peter Schröder
|
95
|
-
* Use of BigDecimal on filters to have better precision (closes #155) [Arthur Nogueira Neves
|
182
|
+
* Use array instead of Hash to keep the registered filters [Tasos Stathopoulos]
|
183
|
+
* Cache tokenized partial templates [Tom Burns]
|
184
|
+
* Avoid warnings in Ruby 1.9.3 [Marcus Stollsteimer]
|
185
|
+
* Better documentation for 'include' tag (closes #163) [Peter Schröder]
|
186
|
+
* Use of BigDecimal on filters to have better precision (closes #155) [Arthur Nogueira Neves]
|
96
187
|
|
97
188
|
## 2.5.5 / 2014-01-10 / branch "2-5-stable"
|
98
189
|
|
99
190
|
Security fix, cherry-picked from master (4e14a65):
|
100
|
-
* Don't call to_sym when creating conditions for security reasons
|
101
|
-
* Prevent arbitrary method invocation on condition objects
|
191
|
+
* Don't call to_sym when creating conditions for security reasons (#273) [Bouke van der Bijl]
|
192
|
+
* Prevent arbitrary method invocation on condition objects (#274) [Dylan Thacker-Smith]
|
102
193
|
|
103
194
|
## 2.5.4 / 2013-11-11
|
104
195
|
|
105
|
-
* Fix "can't convert Fixnum into String" for "replace"
|
196
|
+
* Fix "can't convert Fixnum into String" for "replace" (#173), [jsw0528]
|
106
197
|
|
107
198
|
## 2.5.3 / 2013-10-09
|
108
199
|
|
109
|
-
* #232, #234, #237: Fix map filter bugs [Florian Weingarten
|
200
|
+
* #232, #234, #237: Fix map filter bugs [Florian Weingarten]
|
110
201
|
|
111
202
|
## 2.5.2 / 2013-09-03 / deleted
|
112
203
|
|
@@ -114,7 +205,7 @@ Yanked from rubygems, as it contained too many changes that broke compatibility.
|
|
114
205
|
|
115
206
|
## 2.5.1 / 2013-07-24
|
116
207
|
|
117
|
-
* #230: Fix security issue with map filter, Use invoke_drop in map filter [Florian Weingarten
|
208
|
+
* #230: Fix security issue with map filter, Use invoke_drop in map filter [Florian Weingarten]
|
118
209
|
|
119
210
|
## 2.5.0 / 2013-03-06
|
120
211
|
|
data/{MIT-LICENSE → LICENSE}
RENAMED
File without changes
|
data/README.md
CHANGED
@@ -42,6 +42,8 @@ Liquid is a template engine which was written with very specific requirements:
|
|
42
42
|
|
43
43
|
## How to use Liquid
|
44
44
|
|
45
|
+
Install Liquid by adding `gem 'liquid'` to your gemfile.
|
46
|
+
|
45
47
|
Liquid supports a very simple API based around the Liquid::Template class.
|
46
48
|
For standard use you can just pass it the content of a file and call render with a parameters hash.
|
47
49
|
|
@@ -73,3 +75,34 @@ This is useful for doing things like enabling strict mode only in the theme edit
|
|
73
75
|
|
74
76
|
It is recommended that you enable `:strict` or `:warn` mode on new apps to stop invalid templates from being created.
|
75
77
|
It is also recommended that you use it in the template editors of existing apps to give editors better error messages.
|
78
|
+
|
79
|
+
### Undefined variables and filters
|
80
|
+
|
81
|
+
By default, the renderer doesn't raise or in any other way notify you if some variables or filters are missing, i.e. not passed to the `render` method.
|
82
|
+
You can improve this situation by passing `strict_variables: true` and/or `strict_filters: true` options to the `render` method.
|
83
|
+
When one of these options is set to true, all errors about undefined variables and undefined filters will be stored in `errors` array of a `Liquid::Template` instance.
|
84
|
+
Here are some examples:
|
85
|
+
|
86
|
+
```ruby
|
87
|
+
template = Liquid::Template.parse("{{x}} {{y}} {{z.a}} {{z.b}}")
|
88
|
+
template.render({ 'x' => 1, 'z' => { 'a' => 2 } }, { strict_variables: true })
|
89
|
+
#=> '1 2 ' # when a variable is undefined, it's rendered as nil
|
90
|
+
template.errors
|
91
|
+
#=> [#<Liquid::UndefinedVariable: Liquid error: undefined variable y>, #<Liquid::UndefinedVariable: Liquid error: undefined variable b>]
|
92
|
+
```
|
93
|
+
|
94
|
+
```ruby
|
95
|
+
template = Liquid::Template.parse("{{x | filter1 | upcase}}")
|
96
|
+
template.render({ 'x' => 'foo' }, { strict_filters: true })
|
97
|
+
#=> '' # when at least one filter in the filter chain is undefined, a whole expression is rendered as nil
|
98
|
+
template.errors
|
99
|
+
#=> [#<Liquid::UndefinedFilter: Liquid error: undefined filter filter1>]
|
100
|
+
```
|
101
|
+
|
102
|
+
If you want to raise on a first exception instead of pushing all of them in `errors`, you can use `render!` method:
|
103
|
+
|
104
|
+
```ruby
|
105
|
+
template = Liquid::Template.parse("{{x}} {{y}}")
|
106
|
+
template.render!({ 'x' => 1}, { strict_variables: true })
|
107
|
+
#=> Liquid::UndefinedVariable: Liquid error: undefined variable y
|
108
|
+
```
|
data/lib/liquid/block.rb
CHANGED
@@ -1,90 +1,41 @@
|
|
1
1
|
module Liquid
|
2
2
|
class Block < Tag
|
3
|
-
|
4
|
-
ContentOfVariable = /\A#{VariableStart}(.*)#{VariableEnd}\z/om
|
5
|
-
TAGSTART = "{%".freeze
|
6
|
-
VARSTART = "{{".freeze
|
3
|
+
MAX_DEPTH = 100
|
7
4
|
|
8
|
-
def
|
9
|
-
|
5
|
+
def initialize(tag_name, markup, options)
|
6
|
+
super
|
7
|
+
@blank = true
|
10
8
|
end
|
11
9
|
|
12
10
|
def parse(tokens)
|
13
|
-
@
|
14
|
-
@
|
15
|
-
@nodelist.clear
|
16
|
-
|
17
|
-
while token = tokens.shift
|
18
|
-
begin
|
19
|
-
unless token.empty?
|
20
|
-
case
|
21
|
-
when token.start_with?(TAGSTART)
|
22
|
-
if token =~ FullToken
|
23
|
-
|
24
|
-
# if we found the proper block delimiter just end parsing here and let the outer block
|
25
|
-
# proceed
|
26
|
-
return if block_delimiter == $1
|
27
|
-
|
28
|
-
# fetch the tag from registered blocks
|
29
|
-
if tag = Template.tags[$1]
|
30
|
-
markup = token.is_a?(Token) ? token.child($2) : $2
|
31
|
-
new_tag = tag.parse($1, markup, tokens, @options)
|
32
|
-
new_tag.line_number = token.line_number if token.is_a?(Token)
|
33
|
-
@blank &&= new_tag.blank?
|
34
|
-
@nodelist << new_tag
|
35
|
-
else
|
36
|
-
# this tag is not registered with the system
|
37
|
-
# pass it to the current block for special handling or error reporting
|
38
|
-
unknown_tag($1, $2, tokens)
|
39
|
-
end
|
40
|
-
else
|
41
|
-
raise SyntaxError.new(options[:locale].t("errors.syntax.tag_termination".freeze, :token => token, :tag_end => TagEnd.inspect))
|
42
|
-
end
|
43
|
-
when token.start_with?(VARSTART)
|
44
|
-
new_var = create_variable(token)
|
45
|
-
new_var.line_number = token.line_number if token.is_a?(Token)
|
46
|
-
@nodelist << new_var
|
47
|
-
@blank = false
|
48
|
-
else
|
49
|
-
@nodelist << token
|
50
|
-
@blank &&= (token =~ /\A\s*\z/)
|
51
|
-
end
|
52
|
-
end
|
53
|
-
rescue SyntaxError => e
|
54
|
-
e.set_line_number_from_token(token)
|
55
|
-
raise
|
56
|
-
end
|
11
|
+
@body = BlockBody.new
|
12
|
+
while parse_body(@body, tokens)
|
57
13
|
end
|
58
|
-
|
59
|
-
# Make sure that it's ok to end parsing in the current block.
|
60
|
-
# Effectively this method will throw an exception unless the current block is
|
61
|
-
# of type Document
|
62
|
-
assert_missing_delimitation!
|
63
14
|
end
|
64
15
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
all_warnings.concat(@warnings) if @warnings
|
16
|
+
def render(context)
|
17
|
+
@body.render(context)
|
18
|
+
end
|
69
19
|
|
70
|
-
|
71
|
-
|
72
|
-
|
20
|
+
def blank?
|
21
|
+
@blank
|
22
|
+
end
|
73
23
|
|
74
|
-
|
24
|
+
def nodelist
|
25
|
+
@body.nodelist
|
75
26
|
end
|
76
27
|
|
77
|
-
def unknown_tag(tag,
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
28
|
+
def unknown_tag(tag, _params, _tokens)
|
29
|
+
if tag == 'else'.freeze
|
30
|
+
raise SyntaxError.new(parse_context.locale.t("errors.syntax.unexpected_else".freeze,
|
31
|
+
block_name: block_name))
|
32
|
+
elsif tag.start_with?('end'.freeze)
|
33
|
+
raise SyntaxError.new(parse_context.locale.t("errors.syntax.invalid_delimiter".freeze,
|
34
|
+
tag: tag,
|
35
|
+
block_name: block_name,
|
36
|
+
block_delimiter: block_delimiter))
|
86
37
|
else
|
87
|
-
raise SyntaxError.new(
|
38
|
+
raise SyntaxError.new(parse_context.locale.t("errors.syntax.unknown_tag".freeze, tag: tag))
|
88
39
|
end
|
89
40
|
end
|
90
41
|
|
@@ -96,65 +47,31 @@ module Liquid
|
|
96
47
|
@block_delimiter ||= "end#{block_name}"
|
97
48
|
end
|
98
49
|
|
99
|
-
def create_variable(token)
|
100
|
-
token.scan(ContentOfVariable) do |content|
|
101
|
-
markup = token.is_a?(Token) ? token.child(content.first) : content.first
|
102
|
-
return Variable.new(markup, @options)
|
103
|
-
end
|
104
|
-
raise SyntaxError.new(options[:locale].t("errors.syntax.variable_termination".freeze, :token => token, :tag_end => VariableEnd.inspect))
|
105
|
-
end
|
106
|
-
|
107
|
-
def render(context)
|
108
|
-
render_all(@nodelist, context)
|
109
|
-
end
|
110
|
-
|
111
50
|
protected
|
112
51
|
|
113
|
-
def
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
begin
|
127
|
-
# If we get an Interrupt that means the block must stop processing. An
|
128
|
-
# Interrupt is any command that stops block execution such as {% break %}
|
129
|
-
# or {% continue %}
|
130
|
-
if token.is_a? Continue or token.is_a? Break
|
131
|
-
context.push_interrupt(token.interrupt)
|
132
|
-
break
|
52
|
+
def parse_body(body, tokens)
|
53
|
+
if parse_context.depth >= MAX_DEPTH
|
54
|
+
raise StackLevelError, "Nesting too deep".freeze
|
55
|
+
end
|
56
|
+
parse_context.depth += 1
|
57
|
+
begin
|
58
|
+
body.parse(tokens, parse_context) do |end_tag_name, end_tag_params|
|
59
|
+
@blank &&= body.blank?
|
60
|
+
|
61
|
+
return false if end_tag_name == block_delimiter
|
62
|
+
unless end_tag_name
|
63
|
+
raise SyntaxError.new(parse_context.locale.t("errors.syntax.tag_never_closed".freeze, block_name: block_name))
|
133
64
|
end
|
134
65
|
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
output << token_output
|
139
|
-
end
|
140
|
-
rescue MemoryError => e
|
141
|
-
raise e
|
142
|
-
rescue ::StandardError => e
|
143
|
-
output << (context.handle_error(e, token))
|
66
|
+
# this tag is not registered with the system
|
67
|
+
# pass it to the current block for special handling or error reporting
|
68
|
+
unknown_tag(end_tag_name, end_tag_params, tokens)
|
144
69
|
end
|
70
|
+
ensure
|
71
|
+
parse_context.depth -= 1
|
145
72
|
end
|
146
73
|
|
147
|
-
|
148
|
-
end
|
149
|
-
|
150
|
-
def render_token(token, context)
|
151
|
-
token_output = (token.respond_to?(:render) ? token.render(context) : token)
|
152
|
-
context.increment_used_resources(:render_length_current, token_output)
|
153
|
-
if context.resource_limits_reached?
|
154
|
-
context.resource_limits[:reached] = true
|
155
|
-
raise MemoryError.new("Memory limits exceeded".freeze)
|
156
|
-
end
|
157
|
-
token_output
|
74
|
+
true
|
158
75
|
end
|
159
76
|
end
|
160
77
|
end
|