liquid 3.0.6 → 4.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +89 -58
  3. data/{MIT-LICENSE → LICENSE} +0 -0
  4. data/lib/liquid.rb +7 -6
  5. data/lib/liquid/block.rb +31 -124
  6. data/lib/liquid/block_body.rb +54 -57
  7. data/lib/liquid/condition.rb +23 -22
  8. data/lib/liquid/context.rb +50 -42
  9. data/lib/liquid/document.rb +19 -9
  10. data/lib/liquid/drop.rb +12 -13
  11. data/lib/liquid/errors.rb +16 -17
  12. data/lib/liquid/expression.rb +15 -3
  13. data/lib/liquid/extensions.rb +7 -7
  14. data/lib/liquid/file_system.rb +3 -3
  15. data/lib/liquid/forloop_drop.rb +42 -0
  16. data/lib/liquid/i18n.rb +5 -5
  17. data/lib/liquid/interrupts.rb +1 -2
  18. data/lib/liquid/lexer.rb +6 -4
  19. data/lib/liquid/locales/en.yml +3 -1
  20. data/lib/liquid/parse_context.rb +37 -0
  21. data/lib/liquid/parser_switching.rb +4 -4
  22. data/lib/liquid/profiler.rb +18 -19
  23. data/lib/liquid/profiler/hooks.rb +7 -7
  24. data/lib/liquid/range_lookup.rb +16 -1
  25. data/lib/liquid/resource_limits.rb +23 -0
  26. data/lib/liquid/standardfilters.rb +101 -56
  27. data/lib/liquid/strainer.rb +4 -5
  28. data/lib/liquid/tablerowloop_drop.rb +62 -0
  29. data/lib/liquid/tag.rb +9 -8
  30. data/lib/liquid/tags/assign.rb +5 -4
  31. data/lib/liquid/tags/break.rb +0 -3
  32. data/lib/liquid/tags/capture.rb +1 -1
  33. data/lib/liquid/tags/case.rb +19 -12
  34. data/lib/liquid/tags/comment.rb +2 -2
  35. data/lib/liquid/tags/cycle.rb +6 -6
  36. data/lib/liquid/tags/decrement.rb +1 -4
  37. data/lib/liquid/tags/for.rb +93 -75
  38. data/lib/liquid/tags/if.rb +49 -44
  39. data/lib/liquid/tags/ifchanged.rb +0 -2
  40. data/lib/liquid/tags/include.rb +60 -52
  41. data/lib/liquid/tags/raw.rb +26 -4
  42. data/lib/liquid/tags/table_row.rb +12 -30
  43. data/lib/liquid/tags/unless.rb +3 -4
  44. data/lib/liquid/template.rb +23 -50
  45. data/lib/liquid/tokenizer.rb +31 -0
  46. data/lib/liquid/utils.rb +48 -8
  47. data/lib/liquid/variable.rb +46 -45
  48. data/lib/liquid/variable_lookup.rb +3 -3
  49. data/lib/liquid/version.rb +1 -1
  50. data/test/integration/assign_test.rb +8 -8
  51. data/test/integration/blank_test.rb +14 -14
  52. data/test/integration/context_test.rb +2 -2
  53. data/test/integration/document_test.rb +19 -0
  54. data/test/integration/drop_test.rb +42 -40
  55. data/test/integration/error_handling_test.rb +64 -45
  56. data/test/integration/filter_test.rb +60 -20
  57. data/test/integration/output_test.rb +26 -27
  58. data/test/integration/parsing_quirks_test.rb +15 -13
  59. data/test/integration/render_profiling_test.rb +20 -20
  60. data/test/integration/security_test.rb +5 -7
  61. data/test/integration/standard_filter_test.rb +119 -37
  62. data/test/integration/tags/break_tag_test.rb +1 -2
  63. data/test/integration/tags/continue_tag_test.rb +0 -1
  64. data/test/integration/tags/for_tag_test.rb +133 -98
  65. data/test/integration/tags/if_else_tag_test.rb +75 -77
  66. data/test/integration/tags/include_tag_test.rb +23 -30
  67. data/test/integration/tags/increment_tag_test.rb +10 -11
  68. data/test/integration/tags/raw_tag_test.rb +7 -1
  69. data/test/integration/tags/standard_tag_test.rb +121 -122
  70. data/test/integration/tags/statements_test.rb +3 -5
  71. data/test/integration/tags/table_row_test.rb +20 -19
  72. data/test/integration/tags/unless_else_tag_test.rb +6 -6
  73. data/test/integration/template_test.rb +91 -45
  74. data/test/integration/variable_test.rb +23 -13
  75. data/test/test_helper.rb +33 -5
  76. data/test/unit/block_unit_test.rb +6 -5
  77. data/test/unit/condition_unit_test.rb +82 -77
  78. data/test/unit/context_unit_test.rb +48 -57
  79. data/test/unit/file_system_unit_test.rb +3 -3
  80. data/test/unit/i18n_unit_test.rb +2 -2
  81. data/test/unit/lexer_unit_test.rb +11 -8
  82. data/test/unit/parser_unit_test.rb +2 -2
  83. data/test/unit/regexp_unit_test.rb +1 -1
  84. data/test/unit/strainer_unit_test.rb +13 -2
  85. data/test/unit/tag_unit_test.rb +7 -2
  86. data/test/unit/tags/case_tag_unit_test.rb +1 -1
  87. data/test/unit/tags/for_tag_unit_test.rb +2 -2
  88. data/test/unit/tags/if_tag_unit_test.rb +1 -1
  89. data/test/unit/template_unit_test.rb +6 -5
  90. data/test/unit/tokenizer_unit_test.rb +24 -7
  91. data/test/unit/variable_unit_test.rb +60 -43
  92. metadata +44 -41
  93. data/lib/liquid/module_ex.rb +0 -62
  94. data/lib/liquid/token.rb +0 -18
  95. data/test/unit/module_ex_unit_test.rb +0 -87
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d261e9933d148ea6cd126089810b2ab38c510d84
4
- data.tar.gz: bab6c47dafec91fb743720a77430e4c662108482
3
+ metadata.gz: 8cb85d26c5a294b870e0624188f36b3a7e8c8ba7
4
+ data.tar.gz: 1eea59fdf71a08c68a61dc240bf6655e244c7777
5
5
  SHA512:
