liquid 2.6.3 → 3.0.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 +4 -4
- data/History.md +46 -13
- data/README.md +27 -2
- data/lib/liquid/block.rb +85 -51
- data/lib/liquid/block_body.rb +123 -0
- data/lib/liquid/condition.rb +26 -15
- data/lib/liquid/context.rb +106 -140
- data/lib/liquid/document.rb +3 -3
- data/lib/liquid/drop.rb +17 -1
- data/lib/liquid/errors.rb +50 -2
- data/lib/liquid/expression.rb +33 -0
- data/lib/liquid/file_system.rb +17 -6
- data/lib/liquid/i18n.rb +39 -0
- data/lib/liquid/interrupts.rb +1 -1
- data/lib/liquid/lexer.rb +51 -0
- data/lib/liquid/locales/en.yml +22 -0
- data/lib/liquid/parser.rb +90 -0
- data/lib/liquid/parser_switching.rb +31 -0
- data/lib/liquid/profiler/hooks.rb +23 -0
- data/lib/liquid/profiler.rb +159 -0
- data/lib/liquid/range_lookup.rb +22 -0
- data/lib/liquid/standardfilters.rb +143 -55
- data/lib/liquid/strainer.rb +14 -4
- data/lib/liquid/tag.rb +25 -9
- data/lib/liquid/tags/assign.rb +12 -9
- data/lib/liquid/tags/break.rb +1 -1
- data/lib/liquid/tags/capture.rb +10 -8
- data/lib/liquid/tags/case.rb +13 -13
- data/lib/liquid/tags/comment.rb +9 -2
- data/lib/liquid/tags/continue.rb +1 -4
- data/lib/liquid/tags/cycle.rb +5 -7
- data/lib/liquid/tags/decrement.rb +3 -4
- data/lib/liquid/tags/for.rb +69 -36
- data/lib/liquid/tags/if.rb +52 -25
- data/lib/liquid/tags/ifchanged.rb +3 -3
- data/lib/liquid/tags/include.rb +19 -8
- data/lib/liquid/tags/increment.rb +4 -8
- data/lib/liquid/tags/raw.rb +4 -7
- data/lib/liquid/tags/table_row.rb +73 -0
- data/lib/liquid/tags/unless.rb +2 -4
- data/lib/liquid/template.rb +124 -14
- data/lib/liquid/token.rb +18 -0
- data/lib/liquid/utils.rb +13 -4
- data/lib/liquid/variable.rb +103 -25
- data/lib/liquid/variable_lookup.rb +78 -0
- data/lib/liquid/version.rb +1 -1
- data/lib/liquid.rb +19 -11
- data/test/fixtures/en_locale.yml +9 -0
- data/test/{liquid → integration}/assign_test.rb +18 -1
- data/test/integration/blank_test.rb +106 -0
- data/test/{liquid → integration}/capture_test.rb +3 -3
- data/test/integration/context_test.rb +32 -0
- data/test/integration/drop_test.rb +271 -0
- data/test/integration/error_handling_test.rb +207 -0
- data/test/{liquid → integration}/filter_test.rb +11 -11
- data/test/integration/hash_ordering_test.rb +23 -0
- data/test/{liquid → integration}/output_test.rb +13 -13
- data/test/integration/parsing_quirks_test.rb +116 -0
- data/test/integration/render_profiling_test.rb +154 -0
- data/test/{liquid → integration}/security_test.rb +10 -10
- data/test/{liquid → integration}/standard_filter_test.rb +148 -32
- data/test/{liquid → integration}/tags/break_tag_test.rb +1 -1
- data/test/{liquid → integration}/tags/continue_tag_test.rb +1 -1
- data/test/{liquid → integration}/tags/for_tag_test.rb +80 -2
- data/test/{liquid → integration}/tags/if_else_tag_test.rb +24 -21
- data/test/integration/tags/include_tag_test.rb +234 -0
- data/test/{liquid → integration}/tags/increment_tag_test.rb +1 -1
- data/test/{liquid → integration}/tags/raw_tag_test.rb +2 -1
- data/test/{liquid → integration}/tags/standard_tag_test.rb +28 -26
- data/test/integration/tags/statements_test.rb +113 -0
- data/test/{liquid/tags/html_tag_test.rb → integration/tags/table_row_test.rb} +5 -5
- data/test/{liquid → integration}/tags/unless_else_tag_test.rb +1 -1
- data/test/{liquid → integration}/template_test.rb +81 -45
- data/test/integration/variable_test.rb +82 -0
- data/test/test_helper.rb +73 -20
- data/test/{liquid/block_test.rb → unit/block_unit_test.rb} +2 -5
- data/test/{liquid/condition_test.rb → unit/condition_unit_test.rb} +23 -1
- data/test/{liquid/context_test.rb → unit/context_unit_test.rb} +39 -25
- data/test/{liquid/file_system_test.rb → unit/file_system_unit_test.rb} +11 -5
- data/test/unit/i18n_unit_test.rb +37 -0
- data/test/unit/lexer_unit_test.rb +48 -0
- data/test/{liquid/module_ex_test.rb → unit/module_ex_unit_test.rb} +7 -7
- data/test/unit/parser_unit_test.rb +82 -0
- data/test/{liquid/regexp_test.rb → unit/regexp_unit_test.rb} +3 -3
- data/test/{liquid/strainer_test.rb → unit/strainer_unit_test.rb} +20 -1
- data/test/unit/tag_unit_test.rb +16 -0
- data/test/unit/tags/case_tag_unit_test.rb +10 -0
- data/test/unit/tags/for_tag_unit_test.rb +13 -0
- data/test/unit/tags/if_tag_unit_test.rb +8 -0
- data/test/unit/template_unit_test.rb +69 -0
- data/test/unit/tokenizer_unit_test.rb +38 -0
- data/test/unit/variable_unit_test.rb +139 -0
- metadata +135 -67
- data/lib/extras/liquid_view.rb +0 -51
- data/lib/liquid/htmltags.rb +0 -73
- data/test/liquid/drop_test.rb +0 -180
- data/test/liquid/error_handling_test.rb +0 -81
- data/test/liquid/hash_ordering_test.rb +0 -25
- data/test/liquid/parsing_quirks_test.rb +0 -52
- data/test/liquid/tags/include_tag_test.rb +0 -166
- data/test/liquid/tags/statements_test.rb +0 -134
- data/test/liquid/variable_test.rb +0 -186
metadata
CHANGED
@@ -1,15 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: liquid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tobias Luetke
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
11
|
+
date: 2014-11-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: minitest
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
13
41
|
description:
|
14
42
|
email:
|
15
43
|
- tobi@leetsoft.com
|
@@ -22,19 +50,27 @@ files:
|
|
22
50
|
- History.md
|
23
51
|
- MIT-LICENSE
|
24
52
|
- README.md
|
25
|
-
- lib/extras/liquid_view.rb
|
26
53
|
- lib/liquid.rb
|
27
54
|
- lib/liquid/block.rb
|
55
|
+
- lib/liquid/block_body.rb
|
28
56
|
- lib/liquid/condition.rb
|
29
57
|
- lib/liquid/context.rb
|
30
58
|
- lib/liquid/document.rb
|
31
59
|
- lib/liquid/drop.rb
|
32
60
|
- lib/liquid/errors.rb
|
61
|
+
- lib/liquid/expression.rb
|
33
62
|
- lib/liquid/extensions.rb
|
34
63
|
- lib/liquid/file_system.rb
|
35
|
-
- lib/liquid/
|
64
|
+
- lib/liquid/i18n.rb
|
36
65
|
- lib/liquid/interrupts.rb
|
66
|
+
- lib/liquid/lexer.rb
|
67
|
+
- lib/liquid/locales/en.yml
|
37
68
|
- lib/liquid/module_ex.rb
|
69
|
+
- lib/liquid/parser.rb
|
70
|
+
- lib/liquid/parser_switching.rb
|
71
|
+
- lib/liquid/profiler.rb
|
72
|
+
- lib/liquid/profiler/hooks.rb
|
73
|
+
- lib/liquid/range_lookup.rb
|
38
74
|
- lib/liquid/standardfilters.rb
|
39
75
|
- lib/liquid/strainer.rb
|
40
76
|
- lib/liquid/tag.rb
|
@@ -52,44 +88,62 @@ files:
|
|
52
88
|
- lib/liquid/tags/include.rb
|
53
89
|
- lib/liquid/tags/increment.rb
|
54
90
|
- lib/liquid/tags/raw.rb
|
91
|
+
- lib/liquid/tags/table_row.rb
|
55
92
|
- lib/liquid/tags/unless.rb
|
56
93
|
- lib/liquid/template.rb
|
94
|
+
- lib/liquid/token.rb
|
57
95
|
- lib/liquid/utils.rb
|
58
96
|
- lib/liquid/variable.rb
|
97
|
+
- lib/liquid/variable_lookup.rb
|
59
98
|
- lib/liquid/version.rb
|
60
|
-
- test/
|
61
|
-
- test/
|
62
|
-
- test/
|
63
|
-
- test/
|
64
|
-
- test/
|
65
|
-
- test/
|
66
|
-
- test/
|
67
|
-
- test/
|
68
|
-
- test/
|
69
|
-
- test/
|
70
|
-
- test/
|
71
|
-
- test/
|
72
|
-
- test/
|
73
|
-
- test/
|
74
|
-
- test/
|
75
|
-
- test/
|
76
|
-
- test/
|
77
|
-
- test/
|
78
|
-
- test/
|
79
|
-
- test/
|
80
|
-
- test/
|
81
|
-
- test/
|
82
|
-
- test/
|
83
|
-
- test/
|
84
|
-
- test/
|
85
|
-
- test/
|
86
|
-
- test/
|
87
|
-
- test/liquid/tags/unless_else_tag_test.rb
|
88
|
-
- test/liquid/template_test.rb
|
89
|
-
- test/liquid/variable_test.rb
|
99
|
+
- test/fixtures/en_locale.yml
|
100
|
+
- test/integration/assign_test.rb
|
101
|
+
- test/integration/blank_test.rb
|
102
|
+
- test/integration/capture_test.rb
|
103
|
+
- test/integration/context_test.rb
|
104
|
+
- test/integration/drop_test.rb
|
105
|
+
- test/integration/error_handling_test.rb
|
106
|
+
- test/integration/filter_test.rb
|
107
|
+
- test/integration/hash_ordering_test.rb
|
108
|
+
- test/integration/output_test.rb
|
109
|
+
- test/integration/parsing_quirks_test.rb
|
110
|
+
- test/integration/render_profiling_test.rb
|
111
|
+
- test/integration/security_test.rb
|
112
|
+
- test/integration/standard_filter_test.rb
|
113
|
+
- test/integration/tags/break_tag_test.rb
|
114
|
+
- test/integration/tags/continue_tag_test.rb
|
115
|
+
- test/integration/tags/for_tag_test.rb
|
116
|
+
- test/integration/tags/if_else_tag_test.rb
|
117
|
+
- test/integration/tags/include_tag_test.rb
|
118
|
+
- test/integration/tags/increment_tag_test.rb
|
119
|
+
- test/integration/tags/raw_tag_test.rb
|
120
|
+
- test/integration/tags/standard_tag_test.rb
|
121
|
+
- test/integration/tags/statements_test.rb
|
122
|
+
- test/integration/tags/table_row_test.rb
|
123
|
+
- test/integration/tags/unless_else_tag_test.rb
|
124
|
+
- test/integration/template_test.rb
|
125
|
+
- test/integration/variable_test.rb
|
90
126
|
- test/test_helper.rb
|
127
|
+
- test/unit/block_unit_test.rb
|
128
|
+
- test/unit/condition_unit_test.rb
|
129
|
+
- test/unit/context_unit_test.rb
|
130
|
+
- test/unit/file_system_unit_test.rb
|
131
|
+
- test/unit/i18n_unit_test.rb
|
132
|
+
- test/unit/lexer_unit_test.rb
|
133
|
+
- test/unit/module_ex_unit_test.rb
|
134
|
+
- test/unit/parser_unit_test.rb
|
135
|
+
- test/unit/regexp_unit_test.rb
|
136
|
+
- test/unit/strainer_unit_test.rb
|
137
|
+
- test/unit/tag_unit_test.rb
|
138
|
+
- test/unit/tags/case_tag_unit_test.rb
|
139
|
+
- test/unit/tags/for_tag_unit_test.rb
|
140
|
+
- test/unit/tags/if_tag_unit_test.rb
|
141
|
+
- test/unit/template_unit_test.rb
|
142
|
+
- test/unit/tokenizer_unit_test.rb
|
143
|
+
- test/unit/variable_unit_test.rb
|
91
144
|
homepage: http://www.liquidmarkup.org
|
92
|
-
licenses:
|
145
|
+
licenses:
|
146
|
+
- MIT
|
93
147
|
metadata: {}
|
94
148
|
post_install_message:
|
95
149
|
rdoc_options: []
|
@@ -107,39 +161,53 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
107
161
|
version: 1.3.7
|
108
162
|
requirements: []
|
109
163
|
rubyforge_project:
|
110
|
-
rubygems_version: 2.2.
|
164
|
+
rubygems_version: 2.2.2
|
111
165
|
signing_key:
|
112
166
|
specification_version: 4
|
113
167
|
summary: A secure, non-evaling end user template engine with aesthetic markup.
|
114
168
|
test_files:
|
115
|
-
- test/
|
116
|
-
- test/
|
117
|
-
- test/
|
118
|
-
- test/
|
119
|
-
- test/
|
120
|
-
- test/
|
121
|
-
- test/
|
122
|
-
- test/
|
123
|
-
- test/
|
124
|
-
- test/
|
125
|
-
- test/
|
126
|
-
- test/
|
127
|
-
- test/
|
128
|
-
- test/
|
129
|
-
- test/
|
130
|
-
- test/
|
131
|
-
- test/
|
132
|
-
- test/liquid/tags/break_tag_test.rb
|
133
|
-
- test/liquid/tags/continue_tag_test.rb
|
134
|
-
- test/liquid/tags/for_tag_test.rb
|
135
|
-
- test/liquid/tags/html_tag_test.rb
|
136
|
-
- test/liquid/tags/if_else_tag_test.rb
|
137
|
-
- test/liquid/tags/include_tag_test.rb
|
138
|
-
- test/liquid/tags/increment_tag_test.rb
|
139
|
-
- test/liquid/tags/raw_tag_test.rb
|
140
|
-
- test/liquid/tags/standard_tag_test.rb
|
141
|
-
- test/liquid/tags/statements_test.rb
|
142
|
-
- test/liquid/tags/unless_else_tag_test.rb
|
143
|
-
- test/liquid/template_test.rb
|
144
|
-
- test/liquid/variable_test.rb
|
169
|
+
- test/unit/tags/for_tag_unit_test.rb
|
170
|
+
- test/unit/tags/if_tag_unit_test.rb
|
171
|
+
- test/unit/tags/case_tag_unit_test.rb
|
172
|
+
- test/unit/parser_unit_test.rb
|
173
|
+
- test/unit/condition_unit_test.rb
|
174
|
+
- test/unit/file_system_unit_test.rb
|
175
|
+
- test/unit/regexp_unit_test.rb
|
176
|
+
- test/unit/tag_unit_test.rb
|
177
|
+
- test/unit/i18n_unit_test.rb
|
178
|
+
- test/unit/tokenizer_unit_test.rb
|
179
|
+
- test/unit/strainer_unit_test.rb
|
180
|
+
- test/unit/template_unit_test.rb
|
181
|
+
- test/unit/module_ex_unit_test.rb
|
182
|
+
- test/unit/lexer_unit_test.rb
|
183
|
+
- test/unit/block_unit_test.rb
|
184
|
+
- test/unit/context_unit_test.rb
|
185
|
+
- test/unit/variable_unit_test.rb
|
145
186
|
- test/test_helper.rb
|
187
|
+
- test/integration/tags/for_tag_test.rb
|
188
|
+
- test/integration/tags/if_else_tag_test.rb
|
189
|
+
- test/integration/tags/include_tag_test.rb
|
190
|
+
- test/integration/tags/continue_tag_test.rb
|
191
|
+
- test/integration/tags/raw_tag_test.rb
|
192
|
+
- test/integration/tags/table_row_test.rb
|
193
|
+
- test/integration/tags/standard_tag_test.rb
|
194
|
+
- test/integration/tags/increment_tag_test.rb
|
195
|
+
- test/integration/tags/unless_else_tag_test.rb
|
196
|
+
- test/integration/tags/statements_test.rb
|
197
|
+
- test/integration/tags/break_tag_test.rb
|
198
|
+
- test/integration/filter_test.rb
|
199
|
+
- test/integration/render_profiling_test.rb
|
200
|
+
- test/integration/parsing_quirks_test.rb
|
201
|
+
- test/integration/drop_test.rb
|
202
|
+
- test/integration/hash_ordering_test.rb
|
203
|
+
- test/integration/capture_test.rb
|
204
|
+
- test/integration/assign_test.rb
|
205
|
+
- test/integration/output_test.rb
|
206
|
+
- test/integration/error_handling_test.rb
|
207
|
+
- test/integration/blank_test.rb
|
208
|
+
- test/integration/template_test.rb
|
209
|
+
- test/integration/security_test.rb
|
210
|
+
- test/integration/variable_test.rb
|
211
|
+
- test/integration/standard_filter_test.rb
|
212
|
+
- test/integration/context_test.rb
|
213
|
+
- test/fixtures/en_locale.yml
|
data/lib/extras/liquid_view.rb
DELETED
@@ -1,51 +0,0 @@
|
|
1
|
-
# LiquidView is a action view extension class. You can register it with rails
|
2
|
-
# and use liquid as an template system for .liquid files
|
3
|
-
#
|
4
|
-
# Example
|
5
|
-
#
|
6
|
-
# ActionView::Base::register_template_handler :liquid, LiquidView
|
7
|
-
class LiquidView
|
8
|
-
PROTECTED_ASSIGNS = %w( template_root response _session template_class action_name request_origin session template
|
9
|
-
_response url _request _cookies variables_added _flash params _headers request cookies
|
10
|
-
ignore_missing_templates flash _params logger before_filter_chain_aborted headers )
|
11
|
-
PROTECTED_INSTANCE_VARIABLES = %w( @_request @controller @_first_render @_memoized__pick_template @view_paths
|
12
|
-
@helpers @assigns_added @template @_render_stack @template_format @assigns )
|
13
|
-
|
14
|
-
def self.call(template)
|
15
|
-
"LiquidView.new(self).render(template, local_assigns)"
|
16
|
-
end
|
17
|
-
|
18
|
-
def initialize(view)
|
19
|
-
@view = view
|
20
|
-
end
|
21
|
-
|
22
|
-
def render(template, local_assigns = nil)
|
23
|
-
@view.controller.headers["Content-Type"] ||= 'text/html; charset=utf-8'
|
24
|
-
|
25
|
-
# Rails 2.2 Template has source, but not locals
|
26
|
-
if template.respond_to?(:source) && !template.respond_to?(:locals)
|
27
|
-
assigns = (@view.instance_variables - PROTECTED_INSTANCE_VARIABLES).inject({}) do |hash, ivar|
|
28
|
-
hash[ivar[1..-1]] = @view.instance_variable_get(ivar)
|
29
|
-
hash
|
30
|
-
end
|
31
|
-
else
|
32
|
-
assigns = @view.assigns.reject{ |k,v| PROTECTED_ASSIGNS.include?(k) }
|
33
|
-
end
|
34
|
-
|
35
|
-
source = template.respond_to?(:source) ? template.source : template
|
36
|
-
local_assigns = (template.respond_to?(:locals) ? template.locals : local_assigns) || {}
|
37
|
-
|
38
|
-
if content_for_layout = @view.instance_variable_get("@content_for_layout")
|
39
|
-
assigns['content_for_layout'] = content_for_layout
|
40
|
-
end
|
41
|
-
assigns.merge!(local_assigns.stringify_keys)
|
42
|
-
|
43
|
-
liquid = Liquid::Template.parse(source)
|
44
|
-
liquid.render(assigns, :filters => [@view.controller.master_helper_module], :registers => {:action_view => @view, :controller => @view.controller})
|
45
|
-
end
|
46
|
-
|
47
|
-
def compilable?
|
48
|
-
false
|
49
|
-
end
|
50
|
-
|
51
|
-
end
|
data/lib/liquid/htmltags.rb
DELETED
@@ -1,73 +0,0 @@
|
|
1
|
-
module Liquid
|
2
|
-
class TableRow < Block
|
3
|
-
Syntax = /(\w+)\s+in\s+(#{QuotedFragment}+)/o
|
4
|
-
|
5
|
-
def initialize(tag_name, markup, tokens)
|
6
|
-
if markup =~ Syntax
|
7
|
-
@variable_name = $1
|
8
|
-
@collection_name = $2
|
9
|
-
@attributes = {}
|
10
|
-
markup.scan(TagAttributes) do |key, value|
|
11
|
-
@attributes[key] = value
|
12
|
-
end
|
13
|
-
else
|
14
|
-
raise SyntaxError.new("Syntax Error in 'table_row loop' - Valid syntax: table_row [item] in [collection] cols=3")
|
15
|
-
end
|
16
|
-
|
17
|
-
super
|
18
|
-
end
|
19
|
-
|
20
|
-
def render(context)
|
21
|
-
collection = context[@collection_name] or return ''
|
22
|
-
|
23
|
-
from = @attributes['offset'] ? context[@attributes['offset']].to_i : 0
|
24
|
-
to = @attributes['limit'] ? from + context[@attributes['limit']].to_i : nil
|
25
|
-
|
26
|
-
collection = Utils.slice_collection_using_each(collection, from, to)
|
27
|
-
|
28
|
-
length = collection.length
|
29
|
-
|
30
|
-
cols = context[@attributes['cols']].to_i
|
31
|
-
|
32
|
-
row = 1
|
33
|
-
col = 0
|
34
|
-
|
35
|
-
result = "<tr class=\"row1\">\n"
|
36
|
-
context.stack do
|
37
|
-
|
38
|
-
collection.each_with_index do |item, index|
|
39
|
-
context[@variable_name] = item
|
40
|
-
context['tablerowloop'] = {
|
41
|
-
'length' => length,
|
42
|
-
'index' => index + 1,
|
43
|
-
'index0' => index,
|
44
|
-
'col' => col + 1,
|
45
|
-
'col0' => col,
|
46
|
-
'rindex' => length - index,
|
47
|
-
'rindex0' => length - index - 1,
|
48
|
-
'first' => (index == 0),
|
49
|
-
'last' => (index == length - 1),
|
50
|
-
'col_first' => (col == 0),
|
51
|
-
'col_last' => (col == cols - 1)
|
52
|
-
}
|
53
|
-
|
54
|
-
|
55
|
-
col += 1
|
56
|
-
|
57
|
-
result << "<td class=\"col#{col}\">" << render_all(@nodelist, context) << '</td>'
|
58
|
-
|
59
|
-
if col == cols and (index != length - 1)
|
60
|
-
col = 0
|
61
|
-
row += 1
|
62
|
-
result << "</tr>\n<tr class=\"row#{row}\">"
|
63
|
-
end
|
64
|
-
|
65
|
-
end
|
66
|
-
end
|
67
|
-
result << "</tr>\n"
|
68
|
-
result
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
Template.register_tag('tablerow', TableRow)
|
73
|
-
end
|
data/test/liquid/drop_test.rb
DELETED
@@ -1,180 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class ContextDrop < Liquid::Drop
|
4
|
-
def scopes
|
5
|
-
@context.scopes.size
|
6
|
-
end
|
7
|
-
|
8
|
-
def scopes_as_array
|
9
|
-
(1..@context.scopes.size).to_a
|
10
|
-
end
|
11
|
-
|
12
|
-
def loop_pos
|
13
|
-
@context['forloop.index']
|
14
|
-
end
|
15
|
-
|
16
|
-
def before_method(method)
|
17
|
-
return @context[method]
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
class ProductDrop < Liquid::Drop
|
22
|
-
|
23
|
-
class TextDrop < Liquid::Drop
|
24
|
-
def array
|
25
|
-
['text1', 'text2']
|
26
|
-
end
|
27
|
-
|
28
|
-
def text
|
29
|
-
'text1'
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
class CatchallDrop < Liquid::Drop
|
34
|
-
def before_method(method)
|
35
|
-
return 'method: ' << method.to_s
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def texts
|
40
|
-
TextDrop.new
|
41
|
-
end
|
42
|
-
|
43
|
-
def catchall
|
44
|
-
CatchallDrop.new
|
45
|
-
end
|
46
|
-
|
47
|
-
def context
|
48
|
-
ContextDrop.new
|
49
|
-
end
|
50
|
-
|
51
|
-
protected
|
52
|
-
def callmenot
|
53
|
-
"protected"
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
class EnumerableDrop < Liquid::Drop
|
58
|
-
|
59
|
-
def size
|
60
|
-
3
|
61
|
-
end
|
62
|
-
|
63
|
-
def each
|
64
|
-
yield 1
|
65
|
-
yield 2
|
66
|
-
yield 3
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
class DropsTest < Test::Unit::TestCase
|
71
|
-
include Liquid
|
72
|
-
|
73
|
-
def test_product_drop
|
74
|
-
assert_nothing_raised do
|
75
|
-
tpl = Liquid::Template.parse( ' ' )
|
76
|
-
tpl.render('product' => ProductDrop.new)
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
def test_drop_does_only_respond_to_whitelisted_methods
|
81
|
-
assert_equal "", Liquid::Template.parse("{{ product.inspect }}").render('product' => ProductDrop.new)
|
82
|
-
assert_equal "", Liquid::Template.parse("{{ product.pretty_inspect }}").render('product' => ProductDrop.new)
|
83
|
-
assert_equal "", Liquid::Template.parse("{{ product.whatever }}").render('product' => ProductDrop.new)
|
84
|
-
assert_equal "", Liquid::Template.parse('{{ product | map: "inspect" }}').render('product' => ProductDrop.new)
|
85
|
-
assert_equal "", Liquid::Template.parse('{{ product | map: "pretty_inspect" }}').render('product' => ProductDrop.new)
|
86
|
-
assert_equal "", Liquid::Template.parse('{{ product | map: "whatever" }}').render('product' => ProductDrop.new)
|
87
|
-
end
|
88
|
-
|
89
|
-
def test_drops_respond_to_to_liquid
|
90
|
-
assert_equal "text1", Liquid::Template.parse("{{ product.to_liquid.texts.text }}").render('product' => ProductDrop.new)
|
91
|
-
assert_equal "text1", Liquid::Template.parse('{{ product | map: "to_liquid" | map: "texts" | map: "text" }}').render('product' => ProductDrop.new)
|
92
|
-
end
|
93
|
-
|
94
|
-
def test_text_drop
|
95
|
-
output = Liquid::Template.parse( ' {{ product.texts.text }} ' ).render('product' => ProductDrop.new)
|
96
|
-
assert_equal ' text1 ', output
|
97
|
-
end
|
98
|
-
|
99
|
-
def test_unknown_method
|
100
|
-
output = Liquid::Template.parse( ' {{ product.catchall.unknown }} ' ).render('product' => ProductDrop.new)
|
101
|
-
assert_equal ' method: unknown ', output
|
102
|
-
end
|
103
|
-
|
104
|
-
def test_integer_argument_drop
|
105
|
-
output = Liquid::Template.parse( ' {{ product.catchall[8] }} ' ).render('product' => ProductDrop.new)
|
106
|
-
assert_equal ' method: 8 ', output
|
107
|
-
end
|
108
|
-
|
109
|
-
def test_text_array_drop
|
110
|
-
output = Liquid::Template.parse( '{% for text in product.texts.array %} {{text}} {% endfor %}' ).render('product' => ProductDrop.new)
|
111
|
-
assert_equal ' text1 text2 ', output
|
112
|
-
end
|
113
|
-
|
114
|
-
def test_context_drop
|
115
|
-
output = Liquid::Template.parse( ' {{ context.bar }} ' ).render('context' => ContextDrop.new, 'bar' => "carrot")
|
116
|
-
assert_equal ' carrot ', output
|
117
|
-
end
|
118
|
-
|
119
|
-
def test_nested_context_drop
|
120
|
-
output = Liquid::Template.parse( ' {{ product.context.foo }} ' ).render('product' => ProductDrop.new, 'foo' => "monkey")
|
121
|
-
assert_equal ' monkey ', output
|
122
|
-
end
|
123
|
-
|
124
|
-
def test_protected
|
125
|
-
output = Liquid::Template.parse( ' {{ product.callmenot }} ' ).render('product' => ProductDrop.new)
|
126
|
-
assert_equal ' ', output
|
127
|
-
end
|
128
|
-
|
129
|
-
def test_object_methods_not_allowed
|
130
|
-
[:dup, :clone, :singleton_class, :eval, :class_eval, :inspect].each do |method|
|
131
|
-
output = Liquid::Template.parse(" {{ product.#{method} }} ").render('product' => ProductDrop.new)
|
132
|
-
assert_equal ' ', output
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
def test_scope
|
137
|
-
assert_equal '1', Liquid::Template.parse( '{{ context.scopes }}' ).render('context' => ContextDrop.new)
|
138
|
-
assert_equal '2', Liquid::Template.parse( '{%for i in dummy%}{{ context.scopes }}{%endfor%}' ).render('context' => ContextDrop.new, 'dummy' => [1])
|
139
|
-
assert_equal '3', Liquid::Template.parse( '{%for i in dummy%}{%for i in dummy%}{{ context.scopes }}{%endfor%}{%endfor%}' ).render('context' => ContextDrop.new, 'dummy' => [1])
|
140
|
-
end
|
141
|
-
|
142
|
-
def test_scope_though_proc
|
143
|
-
assert_equal '1', Liquid::Template.parse( '{{ s }}' ).render('context' => ContextDrop.new, 's' => Proc.new{|c| c['context.scopes'] })
|
144
|
-
assert_equal '2', Liquid::Template.parse( '{%for i in dummy%}{{ s }}{%endfor%}' ).render('context' => ContextDrop.new, 's' => Proc.new{|c| c['context.scopes'] }, 'dummy' => [1])
|
145
|
-
assert_equal '3', Liquid::Template.parse( '{%for i in dummy%}{%for i in dummy%}{{ s }}{%endfor%}{%endfor%}' ).render('context' => ContextDrop.new, 's' => Proc.new{|c| c['context.scopes'] }, 'dummy' => [1])
|
146
|
-
end
|
147
|
-
|
148
|
-
def test_scope_with_assigns
|
149
|
-
assert_equal 'variable', Liquid::Template.parse( '{% assign a = "variable"%}{{a}}' ).render('context' => ContextDrop.new)
|
150
|
-
assert_equal 'variable', Liquid::Template.parse( '{% assign a = "variable"%}{%for i in dummy%}{{a}}{%endfor%}' ).render('context' => ContextDrop.new, 'dummy' => [1])
|
151
|
-
assert_equal 'test', Liquid::Template.parse( '{% assign header_gif = "test"%}{{header_gif}}' ).render('context' => ContextDrop.new)
|
152
|
-
assert_equal 'test', Liquid::Template.parse( "{% assign header_gif = 'test'%}{{header_gif}}" ).render('context' => ContextDrop.new)
|
153
|
-
end
|
154
|
-
|
155
|
-
def test_scope_from_tags
|
156
|
-
assert_equal '1', Liquid::Template.parse( '{% for i in context.scopes_as_array %}{{i}}{% endfor %}' ).render('context' => ContextDrop.new, 'dummy' => [1])
|
157
|
-
assert_equal '12', Liquid::Template.parse( '{%for a in dummy%}{% for i in context.scopes_as_array %}{{i}}{% endfor %}{% endfor %}' ).render('context' => ContextDrop.new, 'dummy' => [1])
|
158
|
-
assert_equal '123', Liquid::Template.parse( '{%for a in dummy%}{%for a in dummy%}{% for i in context.scopes_as_array %}{{i}}{% endfor %}{% endfor %}{% endfor %}' ).render('context' => ContextDrop.new, 'dummy' => [1])
|
159
|
-
end
|
160
|
-
|
161
|
-
def test_access_context_from_drop
|
162
|
-
assert_equal '123', Liquid::Template.parse( '{%for a in dummy%}{{ context.loop_pos }}{% endfor %}' ).render('context' => ContextDrop.new, 'dummy' => [1,2,3])
|
163
|
-
end
|
164
|
-
|
165
|
-
def test_enumerable_drop
|
166
|
-
assert_equal '123', Liquid::Template.parse( '{% for c in collection %}{{c}}{% endfor %}').render('collection' => EnumerableDrop.new)
|
167
|
-
end
|
168
|
-
|
169
|
-
def test_enumerable_drop_size
|
170
|
-
assert_equal '3', Liquid::Template.parse( '{{collection.size}}').render('collection' => EnumerableDrop.new)
|
171
|
-
end
|
172
|
-
|
173
|
-
def test_empty_string_value_access
|
174
|
-
assert_equal '', Liquid::Template.parse('{{ product[value] }}').render('product' => ProductDrop.new, 'value' => '')
|
175
|
-
end
|
176
|
-
|
177
|
-
def test_nil_value_access
|
178
|
-
assert_equal '', Liquid::Template.parse('{{ product[value] }}').render('product' => ProductDrop.new, 'value' => nil)
|
179
|
-
end
|
180
|
-
end # DropsTest
|
@@ -1,81 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class ErrorDrop < Liquid::Drop
|
4
|
-
def standard_error
|
5
|
-
raise Liquid::StandardError, 'standard error'
|
6
|
-
end
|
7
|
-
|
8
|
-
def argument_error
|
9
|
-
raise Liquid::ArgumentError, 'argument error'
|
10
|
-
end
|
11
|
-
|
12
|
-
def syntax_error
|
13
|
-
raise Liquid::SyntaxError, 'syntax error'
|
14
|
-
end
|
15
|
-
|
16
|
-
def exception
|
17
|
-
raise Exception, 'exception'
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
21
|
-
|
22
|
-
class ErrorHandlingTest < Test::Unit::TestCase
|
23
|
-
include Liquid
|
24
|
-
|
25
|
-
def test_standard_error
|
26
|
-
assert_nothing_raised do
|
27
|
-
template = Liquid::Template.parse( ' {{ errors.standard_error }} ' )
|
28
|
-
assert_equal ' Liquid error: standard error ', template.render('errors' => ErrorDrop.new)
|
29
|
-
|
30
|
-
assert_equal 1, template.errors.size
|
31
|
-
assert_equal StandardError, template.errors.first.class
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_syntax
|
36
|
-
|
37
|
-
assert_nothing_raised do
|
38
|
-
|
39
|
-
template = Liquid::Template.parse( ' {{ errors.syntax_error }} ' )
|
40
|
-
assert_equal ' Liquid syntax error: syntax error ', template.render('errors' => ErrorDrop.new)
|
41
|
-
|
42
|
-
assert_equal 1, template.errors.size
|
43
|
-
assert_equal SyntaxError, template.errors.first.class
|
44
|
-
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_argument
|
49
|
-
assert_nothing_raised do
|
50
|
-
|
51
|
-
template = Liquid::Template.parse( ' {{ errors.argument_error }} ' )
|
52
|
-
assert_equal ' Liquid error: argument error ', template.render('errors' => ErrorDrop.new)
|
53
|
-
|
54
|
-
assert_equal 1, template.errors.size
|
55
|
-
assert_equal ArgumentError, template.errors.first.class
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
def test_missing_endtag_parse_time_error
|
60
|
-
assert_raise(Liquid::SyntaxError) do
|
61
|
-
template = Liquid::Template.parse(' {% for a in b %} ... ')
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
def test_unrecognized_operator
|
66
|
-
assert_nothing_raised do
|
67
|
-
template = Liquid::Template.parse(' {% if 1 =! 2 %}ok{% endif %} ')
|
68
|
-
assert_equal ' Liquid error: Unknown operator =! ', template.render
|
69
|
-
assert_equal 1, template.errors.size
|
70
|
-
assert_equal Liquid::ArgumentError, template.errors.first.class
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
# Liquid should not catch Exceptions that are not subclasses of StandardError, like Interrupt and NoMemoryError
|
75
|
-
def test_exceptions_propagate
|
76
|
-
assert_raise Exception do
|
77
|
-
template = Liquid::Template.parse( ' {{ errors.exception }} ' )
|
78
|
-
template.render('errors' => ErrorDrop.new)
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end # ErrorHandlingTest
|
@@ -1,25 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
module MoneyFilter
|
4
|
-
def money(input)
|
5
|
-
sprintf(' %d$ ', input)
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
|
-
module CanadianMoneyFilter
|
10
|
-
def money(input)
|
11
|
-
sprintf(' %d$ CAD ', input)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
class HashOrderingTest < Test::Unit::TestCase
|
16
|
-
include Liquid
|
17
|
-
|
18
|
-
def test_global_register_order
|
19
|
-
Template.register_filter(MoneyFilter)
|
20
|
-
Template.register_filter(CanadianMoneyFilter)
|
21
|
-
|
22
|
-
assert_equal " 1000$ CAD ", Template.parse("{{1000 | money}}").render(nil, nil)
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|