liquid-4-0-2 4.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. checksums.yaml +7 -0
  2. data/History.md +235 -0
  3. data/LICENSE +20 -0
  4. data/README.md +108 -0
  5. data/lib/liquid.rb +80 -0
  6. data/lib/liquid/block.rb +77 -0
  7. data/lib/liquid/block_body.rb +142 -0
  8. data/lib/liquid/condition.rb +151 -0
  9. data/lib/liquid/context.rb +226 -0
  10. data/lib/liquid/document.rb +27 -0
  11. data/lib/liquid/drop.rb +78 -0
  12. data/lib/liquid/errors.rb +56 -0
  13. data/lib/liquid/expression.rb +49 -0
  14. data/lib/liquid/extensions.rb +74 -0
  15. data/lib/liquid/file_system.rb +73 -0
  16. data/lib/liquid/forloop_drop.rb +42 -0
  17. data/lib/liquid/i18n.rb +39 -0
  18. data/lib/liquid/interrupts.rb +16 -0
  19. data/lib/liquid/lexer.rb +55 -0
  20. data/lib/liquid/locales/en.yml +26 -0
  21. data/lib/liquid/parse_context.rb +38 -0
  22. data/lib/liquid/parse_tree_visitor.rb +42 -0
  23. data/lib/liquid/parser.rb +90 -0
  24. data/lib/liquid/parser_switching.rb +31 -0
  25. data/lib/liquid/profiler.rb +158 -0
  26. data/lib/liquid/profiler/hooks.rb +23 -0
  27. data/lib/liquid/range_lookup.rb +37 -0
  28. data/lib/liquid/resource_limits.rb +23 -0
  29. data/lib/liquid/standardfilters.rb +485 -0
  30. data/lib/liquid/strainer.rb +66 -0
  31. data/lib/liquid/tablerowloop_drop.rb +62 -0
  32. data/lib/liquid/tag.rb +43 -0
  33. data/lib/liquid/tags/assign.rb +59 -0
  34. data/lib/liquid/tags/break.rb +18 -0
  35. data/lib/liquid/tags/capture.rb +38 -0
  36. data/lib/liquid/tags/case.rb +94 -0
  37. data/lib/liquid/tags/comment.rb +16 -0
  38. data/lib/liquid/tags/continue.rb +18 -0
  39. data/lib/liquid/tags/cycle.rb +65 -0
  40. data/lib/liquid/tags/decrement.rb +35 -0
  41. data/lib/liquid/tags/for.rb +203 -0
  42. data/lib/liquid/tags/if.rb +122 -0
  43. data/lib/liquid/tags/ifchanged.rb +18 -0
  44. data/lib/liquid/tags/include.rb +124 -0
  45. data/lib/liquid/tags/increment.rb +31 -0
  46. data/lib/liquid/tags/raw.rb +47 -0
  47. data/lib/liquid/tags/table_row.rb +62 -0
  48. data/lib/liquid/tags/unless.rb +30 -0
  49. data/lib/liquid/template.rb +254 -0
  50. data/lib/liquid/tokenizer.rb +31 -0
  51. data/lib/liquid/utils.rb +83 -0
  52. data/lib/liquid/variable.rb +148 -0
  53. data/lib/liquid/variable_lookup.rb +88 -0
  54. data/lib/liquid/version.rb +4 -0
  55. data/test/fixtures/en_locale.yml +9 -0
  56. data/test/integration/assign_test.rb +48 -0
  57. data/test/integration/blank_test.rb +106 -0
  58. data/test/integration/block_test.rb +12 -0
  59. data/test/integration/capture_test.rb +50 -0
  60. data/test/integration/context_test.rb +32 -0
  61. data/test/integration/document_test.rb +19 -0
  62. data/test/integration/drop_test.rb +273 -0
  63. data/test/integration/error_handling_test.rb +260 -0
  64. data/test/integration/filter_test.rb +178 -0
  65. data/test/integration/hash_ordering_test.rb +23 -0
  66. data/test/integration/output_test.rb +123 -0
  67. data/test/integration/parse_tree_visitor_test.rb +247 -0
  68. data/test/integration/parsing_quirks_test.rb +122 -0
  69. data/test/integration/render_profiling_test.rb +154 -0
  70. data/test/integration/security_test.rb +80 -0
  71. data/test/integration/standard_filter_test.rb +698 -0
  72. data/test/integration/tags/break_tag_test.rb +15 -0
  73. data/test/integration/tags/continue_tag_test.rb +15 -0
  74. data/test/integration/tags/for_tag_test.rb +410 -0
  75. data/test/integration/tags/if_else_tag_test.rb +188 -0
  76. data/test/integration/tags/include_tag_test.rb +245 -0
  77. data/test/integration/tags/increment_tag_test.rb +23 -0
  78. data/test/integration/tags/raw_tag_test.rb +31 -0
  79. data/test/integration/tags/standard_tag_test.rb +296 -0
  80. data/test/integration/tags/statements_test.rb +111 -0
  81. data/test/integration/tags/table_row_test.rb +64 -0
  82. data/test/integration/tags/unless_else_tag_test.rb +26 -0
  83. data/test/integration/template_test.rb +332 -0
  84. data/test/integration/trim_mode_test.rb +529 -0
  85. data/test/integration/variable_test.rb +96 -0
  86. data/test/test_helper.rb +116 -0
  87. data/test/unit/block_unit_test.rb +58 -0
  88. data/test/unit/condition_unit_test.rb +166 -0
  89. data/test/unit/context_unit_test.rb +489 -0
  90. data/test/unit/file_system_unit_test.rb +35 -0
  91. data/test/unit/i18n_unit_test.rb +37 -0
  92. data/test/unit/lexer_unit_test.rb +51 -0
  93. data/test/unit/parser_unit_test.rb +82 -0
  94. data/test/unit/regexp_unit_test.rb +44 -0
  95. data/test/unit/strainer_unit_test.rb +164 -0
  96. data/test/unit/tag_unit_test.rb +21 -0
  97. data/test/unit/tags/case_tag_unit_test.rb +10 -0
  98. data/test/unit/tags/for_tag_unit_test.rb +13 -0
  99. data/test/unit/tags/if_tag_unit_test.rb +8 -0
  100. data/test/unit/template_unit_test.rb +78 -0
  101. data/test/unit/tokenizer_unit_test.rb +55 -0
  102. data/test/unit/variable_unit_test.rb +162 -0
  103. metadata +224 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6fda735ee69a1b1ec6e0d06c0cc3a24fb2b58c9107e37789aa29a4d0446ee0d7