6
- metadata.gz: 2d6e8d2d67a425d95afe16df6e99322fde8792ad51019a94c39d0169c98def33aa862845ffcaef1ec660d0f524985692c23335865d82d5ea6703caa10427c9d8
7
- data.tar.gz: 0b66d763cd81d42c3cf38adad9693df294eb356f880a920c109f504cf827c48729df1bdb9c22104386776dd9140101dfa1db5f9b0d9b0691620f81937cdcc01b
6
+ metadata.gz: ce2003217fb7c25700c641d5af17b6b41e5247f062dba6ae34869abde88d169fd1407b210ce00f03465742a105294e202b97b98698a95a2992cdeaad66cd8429
7
+ data.tar.gz: 9ff0d24f24b9c9411ddfa3b74577e6945dfc2b69f01508c9da6d409e82bc20629f0448110b3ee4e2f35c3e4c307c0c1e75e656659f3c78bb8fdbfd2b168a9831
data/History.md CHANGED
@@ -1,4 +1,35 @@
1
- # Liquid Version History
1
+ # Liquid Change Log
2
+
3
+ ## 4.0.0 / not yet released / branch "master"
4
+
5
+ ### Changed
6
+ * Add url_decode filter to invert url_encode (#645) [Larry Archer]
7
+ * Add global_filter to apply a filter to all output (#610) [Loren Hale]
8
+ * Add compact filter (#600) [Carson Reinke]
9
+ * Rename deprecated "has_key?" and "has_interrupt?" methods (#593) [Florian Weingarten]
10
+ * Include template name with line numbers in render errors (574) [Dylan Thacker-Smith]
11
+ * Add sort_natural filter (#554) [Martin Hanzel]
12
+ * Add forloop.parentloop as a reference to the parent loop (#520) [Justin Li]
13
+ * Block parsing moved to BlockBody class (#458) [Dylan Thacker-Smith]
14
+ * Add concat filter to concatenate arrays (#429) [Diogo Beato]
15
+ * Ruby 1.9 support dropped (#491) [Justin Li]
16
+ * Liquid::Template.file_system's read_template_file method is no longer passed the context. (#441) [James Reid-Smith]
17
+ * Remove support for `liquid_methods`
18
+ * Rename Drop method `before_method` as `liquid_method_missing` (#661) [Thierry Joyal]
19
+
20
+ ### Fixed
21
+ * Fix sort filter behaviour with empty array input (#652) [Marcel Cary]
22
+ * Fix test failure under certain timezones (#631) [Dylan Thacker-Smith]
23
+ * Fix bug in uniq filter (#595) [Florian Weingarten]
24
+ * Fix bug when "blank" and "empty" are used as variable names (#592) [Florian Weingarten]
25
+ * Fix condition parse order in strict mode (#569) [Justin Li]
26
+ * Fix naming of the "context variable" when dynamically including a template (#559) [Justin Li]
27
+ * Gracefully accept empty strings in the date filter (#555) [Loren Hale]
28
+ * Fix capturing into variables with a hyphen in the name (#505) [Florian Weingarten]
29
+ * Fix case sensitivity regression in date standard filter (#499) [Kelley Reynolds]
30
+ * Disallow filters with no variable in strict mode (#475) [Justin Li]
31
+ * Disallow variable names in the strict parser that are not valid in the lax parser (#463) [Justin Li]
32
+ * Fix BlockBody#warnings taking exponential time to compute (#486) [Justin Li]
2
33
 
3
34
  ## 3.0.5 / 2015-07-23 / branch "3-0-stable"
4
35
 
@@ -10,11 +41,11 @@
10
41
 
11
42
  ## 3.0.3 / 2015-05-28
12
43
 
13
- * Fix condition parse order in strict mode (#569) [Justin Li, pushrax]
44
+ * Fix condition parse order in strict mode (#569) [Justin Li]
14
45
 
15
46
  ## 3.0.2 / 2015-04-24
16
47
 
17
- * Expose VariableLookup private members (#551) [Justin Li, pushrax]
48
+ * Expose VariableLookup private members (#551) [Justin Li]
18
49
  * Documentation fixes
19
50
 
20
51
  ## 3.0.1 / 2015-01-23
@@ -23,38 +54,38 @@
23
54
 
24
55
  ## 3.0.0 / 2014-11-12
25
56
 
26
- * Removed Block#end_tag. Instead, override parse with `super` followed by your code. See #446 [Dylan Thacker-Smith, dylanahsmith]
27
- * Fixed condition with wrong data types, see #423 [Bogdan Gusiev]
28
- * Add url_encode to standard filters, see #421 [Derrick Reimer, djreimer]
29
- * Add uniq to standard filters [Florian Weingarten, fw42]
30
- * Add exception_handler feature, see #397 and #254 [Bogdan Gusiev, bogdan and Florian Weingarten, fw42]
31
- * Optimize variable parsing to avoid repeated regex evaluation during template rendering #383 [Jason Hiltz-Laforge, jasonhl]
32
- * Optimize checking for block interrupts to reduce object allocation #380 [Jason Hiltz-Laforge, jasonhl]
33
- * Properly set context rethrow_errors on render! #349 [Thierry Joyal, tjoyal]
34
- * Fix broken rendering of variables which are equal to false, see #345 [Florian Weingarten, fw42]
35
- * Remove ActionView template handler [Dylan Thacker-Smith, dylanahsmith]
36
- * Freeze lots of string literals for new Ruby 2.1 optimization, see #297 [Florian Weingarten, fw42]
37
- * Allow newlines in tags and variables, see #324 [Dylan Thacker-Smith, dylanahsmith]
38
- * Tag#parse is called after initialize, which now takes options instead of tokens as the 3rd argument. See #321 [Dylan Thacker-Smith, dylanahsmith]
39
- * Raise `Liquid::ArgumentError` instead of `::ArgumentError` when filter has wrong number of arguments #309 [Bogdan Gusiev, bogdan]
40
- * Add a to_s default for liquid drops, see #306 [Adam Doeler, releod]
41
- * Add strip, lstrip, and rstrip to standard filters [Florian Weingarten, fw42]
42
- * Make if, for & case tags return complete and consistent nodelists, see #250 [Nick Jones, dntj]
43
- * Prevent arbitrary method invocation on condition objects, see #274 [Dylan Thacker-Smith, dylanahsmith]
44
- * Don't call to_sym when creating conditions for security reasons, see #273 [Bouke van der Bijl, bouk]
45
- * Fix resource counting bug with respond_to?(:length), see #263 [Florian Weingarten, fw42]
46
- * Allow specifying custom patterns for template filenames, see #284 [Andrei Gladkyi, agladkyi]
47
- * Allow drops to optimize loading a slice of elements, see #282 [Tom Burns, boourns]
48
- * Support for passing variables to snippets in subdirs, see #271 [Joost Hietbrink, joost]
49
- * Add a class cache to avoid runtime extend calls, see #249 [James Tucker, raggi]
50
- * Remove some legacy Ruby 1.8 compatibility code, see #276 [Florian Weingarten, fw42]
51
- * Add default filter to standard filters, see #267 [Derrick Reimer, djreimer]
52
- * Add optional strict parsing and warn parsing, see #235 [Tristan Hume, trishume]
53
- * Add I18n syntax error translation, see #241 [Simon Hørup Eskildsen, Sirupsen]
54
- * Make sort filter work on enumerable drops, see #239 [Florian Weingarten, fw42]
55
- * Fix clashing method names in enumerable drops, see #238 [Florian Weingarten, fw42]
56
- * Make map filter work on enumerable drops, see #233 [Florian Weingarten, fw42]
57
- * Improved whitespace stripping for blank blocks, related to #216 [Florian Weingarten, fw42]
57
+ * Removed Block#end_tag. Instead, override parse with `super` followed by your code. See #446 [Dylan Thacker-Smith]
58
+ * Fixed condition with wrong data types (#423) [Bogdan Gusiev]
59
+ * Add url_encode to standard filters (#421) [Derrick Reimer]
60
+ * Add uniq to standard filters [Florian Weingarten]
61
+ * Add exception_handler feature (#397) and #254 [Bogdan Gusiev, Florian Weingarten]
62
+ * Optimize variable parsing to avoid repeated regex evaluation during template rendering #383 [Jason Hiltz-Laforge]
63
+ * Optimize checking for block interrupts to reduce object allocation #380 [Jason Hiltz-Laforge]
64
+ * Properly set context rethrow_errors on render! #349 [Thierry Joyal]
65
+ * Fix broken rendering of variables which are equal to false (#345) [Florian Weingarten]
66
+ * Remove ActionView template handler [Dylan Thacker-Smith]
67
+ * Freeze lots of string literals for new Ruby 2.1 optimization (#297) [Florian Weingarten]
68
+ * Allow newlines in tags and variables (#324) [Dylan Thacker-Smith]
69
+ * Tag#parse is called after initialize, which now takes options instead of tokens as the 3rd argument. See #321 [Dylan Thacker-Smith]
70
+ * Raise `Liquid::ArgumentError` instead of `::ArgumentError` when filter has wrong number of arguments #309 [Bogdan Gusiev]
71
+ * Add a to_s default for liquid drops (#306) [Adam Doeler]
72
+ * Add strip, lstrip, and rstrip to standard filters [Florian Weingarten]
73
+ * Make if, for & case tags return complete and consistent nodelists (#250) [Nick Jones]
74
+ * Prevent arbitrary method invocation on condition objects (#274) [Dylan Thacker-Smith]
75
+ * Don't call to_sym when creating conditions for security reasons (#273) [Bouke van der Bijl]
76
+ * Fix resource counting bug with respond_to?(:length) (#263) [Florian Weingarten]
77
+ * Allow specifying custom patterns for template filenames (#284) [Andrei Gladkyi]
78
+ * Allow drops to optimize loading a slice of elements (#282) [Tom Burns]
79
+ * Support for passing variables to snippets in subdirs (#271) [Joost Hietbrink]
80
+ * Add a class cache to avoid runtime extend calls (#249) [James Tucker]
81
+ * Remove some legacy Ruby 1.8 compatibility code (#276) [Florian Weingarten]
82
+ * Add default filter to standard filters (#267) [Derrick Reimer]
83
+ * Add optional strict parsing and warn parsing (#235) [Tristan Hume]
84
+ * Add I18n syntax error translation (#241) [Simon Hørup Eskildsen, Sirupsen]
85
+ * Make sort filter work on enumerable drops (#239) [Florian Weingarten]
86
+ * Fix clashing method names in enumerable drops (#238) [Florian Weingarten]
87
+ * Make map filter work on enumerable drops (#233) [Florian Weingarten]
88
+ * Improved whitespace stripping for blank blocks, related to #216 [Florian Weingarten]
58
89
 
59
90
  ## 2.6.3 / 2015-07-23 / branch "2-6-stable"
60
91
 
@@ -67,8 +98,8 @@
67
98
  ## 2.6.1 / 2014-01-10
68
99
 
69
100
  Security fix, cherry-picked from master (4e14a65):
70
- * Don't call to_sym when creating conditions for security reasons, see #273 [Bouke van der Bijl, bouk]
71
- * Prevent arbitrary method invocation on condition objects, see #274 [Dylan Thacker-Smith, dylanahsmith]
101
+ * Don't call to_sym when creating conditions for security reasons (#273) [Bouke van der Bijl]
102
+ * Prevent arbitrary method invocation on condition objects (#274) [Dylan Thacker-Smith]
72
103
 
73
104
  ## 2.6.0 / 2013-11-25
74
105
 
@@ -76,37 +107,37 @@ IMPORTANT: Liquid 2.6 is going to be the last version of Liquid which maintains
76
107
  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
108
 
78
109
  * Bugfix for #106: fix example servlet [gnowoel]
79
- * Bugfix for #97: strip_html filter supports multi-line tags [Jo Liss, joliss]
80
- * Bugfix for #114: strip_html filter supports style tags [James Allardice, jamesallardice]
81
- * Bugfix for #117: 'now' support for date filter in Ruby 1.9 [Notre Dame Webgroup, ndwebgroup]
82
- * Bugfix for #166: truncate filter on UTF-8 strings with Ruby 1.8 [Florian Weingarten, fw42]
83
- * Bugfix for #204: 'raw' parsing bug [Florian Weingarten, fw42]
84
- * Bugfix for #150: 'for' parsing bug [Peter Schröder, phoet]
85
- * Bugfix for #126: Strip CRLF in strip_newline [Peter Schröder, phoet]
86
- * Bugfix for #174, "can't convert Fixnum into String" for "replace" [wǒ_is神仙, jsw0528]
87
- * Allow a Liquid::Drop to be passed into Template#render [Daniel Huckstep, darkhelmet]
88
- * Resource limits [Florian Weingarten, fw42]
89
- * Add reverse filter [Jay Strybis, unreal]
110
+ * Bugfix for #97: strip_html filter supports multi-line tags [Jo Liss]
111
+ * Bugfix for #114: strip_html filter supports style tags [James Allardice]
112
+ * Bugfix for #117: 'now' support for date filter in Ruby 1.9 [Notre Dame Webgroup]
113
+ * Bugfix for #166: truncate filter on UTF-8 strings with Ruby 1.8 [Florian Weingarten]
114
+ * Bugfix for #204: 'raw' parsing bug [Florian Weingarten]
115
+ * Bugfix for #150: 'for' parsing bug [Peter Schröder]
116
+ * Bugfix for #126: Strip CRLF in strip_newline [Peter Schröder]
117
+ * Bugfix for #174, "can't convert Fixnum into String" for "replace" [jsw0528]
118
+ * Allow a Liquid::Drop to be passed into Template#render [Daniel Huckstep]
119
+ * Resource limits [Florian Weingarten]
120
+ * Add reverse filter [Jay Strybis]
90
121
  * Add utf-8 support
91
- * Use array instead of Hash to keep the registered filters [Tasos Stathopoulos, astathopoulos]
92
- * Cache tokenized partial templates [Tom Burns, boourns]
93
- * Avoid warnings in Ruby 1.9.3 [Marcus Stollsteimer, stomar]
94
- * Better documentation for 'include' tag (closes #163) [Peter Schröder, phoet]
95
- * Use of BigDecimal on filters to have better precision (closes #155) [Arthur Nogueira Neves, arthurnn]
122
+ * Use array instead of Hash to keep the registered filters [Tasos Stathopoulos]
123
+ * Cache tokenized partial templates [Tom Burns]
124
+ * Avoid warnings in Ruby 1.9.3 [Marcus Stollsteimer]
125
+ * Better documentation for 'include' tag (closes #163) [Peter Schröder]
126
+ * Use of BigDecimal on filters to have better precision (closes #155) [Arthur Nogueira Neves]
96
127
 
97
128
  ## 2.5.5 / 2014-01-10 / branch "2-5-stable"
98
129
 
99
130
  Security fix, cherry-picked from master (4e14a65):
100
- * Don't call to_sym when creating conditions for security reasons, see #273 [Bouke van der Bijl, bouk]
101
- * Prevent arbitrary method invocation on condition objects, see #274 [Dylan Thacker-Smith, dylanahsmith]
131
+ * Don't call to_sym when creating conditions for security reasons (#273) [Bouke van der Bijl]
132
+ * Prevent arbitrary method invocation on condition objects (#274) [Dylan Thacker-Smith]
102
133
 
103
134
  ## 2.5.4 / 2013-11-11
104
135
 
105
- * Fix "can't convert Fixnum into String" for "replace", see #173, [wǒ_is神仙, jsw0528]
136
+ * Fix "can't convert Fixnum into String" for "replace" (#173), [jsw0528]
106
137
 
107
138
  ## 2.5.3 / 2013-10-09
108
139
 
109
- * #232, #234, #237: Fix map filter bugs [Florian Weingarten, fw42]
140
+ * #232, #234, #237: Fix map filter bugs [Florian Weingarten]
110
141
 
111
142
  ## 2.5.2 / 2013-09-03 / deleted
112
143
 
@@ -114,7 +145,7 @@ Yanked from rubygems, as it contained too many changes that broke compatibility.
114
145
 
115
146
  ## 2.5.1 / 2013-07-24
116
147
 
117
- * #230: Fix security issue with map filter, Use invoke_drop in map filter [Florian Weingarten, fw42]
148
+ * #230: Fix security issue with map filter, Use invoke_drop in map filter [Florian Weingarten]
118
149
 
119
150
  ## 2.5.0 / 2013-03-06
120
151
 
File without changes
@@ -48,6 +48,8 @@ require 'liquid/lexer'
48
48
  require 'liquid/parser'
49
49
  require 'liquid/i18n'
50
50
  require 'liquid/drop'
51
+ require 'liquid/tablerowloop_drop'
52
+ require 'liquid/forloop_drop'
51
53
  require 'liquid/extensions'
52
54
  require 'liquid/errors'
53
55
  require 'liquid/interrupts'
@@ -57,21 +59,20 @@ require 'liquid/context'
57
59
  require 'liquid/parser_switching'
58
60
  require 'liquid/tag'
59
61
  require 'liquid/block'
62
+ require 'liquid/block_body'
60
63
  require 'liquid/document'
61
64
  require 'liquid/variable'
62
65
  require 'liquid/variable_lookup'
63
66
  require 'liquid/range_lookup'
64
67
  require 'liquid/file_system'
68
+ require 'liquid/resource_limits'
65
69
  require 'liquid/template'
66
70
  require 'liquid/standardfilters'
67
71
  require 'liquid/condition'
68
- require 'liquid/module_ex'
69
72
  require 'liquid/utils'
70
- require 'liquid/token'
73
+ require 'liquid/tokenizer'
74
+ require 'liquid/parse_context'
71
75
 
72
76
  # Load all the tags of the standard library
73
77
  #
74
- Dir[File.dirname(__FILE__) + '/liquid/tags/*.rb'].each { |f| require f }
75
-
76
- require 'liquid/profiler'
77
- require 'liquid/profiler/hooks'
78
+ Dir["#{__dir__}/liquid/tags/*.rb"].each { |f| require f }
@@ -1,90 +1,39 @@
1
1
  module Liquid
2
2
  class Block < Tag
3
- FullToken = /\A#{TagStart}\s*(\w+)\s*(.*)?#{TagEnd}\z/om
4
- ContentOfVariable = /\A#{VariableStart}(.*)#{VariableEnd}\z/om
5
- TAGSTART = "{%".freeze
6
- VARSTART = "{{".freeze
7
-
8
- def blank?
9
- @blank
3
+ def initialize(tag_name, markup, options)
4
+ super
5
+ @blank = true
10
6
  end
11
7
 
12
8
  def parse(tokens)
13
- @blank = true
14
- @nodelist ||= []
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
9
+ @body = BlockBody.new
10
+ while parse_body(@body, tokens)
57
11
  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
12
  end
64
13
 
65
- # warnings of this block and all sub-tags
66
- def warnings
67
- all_warnings = []
68
- all_warnings.concat(@warnings) if @warnings
14
+ def render(context)
15
+ @body.render(context)
16
+ end
69
17
 
70
- (nodelist || []).each do |node|
71
- all_warnings.concat(node.warnings || []) if node.respond_to?(:warnings)
72
- end
18
+ def blank?
19
+ @blank
20
+ end
73
21
 
74
- all_warnings
22
+ def nodelist
23
+ @body.nodelist
75
24
  end
76
25
 
77
- def unknown_tag(tag, params, tokens)
26
+ def unknown_tag(tag, _params, _tokens)
78
27
  case tag
79
28
  when 'else'.freeze
80
- raise SyntaxError.new(options[:locale].t("errors.syntax.unexpected_else".freeze,
81
- :block_name => block_name))
29
+ raise SyntaxError.new(parse_context.locale.t("errors.syntax.unexpected_else".freeze,
30
+ block_name: block_name))
82
31
  when 'end'.freeze
83
- raise SyntaxError.new(options[:locale].t("errors.syntax.invalid_delimiter".freeze,
84
- :block_name => block_name,
85
- :block_delimiter => block_delimiter))
32
+ raise SyntaxError.new(parse_context.locale.t("errors.syntax.invalid_delimiter".freeze,
33
+ block_name: block_name,
34
+ block_delimiter: block_delimiter))
86
35
  else
87
- raise SyntaxError.new(options[:locale].t("errors.syntax.unknown_tag".freeze, :tag => tag))
36
+ raise SyntaxError.new(parse_context.locale.t("errors.syntax.unknown_tag".freeze, tag: tag))
88
37
  end
89
38
  end
90
39
 
@@ -96,65 +45,23 @@ module Liquid
96
45
  @block_delimiter ||= "end#{block_name}"
97
46
  end
98
47
 
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
48
  protected
112
49
 
113
- def assert_missing_delimitation!
114
- raise SyntaxError.new(options[:locale].t("errors.syntax.tag_never_closed".freeze, :block_name => block_name))
115
- end
116
-
117
- def render_all(list, context)
118
- output = []
119
- context.resource_limits[:render_length_current] = 0
120
- context.resource_limits[:render_score_current] += list.length
50
+ def parse_body(body, tokens)
51
+ body.parse(tokens, parse_context) do |end_tag_name, end_tag_params|
52
+ @blank &&= body.blank?
121
53
 
122
- list.each do |token|
123
- # Break out if we have any unhanded interrupts.
124
- break if context.has_interrupt?
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
133
- end
134
-
135
- token_output = render_token(token, context)
136
-
137
- unless token.is_a?(Block) && token.blank?
138
- output << token_output
139
- end
140
- rescue MemoryError => e
141
- raise e
142
- rescue ::StandardError => e
143
- output << (context.handle_error(e, token))
54
+ return false if end_tag_name == block_delimiter
55
+ unless end_tag_name
56
+ raise SyntaxError.new(parse_context.locale.t("errors.syntax.tag_never_closed".freeze, block_name: block_name))
144
57
  end
145
- end
146
58
 
147
- output.join
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)
59
+ # this tag is not registered with the system
60
+ # pass it to the current block for special handling or error reporting
61
+ unknown_tag(end_tag_name, end_tag_params, tokens)
156
62
  end
157
- token_output
63
+
64
+ true
158
65
  end
159
66
  end
160
67
  end
@@ -12,44 +12,37 @@ module Liquid
12
12
  @blank = true
13
13
  end
14
14
 
15
- def parse(tokens, options)
16
- while token = tokens.shift
17
- begin
18
- unless token.empty?
19
- case
20
- when token.start_with?(TAGSTART)
21
- if token =~ FullToken
22
- tag_name = $1
23
- markup = $2
24
- # fetch the tag from registered blocks
25
- if tag = Template.tags[tag_name]
26
- markup = token.child(markup) if token.is_a?(Token)
27
- new_tag = tag.parse(tag_name, markup, tokens, options)
28
- new_tag.line_number = token.line_number if token.is_a?(Token)
29
- @blank &&= new_tag.blank?
30
- @nodelist << new_tag
31
- else
32
- # end parsing if we reach an unknown tag and let the caller decide
33
- # determine how to proceed
34
- return yield tag_name, markup
35
- end
15
+ def parse(tokenizer, parse_context)
16
+ parse_context.line_number = tokenizer.line_number
17
+ while token = tokenizer.shift
18
+ unless token.empty?
19
+ case
20
+ when token.start_with?(TAGSTART)
21
+ if token =~ FullToken
22
+ tag_name = $1
23
+ markup = $2
24
+ # fetch the tag from registered blocks
25
+ if tag = registered_tags[tag_name]
26
+ new_tag = tag.parse(tag_name, markup, tokenizer, parse_context)
27
+ @blank &&= new_tag.blank?
28
+ @nodelist << new_tag
36
29
  else
37
- raise SyntaxError.new(options[:locale].t("errors.syntax.tag_termination".freeze, :token => token, :tag_end => TagEnd.inspect))
30
+ # end parsing if we reach an unknown tag and let the caller decide
31
+ # determine how to proceed
32
+ return yield tag_name, markup
38
33
  end
39
- when token.start_with?(VARSTART)
40
- new_var = create_variable(token, options)
41
- new_var.line_number = token.line_number if token.is_a?(Token)
42
- @nodelist << new_var
43
- @blank = false
44
34
  else
45
- @nodelist << token
46
- @blank &&= !!(token =~ /\A\s*\z/)
35
+ raise_missing_tag_terminator(token, parse_context)
47
36
  end
37
+ when token.start_with?(VARSTART)
38
+ @nodelist << create_variable(token, parse_context)
39
+ @blank = false
40
+ else
41
+ @nodelist << token
42
+ @blank &&= !!(token =~ /\A\s*\z/)
48
43
  end
49
- rescue SyntaxError => e
50
- e.set_line_number_from_token(token)
51
- raise
52
44
  end
45
+ parse_context.line_number = tokenizer.line_number
53
46
  end
54
47
 
55
48
  yield nil, nil
@@ -59,41 +52,32 @@ module Liquid
59
52
  @blank
60
53
  end
61
54
 
62
- def warnings
63
- all_warnings = []
64
- nodelist.each do |node|
65
- all_warnings.concat(node.warnings) if node.respond_to?(:warnings) && node.warnings
66
- end
67
- all_warnings
68
- end
69
-
70
55
  def render(context)
71
56
  output = []
72
- context.resource_limits[:render_length_current] = 0
73
- context.resource_limits[:render_score_current] += @nodelist.length
57
+ context.resource_limits.render_score += @nodelist.length
74
58
 
75
59
  @nodelist.each do |token|
76
60
  # Break out if we have any unhanded interrupts.
77
- break if context.has_interrupt?
61
+ break if context.interrupt?
78
62
 
79
63
  begin
80
64
  # If we get an Interrupt that means the block must stop processing. An
81
65
  # Interrupt is any command that stops block execution such as {% break %}
82
66
  # or {% continue %}
83
- if token.is_a?(Continue) or token.is_a?(Break)
67
+ if token.is_a?(Continue) || token.is_a?(Break)
84
68
  context.push_interrupt(token.interrupt)
85
69
  break
86
70
  end
87
71
 
88
- token_output = render_token(token, context)
72
+ node_output = render_node(token, context)
89
73
 
90
74
  unless token.is_a?(Block) && token.blank?
91
- output << token_output
75
+ output << node_output
92
76
  end
93
77
  rescue MemoryError => e
94
78
  raise e
95
79
  rescue ::StandardError => e
96
- output << context.handle_error(e, token)
80
+ output << context.handle_error(e, token.line_number)
97
81
  end
98
82
  end
99
83
 
@@ -102,22 +86,35 @@ module Liquid
102
86
 
103
87
  private
104
88
 
105
- def render_token(token, context)
106
- token_output = (token.respond_to?(:render) ? token.render(context) : token)
107
- context.increment_used_resources(:render_length_current, token_output)
108
- if context.resource_limits_reached?
109
- context.resource_limits[:reached] = true
89
+ def render_node(node, context)
90
+ node_output = (node.respond_to?(:render) ? node.render(context) : node)
91
+ node_output = node_output.is_a?(Array) ? node_output.join : node_output.to_s
92
+
93
+ context.resource_limits.render_length += node_output.length
94
+ if context.resource_limits.reached?
110
95
  raise MemoryError.new("Memory limits exceeded".freeze)
111
96
  end
112
- token_output
97
+ node_output
113
98
  end
114
99
 
115
- def create_variable(token, options)
100
+ def create_variable(token, parse_context)
116
101
  token.scan(ContentOfVariable) do |content|
117
- markup = token.is_a?(Token) ? token.child(content.first) : content.first
118
- return Variable.new(markup, options)
102
+ markup = content.first
103
+ return Variable.new(markup, parse_context)
119
104
  end
120
- raise SyntaxError.new(options[:locale].t("errors.syntax.variable_termination".freeze, :token => token, :tag_end => VariableEnd.inspect))
105
+ raise_missing_variable_terminator(token, parse_context)
106
+ end
107
+
108
+ def raise_missing_tag_terminator(token, parse_context)
109
+ raise SyntaxError.new(parse_context.locale.t("errors.syntax.tag_termination".freeze, token: token, tag_end: TagEnd.inspect))
110
+ end
111
+
112
+ def raise_missing_variable_terminator(token, parse_context)
113
+ raise SyntaxError.new(parse_context.locale.t("errors.syntax.variable_termination".freeze, token: token, tag_end: VariableEnd.inspect))
114
+ end
115
+
116
+ def registered_tags
117
+ Template.tags
121
118
  end
122
119
  end
123
120
  end