liquid 2.6.3 → 3.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.md +42 -13
- data/README.md +27 -2
- data/lib/liquid.rb +11 -11
- data/lib/liquid/block.rb +75 -45
- data/lib/liquid/condition.rb +15 -11
- data/lib/liquid/context.rb +68 -29
- data/lib/liquid/document.rb +3 -3
- data/lib/liquid/drop.rb +17 -1
- 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/standardfilters.rb +115 -52
- data/lib/liquid/strainer.rb +14 -4
- data/lib/liquid/tag.rb +42 -7
- data/lib/liquid/tags/assign.rb +10 -8
- 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 +2 -2
- data/lib/liquid/tags/include.rb +8 -7
- data/lib/liquid/tags/increment.rb +4 -8
- data/lib/liquid/tags/raw.rb +3 -3
- data/lib/liquid/tags/table_row.rb +73 -0
- data/lib/liquid/tags/unless.rb +2 -4
- data/lib/liquid/template.rb +69 -10
- data/lib/liquid/utils.rb +13 -4
- data/lib/liquid/variable.rb +59 -8
- data/lib/liquid/version.rb +1 -1
- data/test/fixtures/en_locale.yml +9 -0
- data/test/{liquid → integration}/assign_test.rb +6 -0
- data/test/integration/blank_test.rb +106 -0
- data/test/{liquid → integration}/capture_test.rb +2 -2
- data/test/integration/context_test.rb +33 -0
- data/test/integration/drop_test.rb +245 -0
- data/test/{liquid → integration}/error_handling_test.rb +31 -2
- data/test/{liquid → integration}/filter_test.rb +7 -7
- data/test/{liquid → integration}/hash_ordering_test.rb +0 -0
- data/test/{liquid → integration}/output_test.rb +12 -12
- data/test/integration/parsing_quirks_test.rb +94 -0
- data/test/{liquid → integration}/security_test.rb +9 -9
- data/test/{liquid → integration}/standard_filter_test.rb +103 -33
- data/test/{liquid → integration}/tags/break_tag_test.rb +0 -0
- data/test/{liquid → integration}/tags/continue_tag_test.rb +0 -0
- data/test/{liquid → integration}/tags/for_tag_test.rb +78 -0
- data/test/{liquid → integration}/tags/if_else_tag_test.rb +1 -1
- data/test/integration/tags/include_tag_test.rb +212 -0
- data/test/{liquid → integration}/tags/increment_tag_test.rb +0 -0
- data/test/{liquid → integration}/tags/raw_tag_test.rb +1 -0
- data/test/{liquid → integration}/tags/standard_tag_test.rb +24 -22
- 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 +0 -0
- data/test/{liquid → integration}/template_test.rb +66 -42
- data/test/integration/variable_test.rb +72 -0
- data/test/test_helper.rb +32 -7
- data/test/{liquid/block_test.rb → unit/block_unit_test.rb} +1 -1
- data/test/{liquid/condition_test.rb → unit/condition_unit_test.rb} +19 -1
- data/test/{liquid/context_test.rb → unit/context_unit_test.rb} +27 -19
- data/test/{liquid/file_system_test.rb → unit/file_system_unit_test.rb} +7 -1
- 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} +19 -1
- data/test/unit/tag_unit_test.rb +11 -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 +29 -0
- data/test/{liquid/variable_test.rb → unit/variable_unit_test.rb} +17 -67
- metadata +117 -73
- 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/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
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: liquid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0.rc1
|
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-07-24 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'
|
13
27
|
description:
|
14
28
|
email:
|
15
29
|
- tobi@leetsoft.com
|
@@ -19,11 +33,6 @@ extra_rdoc_files:
|
|
19
33
|
- History.md
|
20
34
|
- README.md
|
21
35
|
files:
|
22
|
-
- History.md
|
23
|
-
- MIT-LICENSE
|
24
|
-
- README.md
|
25
|
-
- lib/extras/liquid_view.rb
|
26
|
-
- lib/liquid.rb
|
27
36
|
- lib/liquid/block.rb
|
28
37
|
- lib/liquid/condition.rb
|
29
38
|
- lib/liquid/context.rb
|
@@ -32,9 +41,12 @@ files:
|
|
32
41
|
- lib/liquid/errors.rb
|
33
42
|
- lib/liquid/extensions.rb
|
34
43
|
- lib/liquid/file_system.rb
|
35
|
-
- lib/liquid/
|
44
|
+
- lib/liquid/i18n.rb
|
36
45
|
- lib/liquid/interrupts.rb
|
46
|
+
- lib/liquid/lexer.rb
|
47
|
+
- lib/liquid/locales/en.yml
|
37
48
|
- lib/liquid/module_ex.rb
|
49
|
+
- lib/liquid/parser.rb
|
38
50
|
- lib/liquid/standardfilters.rb
|
39
51
|
- lib/liquid/strainer.rb
|
40
52
|
- lib/liquid/tag.rb
|
@@ -52,44 +64,63 @@ files:
|
|
52
64
|
- lib/liquid/tags/include.rb
|
53
65
|
- lib/liquid/tags/increment.rb
|
54
66
|
- lib/liquid/tags/raw.rb
|
67
|
+
- lib/liquid/tags/table_row.rb
|
55
68
|
- lib/liquid/tags/unless.rb
|
56
69
|
- lib/liquid/template.rb
|
57
70
|
- lib/liquid/utils.rb
|
58
71
|
- lib/liquid/variable.rb
|
59
72
|
- lib/liquid/version.rb
|
60
|
-
-
|
61
|
-
-
|
62
|
-
-
|
63
|
-
-
|
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/
|
88
|
-
- test/
|
89
|
-
- test/
|
73
|
+
- lib/liquid.rb
|
74
|
+
- MIT-LICENSE
|
75
|
+
- README.md
|
76
|
+
- History.md
|
77
|
+
- test/fixtures/en_locale.yml
|
78
|
+
- test/integration/assign_test.rb
|
79
|
+
- test/integration/blank_test.rb
|
80
|
+
- test/integration/capture_test.rb
|
81
|
+
- test/integration/context_test.rb
|
82
|
+
- test/integration/drop_test.rb
|
83
|
+
- test/integration/error_handling_test.rb
|
84
|
+
- test/integration/filter_test.rb
|
85
|
+
- test/integration/hash_ordering_test.rb
|
86
|
+
- test/integration/output_test.rb
|
87
|
+
- test/integration/parsing_quirks_test.rb
|
88
|
+
- test/integration/security_test.rb
|
89
|
+
- test/integration/standard_filter_test.rb
|
90
|
+
- test/integration/tags/break_tag_test.rb
|
91
|
+
- test/integration/tags/continue_tag_test.rb
|
92
|
+
- test/integration/tags/for_tag_test.rb
|
93
|
+
- test/integration/tags/if_else_tag_test.rb
|
94
|
+
- test/integration/tags/include_tag_test.rb
|
95
|
+
- test/integration/tags/increment_tag_test.rb
|
96
|
+
- test/integration/tags/raw_tag_test.rb
|
97
|
+
- test/integration/tags/standard_tag_test.rb
|
98
|
+
- test/integration/tags/statements_test.rb
|
99
|
+
- test/integration/tags/table_row_test.rb
|
100
|
+
- test/integration/tags/unless_else_tag_test.rb
|
101
|
+
- test/integration/template_test.rb
|
102
|
+
- test/integration/variable_test.rb
|
90
103
|
- test/test_helper.rb
|
104
|
+
- test/unit/block_unit_test.rb
|
105
|
+
- test/unit/condition_unit_test.rb
|
106
|
+
- test/unit/context_unit_test.rb
|
107
|
+
- test/unit/file_system_unit_test.rb
|
108
|
+
- test/unit/i18n_unit_test.rb
|
109
|
+
- test/unit/lexer_unit_test.rb
|
110
|
+
- test/unit/module_ex_unit_test.rb
|
111
|
+
- test/unit/parser_unit_test.rb
|
112
|
+
- test/unit/regexp_unit_test.rb
|
113
|
+
- test/unit/strainer_unit_test.rb
|
114
|
+
- test/unit/tag_unit_test.rb
|
115
|
+
- test/unit/tags/case_tag_unit_test.rb
|
116
|
+
- test/unit/tags/for_tag_unit_test.rb
|
117
|
+
- test/unit/tags/if_tag_unit_test.rb
|
118
|
+
- test/unit/template_unit_test.rb
|
119
|
+
- test/unit/tokenizer_unit_test.rb
|
120
|
+
- test/unit/variable_unit_test.rb
|
91
121
|
homepage: http://www.liquidmarkup.org
|
92
|
-
licenses:
|
122
|
+
licenses:
|
123
|
+
- MIT
|
93
124
|
metadata: {}
|
94
125
|
post_install_message:
|
95
126
|
rdoc_options: []
|
@@ -97,49 +128,62 @@ require_paths:
|
|
97
128
|
- lib
|
98
129
|
required_ruby_version: !ruby/object:Gem::Requirement
|
99
130
|
requirements:
|
100
|
-
- -
|
131
|
+
- - '>='
|
101
132
|
- !ruby/object:Gem::Version
|
102
133
|
version: '0'
|
103
134
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
135
|
requirements:
|
105
|
-
- -
|
136
|
+
- - '>='
|
106
137
|
- !ruby/object:Gem::Version
|
107
138
|
version: 1.3.7
|
108
139
|
requirements: []
|
109
140
|
rubyforge_project:
|
110
|
-
rubygems_version: 2.
|
141
|
+
rubygems_version: 2.0.3
|
111
142
|
signing_key:
|
112
143
|
specification_version: 4
|
113
144
|
summary: A secure, non-evaling end user template engine with aesthetic markup.
|
114
145
|
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/
|
133
|
-
- test/
|
134
|
-
- test/
|
135
|
-
- test/
|
136
|
-
- test/
|
137
|
-
- test/
|
138
|
-
- test/
|
139
|
-
- test/
|
140
|
-
- test/
|
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
|
146
|
+
- test/fixtures/en_locale.yml
|
147
|
+
- test/integration/assign_test.rb
|
148
|
+
- test/integration/blank_test.rb
|
149
|
+
- test/integration/capture_test.rb
|
150
|
+
- test/integration/context_test.rb
|
151
|
+
- test/integration/drop_test.rb
|
152
|
+
- test/integration/error_handling_test.rb
|
153
|
+
- test/integration/filter_test.rb
|
154
|
+
- test/integration/hash_ordering_test.rb
|
155
|
+
- test/integration/output_test.rb
|
156
|
+
- test/integration/parsing_quirks_test.rb
|
157
|
+
- test/integration/security_test.rb
|
158
|
+
- test/integration/standard_filter_test.rb
|
159
|
+
- test/integration/tags/break_tag_test.rb
|
160
|
+
- test/integration/tags/continue_tag_test.rb
|
161
|
+
- test/integration/tags/for_tag_test.rb
|
162
|
+
- test/integration/tags/if_else_tag_test.rb
|
163
|
+
- test/integration/tags/include_tag_test.rb
|
164
|
+
- test/integration/tags/increment_tag_test.rb
|
165
|
+
- test/integration/tags/raw_tag_test.rb
|
166
|
+
- test/integration/tags/standard_tag_test.rb
|
167
|
+
- test/integration/tags/statements_test.rb
|
168
|
+
- test/integration/tags/table_row_test.rb
|
169
|
+
- test/integration/tags/unless_else_tag_test.rb
|
170
|
+
- test/integration/template_test.rb
|
171
|
+
- test/integration/variable_test.rb
|
145
172
|
- test/test_helper.rb
|
173
|
+
- test/unit/block_unit_test.rb
|
174
|
+
- test/unit/condition_unit_test.rb
|
175
|
+
- test/unit/context_unit_test.rb
|
176
|
+
- test/unit/file_system_unit_test.rb
|
177
|
+
- test/unit/i18n_unit_test.rb
|
178
|
+
- test/unit/lexer_unit_test.rb
|
179
|
+
- test/unit/module_ex_unit_test.rb
|
180
|
+
- test/unit/parser_unit_test.rb
|
181
|
+
- test/unit/regexp_unit_test.rb
|
182
|
+
- test/unit/strainer_unit_test.rb
|
183
|
+
- test/unit/tag_unit_test.rb
|
184
|
+
- test/unit/tags/case_tag_unit_test.rb
|
185
|
+
- test/unit/tags/for_tag_unit_test.rb
|
186
|
+
- test/unit/tags/if_tag_unit_test.rb
|
187
|
+
- test/unit/template_unit_test.rb
|
188
|
+
- test/unit/tokenizer_unit_test.rb
|
189
|
+
- test/unit/variable_unit_test.rb
|
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
|