4
+ data.tar.gz: 742234d70916644fd5360a8d30b486646835618e9cf911d417b4b7afba68ae21
5
+ SHA512:
6
+ metadata.gz: 01645f11383d2dab2bd5f103b73fa4f57744695d439926d01a7c2374d8fe0eb45c9e60ae94840169e3281d8de90c185edc208310f7101a32fa7c368bec9945b2
7
+ data.tar.gz: be89e302236ac1053980f2f4e700074d6bc3ee060eeacdcf4d65373350c328a0fe49d82990d890a96e08ca8ced3baff9f256b0d9a511dc75595dc6c6627ef358
@@ -0,0 +1,235 @@
1
+ # Liquid Change Log
2
+
3
+ ## 4.0.0 / 2016-12-14 / branch "4-0-stable"
4
+
5
+ ### Changed
6
+ * Render an opaque internal error by default for non-Liquid::Error (#835) [Dylan Thacker-Smith]
7
+ * Ruby 2.0 support dropped (#832) [Dylan Thacker-Smith]
8
+ * Add to_number Drop method to allow custom drops to work with number filters (#731)
9
+ * Add strict_variables and strict_filters options to detect undefined references (#691)
10
+ * Improve loop performance (#681) [Florian Weingarten]
11
+ * Rename Drop method `before_method` to `liquid_method_missing` (#661) [Thierry Joyal]
12
+ * Add url_decode filter to invert url_encode (#645) [Larry Archer]
13
+ * Add global_filter to apply a filter to all output (#610) [Loren Hale]
14
+ * Add compact filter (#600) [Carson Reinke]
15
+ * Rename deprecated "has_key?" and "has_interrupt?" methods (#593) [Florian Weingarten]
16
+ * Include template name with line numbers in render errors (574) [Dylan Thacker-Smith]
17
+ * Add sort_natural filter (#554) [Martin Hanzel]
18
+ * Add forloop.parentloop as a reference to the parent loop (#520) [Justin Li]
19
+ * Block parsing moved to BlockBody class (#458) [Dylan Thacker-Smith]
20
+ * Add concat filter to concatenate arrays (#429) [Diogo Beato]
21
+ * Ruby 1.9 support dropped (#491) [Justin Li]
22
+ * Liquid::Template.file_system's read_template_file method is no longer passed the context. (#441) [James Reid-Smith]
23
+ * Remove `liquid_methods` (See https://github.com/Shopify/liquid/pull/568 for replacement)
24
+ * Liquid::Template.register_filter raises when the module overrides registered public methods as private or protected (#705) [Gaurav Chande]
25
+
26
+ ### Fixed
27
+
28
+ * Fix variable names being detected as an operator when starting with contains (#788) [Michael Angell]
29
+ * Fix include tag used with strict_variables (#828) [QuickPay]
30
+ * Fix map filter when value is a Proc (#672) [Guillaume Malette]
31
+ * Fix truncate filter when value is not a string (#672) [Guillaume Malette]
32
+ * Fix behaviour of escape filter when input is nil (#665) [Tanel Jakobsoo]
33
+ * Fix sort filter behaviour with empty array input (#652) [Marcel Cary]
34
+ * Fix test failure under certain timezones (#631) [Dylan Thacker-Smith]
35
+ * Fix bug in uniq filter (#595) [Florian Weingarten]
36
+ * Fix bug when "blank" and "empty" are used as variable names (#592) [Florian Weingarten]
37
+ * Fix condition parse order in strict mode (#569) [Justin Li]
38
+ * Fix naming of the "context variable" when dynamically including a template (#559) [Justin Li]
39
+ * Gracefully accept empty strings in the date filter (#555) [Loren Hale]
40
+ * Fix capturing into variables with a hyphen in the name (#505) [Florian Weingarten]
41
+ * Fix case sensitivity regression in date standard filter (#499) [Kelley Reynolds]
42
+ * Disallow filters with no variable in strict mode (#475) [Justin Li]
43
+ * Disallow variable names in the strict parser that are not valid in the lax parser (#463) [Justin Li]
44
+ * Fix BlockBody#warnings taking exponential time to compute (#486) [Justin Li]
45
+
46
+ ## 3.0.5 / 2015-07-23 / branch "3-0-stable"
47
+
48
+ * Fix test failure under certain timezones [Dylan Thacker-Smith]
49
+
50
+ ## 3.0.4 / 2015-07-17
51
+
52
+ * Fix chained access to multi-dimensional hashes [Florian Weingarten]
53
+
54
+ ## 3.0.3 / 2015-05-28
55
+
56
+ * Fix condition parse order in strict mode (#569) [Justin Li]
57
+
58
+ ## 3.0.2 / 2015-04-24
59
+
60
+ * Expose VariableLookup private members (#551) [Justin Li]
61
+ * Documentation fixes
62
+
63
+ ## 3.0.1 / 2015-01-23
64
+
65
+ * Remove duplicate `index0` key in TableRow tag (#502) [Alfred Xing]
66
+
67
+ ## 3.0.0 / 2014-11-12
68
+
69
+ * Removed Block#end_tag. Instead, override parse with `super` followed by your code. See #446 [Dylan Thacker-Smith]
70
+ * Fixed condition with wrong data types (#423) [Bogdan Gusiev]
71
+ * Add url_encode to standard filters (#421) [Derrick Reimer]
72
+ * Add uniq to standard filters [Florian Weingarten]
73
+ * Add exception_handler feature (#397) and #254 [Bogdan Gusiev, Florian Weingarten]
74
+ * Optimize variable parsing to avoid repeated regex evaluation during template rendering #383 [Jason Hiltz-Laforge]
75
+ * Optimize checking for block interrupts to reduce object allocation #380 [Jason Hiltz-Laforge]
76
+ * Properly set context rethrow_errors on render! #349 [Thierry Joyal]
77
+ * Fix broken rendering of variables which are equal to false (#345) [Florian Weingarten]
78
+ * Remove ActionView template handler [Dylan Thacker-Smith]
79
+ * Freeze lots of string literals for new Ruby 2.1 optimization (#297) [Florian Weingarten]
80
+ * Allow newlines in tags and variables (#324) [Dylan Thacker-Smith]
81
+ * Tag#parse is called after initialize, which now takes options instead of tokens as the 3rd argument. See #321 [Dylan Thacker-Smith]
82
+ * Raise `Liquid::ArgumentError` instead of `::ArgumentError` when filter has wrong number of arguments #309 [Bogdan Gusiev]
83
+ * Add a to_s default for liquid drops (#306) [Adam Doeler]
84
+ * Add strip, lstrip, and rstrip to standard filters [Florian Weingarten]
85
+ * Make if, for & case tags return complete and consistent nodelists (#250) [Nick Jones]
86
+ * Prevent arbitrary method invocation on condition objects (#274) [Dylan Thacker-Smith]
87
+ * Don't call to_sym when creating conditions for security reasons (#273) [Bouke van der Bijl]
88
+ * Fix resource counting bug with respond_to?(:length) (#263) [Florian Weingarten]
89
+ * Allow specifying custom patterns for template filenames (#284) [Andrei Gladkyi]
90
+ * Allow drops to optimize loading a slice of elements (#282) [Tom Burns]
91
+ * Support for passing variables to snippets in subdirs (#271) [Joost Hietbrink]
92
+ * Add a class cache to avoid runtime extend calls (#249) [James Tucker]
93
+ * Remove some legacy Ruby 1.8 compatibility code (#276) [Florian Weingarten]
94
+ * Add default filter to standard filters (#267) [Derrick Reimer]
95
+ * Add optional strict parsing and warn parsing (#235) [Tristan Hume]
96
+ * Add I18n syntax error translation (#241) [Simon Hørup Eskildsen, Sirupsen]
97
+ * Make sort filter work on enumerable drops (#239) [Florian Weingarten]
98
+ * Fix clashing method names in enumerable drops (#238) [Florian Weingarten]
99
+ * Make map filter work on enumerable drops (#233) [Florian Weingarten]
100
+ * Improved whitespace stripping for blank blocks, related to #216 [Florian Weingarten]
101
+
102
+ ## 2.6.3 / 2015-07-23 / branch "2-6-stable"
103
+
104
+ * Fix test failure under certain timezones [Dylan Thacker-Smith]
105
+
106
+ ## 2.6.2 / 2015-01-23
107
+
108
+ * Remove duplicate hash key [Parker Moore]
109
+
110
+ ## 2.6.1 / 2014-01-10
111
+
112
+ Security fix, cherry-picked from master (4e14a65):
113
+ * Don't call to_sym when creating conditions for security reasons (#273) [Bouke van der Bijl]
114
+ * Prevent arbitrary method invocation on condition objects (#274) [Dylan Thacker-Smith]
115
+
116
+ ## 2.6.0 / 2013-11-25
117
+
118
+ IMPORTANT: Liquid 2.6 is going to be the last version of Liquid which maintains explicit Ruby 1.8 compatability.
119
+ The following releases will only be tested against Ruby 1.9 and Ruby 2.0 and are likely to break on Ruby 1.8.
120
+
121
+ * Bugfix for #106: fix example servlet [gnowoel]
122
+ * Bugfix for #97: strip_html filter supports multi-line tags [Jo Liss]
123
+ * Bugfix for #114: strip_html filter supports style tags [James Allardice]
124
+ * Bugfix for #117: 'now' support for date filter in Ruby 1.9 [Notre Dame Webgroup]
125
+ * Bugfix for #166: truncate filter on UTF-8 strings with Ruby 1.8 [Florian Weingarten]
126
+ * Bugfix for #204: 'raw' parsing bug [Florian Weingarten]
127
+ * Bugfix for #150: 'for' parsing bug [Peter Schröder]
128
+ * Bugfix for #126: Strip CRLF in strip_newline [Peter Schröder]
129
+ * Bugfix for #174, "can't convert Fixnum into String" for "replace" [jsw0528]
130
+ * Allow a Liquid::Drop to be passed into Template#render [Daniel Huckstep]
131
+ * Resource limits [Florian Weingarten]
132
+ * Add reverse filter [Jay Strybis]
133
+ * Add utf-8 support
134
+ * Use array instead of Hash to keep the registered filters [Tasos Stathopoulos]
135
+ * Cache tokenized partial templates [Tom Burns]
136
+ * Avoid warnings in Ruby 1.9.3 [Marcus Stollsteimer]
137
+ * Better documentation for 'include' tag (closes #163) [Peter Schröder]
138
+ * Use of BigDecimal on filters to have better precision (closes #155) [Arthur Nogueira Neves]
139
+
140
+ ## 2.5.5 / 2014-01-10 / branch "2-5-stable"
141
+
142
+ Security fix, cherry-picked from master (4e14a65):
143
+ * Don't call to_sym when creating conditions for security reasons (#273) [Bouke van der Bijl]
144
+ * Prevent arbitrary method invocation on condition objects (#274) [Dylan Thacker-Smith]
145
+
146
+ ## 2.5.4 / 2013-11-11
147
+
148
+ * Fix "can't convert Fixnum into String" for "replace" (#173), [jsw0528]
149
+
150
+ ## 2.5.3 / 2013-10-09
151
+
152
+ * #232, #234, #237: Fix map filter bugs [Florian Weingarten]
153
+
154
+ ## 2.5.2 / 2013-09-03 / deleted
155
+
156
+ Yanked from rubygems, as it contained too many changes that broke compatibility. Those changes will be on following major releases.
157
+
158
+ ## 2.5.1 / 2013-07-24
159
+
160
+ * #230: Fix security issue with map filter, Use invoke_drop in map filter [Florian Weingarten]
161
+
162
+ ## 2.5.0 / 2013-03-06
163
+
164
+ * Prevent Object methods from being called on drops
165
+ * Avoid symbol injection from liquid
166
+ * Added break and continue statements
167
+ * Fix filter parser for args without space separators
168
+ * Add support for filter keyword arguments
169
+
170
+
171
+ ## 2.4.0 / 2012-08-03
172
+
173
+ * Performance improvements
174
+ * Allow filters in `assign`
175
+ * Add `modulo` filter
176
+ * Ruby 1.8, 1.9, and Rubinius compatibility fixes
177
+ * Add support for `quoted['references']` in `tablerow`
178
+ * Add support for Enumerable to `tablerow`
179
+ * `strip_html` filter removes html comments
180
+
181
+
182
+ ## 2.3.0 / 2011-10-16
183
+
184
+ * Several speed/memory improvements
185
+ * Numerous bug fixes
186
+ * Added support for MRI 1.9, Rubinius, and JRuby
187
+ * Added support for integer drop parameters
188
+ * Added epoch support to `date` filter
189
+ * New `raw` tag that suppresses parsing
190
+ * Added `else` option to `for` tag
191
+ * New `increment` tag
192
+ * New `split` filter
193
+
194
+
195
+ ## 2.2.1 / 2010-08-23
196
+
197
+ * Added support for literal tags
198
+
199
+
200
+ ## 2.2.0 / 2010-08-22
201
+
202
+ * Compatible with Ruby 1.8.7, 1.9.1 and 1.9.2-p0
203
+ * Merged some changed made by the community
204
+
205
+
206
+ ## 1.9.0 / 2008-03-04
207
+
208
+ * Fixed gem install rake task
209
+ * Improve Error encapsulation in liquid by maintaining a own set of exceptions instead of relying on ruby build ins
210
+
211
+
212
+ ## Before 1.9.0
213
+
214
+ * Added If with or / and expressions
215
+ * Implemented .to_liquid for all objects which can be passed to liquid like Strings Arrays Hashes Numerics and Booleans. To export new objects to liquid just implement .to_liquid on them and return objects which themselves have .to_liquid methods.
216
+ * Added more tags to standard library
217
+ * Added include tag ( like partials in rails )
218
+ * [...] Gazillion of detail improvements
219
+ * Added strainers as filter hosts for better security [Tobias Luetke]
220
+ * Fixed that rails integration would call filter with the wrong "self" [Michael Geary]
221
+ * Fixed bad error reporting when a filter called a method which doesn't exist. Liquid told you that it couldn't find the filter which was obviously misleading [Tobias Luetke]
222
+ * Removed count helper from standard lib. use size [Tobias Luetke]
223
+ * Fixed bug with string filter parameters failing to tolerate commas in strings. [Paul Hammond]
224
+ * Improved filter parameters. Filter parameters are now context sensitive; Types are resolved according to the rules of the context. Multiple parameters are now separated by the Liquid::ArgumentSeparator: , by default [Paul Hammond]
225
+ {{ 'Typo' | link_to: 'http://typo.leetsoft.com', 'Typo - a modern weblog engine' }}
226
+ * Added Liquid::Drop. A base class which you can use for exporting proxy objects to liquid which can acquire more data when used in liquid. [Tobias Luetke]
227
+
228
+ class ProductDrop < Liquid::Drop
229
+ def top_sales
230
+ Shop.current.products.find(:all, :order => 'sales', :limit => 10 )
231
+ end
232
+ end
233
+ t = Liquid::Template.parse( ' {% for product in product.top_sales %} {{ product.name }} {% endfor %} ' )
234
+ t.render('product' => ProductDrop.new )
235
+ * Added filter parameters support. Example: {{ date | format_date: "%Y" }} [Paul Hammond]
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2005, 2006 Tobias Luetke
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,108 @@
1
+ [![Build Status](https://api.travis-ci.org/Shopify/liquid.svg?branch=master)](http://travis-ci.org/Shopify/liquid)
2
+ [![Inline docs](http://inch-ci.org/github/Shopify/liquid.svg?branch=master)](http://inch-ci.org/github/Shopify/liquid)
3
+
4
+ # Liquid template engine
5
+
6
+ * [Contributing guidelines](CONTRIBUTING.md)
7
+ * [Version history](History.md)
8
+ * [Liquid documentation from Shopify](http://docs.shopify.com/themes/liquid-basics)
9
+ * [Liquid Wiki at GitHub](https://github.com/Shopify/liquid/wiki)
10
+ * [Website](http://liquidmarkup.org/)
11
+
12
+ ## Introduction
13
+
14
+ Liquid is a template engine which was written with very specific requirements:
15
+
16
+ * It has to have beautiful and simple markup. Template engines which don't produce good looking markup are no fun to use.
17
+ * It needs to be non evaling and secure. Liquid templates are made so that users can edit them. You don't want to run code on your server which your users wrote.
18
+ * It has to be stateless. Compile and render steps have to be separate so that the expensive parsing and compiling can be done once and later on you can just render it passing in a hash with local variables and objects.
19
+
20
+ ## Why you should use Liquid
21
+
22
+ * You want to allow your users to edit the appearance of your application but don't want them to run **insecure code on your server**.
23
+ * You want to render templates directly from the database.
24
+ * You like smarty (PHP) style template engines.
25
+ * You need a template engine which does HTML just as well as emails.
26
+ * You don't like the markup of your current templating engine.
27
+
28
+ ## What does it look like?
29
+
30
+ ```html
31
+ <ul id="products">
32
+ {% for product in products %}
33
+ <li>
34
+ <h2>{{ product.name }}</h2>
35
+ Only {{ product.price | price }}
36
+
37
+ {{ product.description | prettyprint | paragraph }}
38
+ </li>
39
+ {% endfor %}
40
+ </ul>
41
+ ```
42
+
43
+ ## How to use Liquid
44
+
45
+ Install Liquid by adding `gem 'liquid'` to your gemfile.
46
+
47
+ Liquid supports a very simple API based around the Liquid::Template class.
48
+ For standard use you can just pass it the content of a file and call render with a parameters hash.
49
+
50
+ ```ruby
51
+ @template = Liquid::Template.parse("hi {{name}}") # Parses and compiles the template
52
+ @template.render('name' => 'tobi') # => "hi tobi"
53
+ ```
54
+
55
+ ### Error Modes
56
+
57
+ Setting the error mode of Liquid lets you specify how strictly you want your templates to be interpreted.
58
+ Normally the parser is very lax and will accept almost anything without error. Unfortunately this can make
59
+ it very hard to debug and can lead to unexpected behaviour.
60
+
61
+ Liquid also comes with a stricter parser that can be used when editing templates to give better error messages
62
+ when templates are invalid. You can enable this new parser like this:
63
+
64
+ ```ruby
65
+ Liquid::Template.error_mode = :strict # Raises a SyntaxError when invalid syntax is used
66
+ Liquid::Template.error_mode = :warn # Adds errors to template.errors but continues as normal
67
+ Liquid::Template.error_mode = :lax # The default mode, accepts almost anything.
68
+ ```
69
+
70
+ If you want to set the error mode only on specific templates you can pass `:error_mode` as an option to `parse`:
71
+ ```ruby
72
+ Liquid::Template.parse(source, :error_mode => :strict)
73
+ ```
74
+ This is useful for doing things like enabling strict mode only in the theme editor.
75
+
76
+ It is recommended that you enable `:strict` or `:warn` mode on new apps to stop invalid templates from being created.
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
+ ```
@@ -0,0 +1,80 @@
1
+ # Copyright (c) 2005 Tobias Luetke
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ module Liquid
23
+ FilterSeparator = /\|/
24
+ ArgumentSeparator = ','.freeze
25
+ FilterArgumentSeparator = ':'.freeze
26
+ VariableAttributeSeparator = '.'.freeze
27
+ WhitespaceControl = '-'.freeze
28
+ TagStart = /\{\%/
29
+ TagEnd = /\%\}/
30
+ VariableSignature = /\(?[\w\-\.\[\]]\)?/
31
+ VariableSegment = /[\w\-]/
32
+ VariableStart = /\{\{/
33
+ VariableEnd = /\}\}/
34
+ VariableIncompleteEnd = /\}\}?/
35
+ QuotedString = /"[^"]*"|'[^']*'/
36
+ QuotedFragment = /#{QuotedString}|(?:[^\s,\|'"]|#{QuotedString})+/o
37
+ TagAttributes = /(\w+)\s*\:\s*(#{QuotedFragment})/o
38
+ AnyStartingTag = /#{TagStart}|#{VariableStart}/o
39
+ PartialTemplateParser = /#{TagStart}.*?#{TagEnd}|#{VariableStart}.*?#{VariableIncompleteEnd}/om
40
+ TemplateParser = /(#{PartialTemplateParser}|#{AnyStartingTag})/om
41
+ VariableParser = /\[[^\]]+\]|#{VariableSegment}+\??/o
42
+
43
+ singleton_class.send(:attr_accessor, :cache_classes)
44
+ self.cache_classes = true
45
+ end
46
+
47
+ require "liquid/version"
48
+ require 'liquid/parse_tree_visitor'
49
+ require 'liquid/lexer'
50
+ require 'liquid/parser'
51
+ require 'liquid/i18n'
52
+ require 'liquid/drop'
53
+ require 'liquid/tablerowloop_drop'
54
+ require 'liquid/forloop_drop'
55
+ require 'liquid/extensions'
56
+ require 'liquid/errors'
57
+ require 'liquid/interrupts'
58
+ require 'liquid/strainer'
59
+ require 'liquid/expression'
60
+ require 'liquid/context'
61
+ require 'liquid/parser_switching'
62
+ require 'liquid/tag'
63
+ require 'liquid/block'
64
+ require 'liquid/block_body'
65
+ require 'liquid/document'
66
+ require 'liquid/variable'
67
+ require 'liquid/variable_lookup'
68
+ require 'liquid/range_lookup'
69
+ require 'liquid/file_system'
70
+ require 'liquid/resource_limits'
71
+ require 'liquid/template'
72
+ require 'liquid/standardfilters'
73
+ require 'liquid/condition'
74
+ require 'liquid/utils'
75
+ require 'liquid/tokenizer'
76
+ require 'liquid/parse_context'
77
+
78
+ # Load all the tags of the standard library
79
+ #
80
+ Dir["#{__dir__}/liquid/tags/*.rb"].each { |f| require f }