liquid 1.7.0 → 1.9.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.
- data/CHANGELOG +17 -15
- data/History.txt +44 -0
- data/MIT-LICENSE +2 -2
- data/Manifest.txt +6 -1
- data/{README → README.txt} +0 -0
- data/Rakefile +3 -3
- data/init.rb +5 -3
- data/lib/liquid.rb +8 -6
- data/lib/liquid/block.rb +6 -9
- data/lib/liquid/condition.rb +49 -17
- data/lib/liquid/context.rb +67 -41
- data/lib/liquid/errors.rb +8 -5
- data/lib/liquid/htmltags.rb +17 -7
- data/lib/liquid/module_ex.rb +62 -0
- data/lib/liquid/standardfilters.rb +39 -0
- data/lib/liquid/strainer.rb +20 -11
- data/lib/liquid/tag.rb +4 -3
- data/lib/liquid/tags/assign.rb +15 -4
- data/lib/liquid/tags/capture.rb +15 -2
- data/lib/liquid/tags/case.rb +51 -36
- data/lib/liquid/tags/cycle.rb +16 -2
- data/lib/liquid/tags/for.rb +45 -8
- data/lib/liquid/tags/if.rb +35 -7
- data/lib/liquid/tags/include.rb +2 -3
- data/lib/liquid/tags/unless.rb +6 -2
- data/lib/liquid/template.rb +13 -18
- data/lib/liquid/variable.rb +25 -12
- data/test/block_test.rb +8 -0
- data/test/condition_test.rb +109 -0
- data/test/context_test.rb +88 -10
- data/test/drop_test.rb +3 -1
- data/test/error_handling_test.rb +16 -3
- data/test/extra/breakpoint.rb +0 -0
- data/test/extra/caller.rb +0 -0
- data/test/filter_test.rb +3 -3
- data/test/html_tag_test.rb +7 -0
- data/test/if_else_test.rb +32 -0
- data/test/include_tag_test.rb +24 -1
- data/test/module_ex_test.rb +89 -0
- data/test/parsing_quirks_test.rb +15 -0
- data/test/regexp_test.rb +4 -3
- data/test/standard_filter_test.rb +27 -2
- data/test/standard_tag_test.rb +67 -20
- data/test/test_helper.rb +20 -0
- data/test/unless_else_test.rb +8 -0
- metadata +60 -46
data/test/regexp_test.rb
CHANGED
@@ -31,9 +31,10 @@ class RegexpTest < Test::Unit::TestCase
|
|
31
31
|
def test_variable_parser
|
32
32
|
assert_equal ['var'], 'var'.scan(VariableParser)
|
33
33
|
assert_equal ['var', 'method'], 'var.method'.scan(VariableParser)
|
34
|
-
assert_equal ['var', 'method'], 'var[method]'.scan(VariableParser)
|
35
|
-
assert_equal ['var', 'method', '0'], 'var[method][0]'.scan(VariableParser)
|
36
|
-
assert_equal ['var', 'method', '0'
|
34
|
+
assert_equal ['var', '[method]'], 'var[method]'.scan(VariableParser)
|
35
|
+
assert_equal ['var', '[method]', '[0]'], 'var[method][0]'.scan(VariableParser)
|
36
|
+
assert_equal ['var', '["method"]', '[0]'], 'var["method"][0]'.scan(VariableParser)
|
37
|
+
assert_equal ['var', '[method]', '[0]', 'method'], 'var[method][0].method'.scan(VariableParser)
|
37
38
|
end
|
38
39
|
|
39
40
|
end
|
@@ -42,10 +42,16 @@ class StandardFiltersTest < Test::Unit::TestCase
|
|
42
42
|
assert_equal '1234567890', @filters.truncate('1234567890')
|
43
43
|
end
|
44
44
|
|
45
|
+
def test_escape
|
46
|
+
assert_equal '<strong>', @filters.escape('<strong>')
|
47
|
+
assert_equal '<strong>', @filters.h('<strong>')
|
48
|
+
end
|
49
|
+
|
45
50
|
def test_truncatewords
|
46
51
|
assert_equal 'one two three', @filters.truncatewords('one two three', 4)
|
47
52
|
assert_equal 'one two...', @filters.truncatewords('one two three', 2)
|
48
|
-
assert_equal 'one two three', @filters.truncatewords('one two three')
|
53
|
+
assert_equal 'one two three', @filters.truncatewords('one two three')
|
54
|
+
assert_equal 'Two small (13” x 5.5” x 10” high) baskets fit inside one large basket (13”...', @filters.truncatewords('Two small (13” x 5.5” x 10” high) baskets fit inside one large basket (13” x 16” x 10.5” high) with cover.', 15)
|
49
55
|
end
|
50
56
|
|
51
57
|
def test_strip_html
|
@@ -78,6 +84,9 @@ class StandardFiltersTest < Test::Unit::TestCase
|
|
78
84
|
assert_equal '2006-07-05 10:00:00', @filters.date("2006-07-05 10:00:00", nil)
|
79
85
|
|
80
86
|
assert_equal '07/05/2006', @filters.date("2006-07-05 10:00:00", "%m/%d/%Y")
|
87
|
+
|
88
|
+
assert_equal "07/16/2004", @filters.date("Fri Jul 16 01:00:00 EDT 2004", "%m/%d/%Y")
|
89
|
+
|
81
90
|
assert_equal nil, @filters.date(nil, "%B")
|
82
91
|
end
|
83
92
|
|
@@ -89,9 +98,25 @@ class StandardFiltersTest < Test::Unit::TestCase
|
|
89
98
|
assert_equal nil, @filters.last([])
|
90
99
|
end
|
91
100
|
|
101
|
+
def test_replace
|
102
|
+
assert_equal 'b b b b', @filters.replace("a a a a", 'a', 'b')
|
103
|
+
assert_equal 'b a a a', @filters.replace_first("a a a a", 'a', 'b')
|
104
|
+
assert_template_result 'b a a a', "{{ 'a a a a' | replace_first: 'a', 'b' }}"
|
105
|
+
end
|
92
106
|
|
107
|
+
def test_remove
|
108
|
+
assert_equal ' ', @filters.remove("a a a a", 'a')
|
109
|
+
assert_equal 'a a a', @filters.remove_first("a a a a", 'a ')
|
110
|
+
assert_template_result 'a a a', "{{ 'a a a a' | remove_first: 'a ' }}"
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_strip_newlines
|
114
|
+
assert_template_result 'abc', "{{ source | strip_newlines }}", 'source' => "a\nb\nc"
|
115
|
+
end
|
93
116
|
|
94
|
-
|
117
|
+
def test_newlines_to_br
|
118
|
+
assert_template_result "a<br />\nb<br />\nc", "{{ source | newline_to_br }}", 'source' => "a\nb\nc"
|
119
|
+
end
|
95
120
|
|
96
121
|
|
97
122
|
|
data/test/standard_tag_test.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/helper'
|
2
2
|
|
3
3
|
|
4
|
-
class
|
4
|
+
class StandardTagTest < Test::Unit::TestCase
|
5
5
|
include Liquid
|
6
6
|
|
7
7
|
|
8
8
|
def test_tag
|
9
|
-
tag = Tag.new([], [])
|
9
|
+
tag = Tag.new('tag', [], [])
|
10
10
|
assert_equal 'liquid::tag', tag.name
|
11
|
-
assert_equal '', tag.render(Context.new
|
11
|
+
assert_equal '', tag.render(Context.new)
|
12
12
|
end
|
13
13
|
|
14
14
|
def test_no_transform
|
@@ -69,6 +69,10 @@ HERE
|
|
69
69
|
HERE
|
70
70
|
assert_template_result(expected,template,'array' => [1,2,3])
|
71
71
|
end
|
72
|
+
|
73
|
+
def test_for_with_range
|
74
|
+
assert_template_result(' 1 2 3 ','{%for item in (1..3) %} {{item}} {%endfor%}')
|
75
|
+
end
|
72
76
|
|
73
77
|
def test_for_with_variable
|
74
78
|
assert_template_result(' 1 2 3 ','{%for item in array%} {{item}} {%endfor%}','array' => [1,2,3])
|
@@ -92,15 +96,7 @@ HERE
|
|
92
96
|
|
93
97
|
def test_for_and_if
|
94
98
|
assigns = {'array' => [1,2,3] }
|
95
|
-
assert_template_result('
|
96
|
-
'{%for item in array%} {% if forloop.first %}yay{% endif %} {%endfor%}',
|
97
|
-
assigns)
|
98
|
-
assert_template_result(' yay boo boo ',
|
99
|
-
'{%for item in array%} {% if forloop.first %}yay{% else %}boo{% endif %} {%endfor%}',
|
100
|
-
assigns)
|
101
|
-
assert_template_result(' boo boo ',
|
102
|
-
'{%for item in array%} {% if forloop.first %}{% else %}boo{% endif %} {%endfor%}',
|
103
|
-
assigns)
|
99
|
+
assert_template_result('+--', '{%for item in array%}{% if forloop.first %}+{% else %}-{% endif %}{%endfor%}', assigns)
|
104
100
|
end
|
105
101
|
|
106
102
|
def test_limiting
|
@@ -185,20 +181,16 @@ HERE
|
|
185
181
|
|
186
182
|
def test_pause_resume_BIG_offset
|
187
183
|
assigns = {'array' => {'items' => [1,2,3,4,5,6,7,8,9,0]}}
|
188
|
-
markup =
|
189
|
-
{%for i in array.items limit:3 %}{{i}}{%endfor%}
|
184
|
+
markup = %q({%for i in array.items limit:3 %}{{i}}{%endfor%}
|
190
185
|
next
|
191
186
|
{%for i in array.items offset:continue limit:3 %}{{i}}{%endfor%}
|
192
187
|
next
|
193
|
-
{%for i in array.items offset:continue limit:3 offset:1000 %}{{i}}{%endfor%}
|
194
|
-
|
195
|
-
expected = <<-XPCTD
|
196
|
-
123
|
188
|
+
{%for i in array.items offset:continue limit:3 offset:1000 %}{{i}}{%endfor%})
|
189
|
+
expected = %q(123
|
197
190
|
next
|
198
191
|
456
|
199
192
|
next
|
200
|
-
|
201
|
-
XPCTD
|
193
|
+
)
|
202
194
|
assert_template_result(expected,markup,assigns)
|
203
195
|
end
|
204
196
|
|
@@ -208,6 +200,12 @@ HERE
|
|
208
200
|
|
209
201
|
end
|
210
202
|
|
203
|
+
def test_hyphenated_assign
|
204
|
+
assigns = {'a-b' => '1' }
|
205
|
+
assert_template_result('a-b:1 a-b:2','a-b:{{a-b}} {%assign a-b = 2 %}a-b:{{a-b}}',assigns)
|
206
|
+
|
207
|
+
end
|
208
|
+
|
211
209
|
def test_capture
|
212
210
|
assigns = {'var' => 'content' }
|
213
211
|
assert_template_result('content foo content foo ','{{ var2 }}{% capture var2 %}{{ var }} foo {% endcapture %}{{ var2 }}{{ var2 }}', assigns)
|
@@ -275,6 +273,55 @@ HERE
|
|
275
273
|
assert_template_result('else', '{% case NULL %}{% when true %}true{% when false %}false{% else %}else{% endcase %}', {})
|
276
274
|
end
|
277
275
|
|
276
|
+
def test_assign_from_case
|
277
|
+
# Example from the shopify forums
|
278
|
+
code = %q({% case collection.handle %}{% when 'menswear-jackets' %}{% assign ptitle = 'menswear' %}{% when 'menswear-t-shirts' %}{% assign ptitle = 'menswear' %}{% else %}{% assign ptitle = 'womenswear' %}{% endcase %}{{ ptitle }})
|
279
|
+
template = Liquid::Template.parse(code)
|
280
|
+
assert_equal "menswear", template.render("collection" => {'handle' => 'menswear-jackets'})
|
281
|
+
assert_equal "menswear", template.render("collection" => {'handle' => 'menswear-t-shirts'})
|
282
|
+
assert_equal "womenswear", template.render("collection" => {'handle' => 'x'})
|
283
|
+
assert_equal "womenswear", template.render("collection" => {'handle' => 'y'})
|
284
|
+
assert_equal "womenswear", template.render("collection" => {'handle' => 'z'})
|
285
|
+
end
|
286
|
+
|
287
|
+
def test_case_when_or
|
288
|
+
code = '{% case condition %}{% when 1 or 2 or 3 %} its 1 or 2 or 3 {% when 4 %} its 4 {% endcase %}'
|
289
|
+
assert_template_result(' its 1 or 2 or 3 ', code, {'condition' => 1 })
|
290
|
+
assert_template_result(' its 1 or 2 or 3 ', code, {'condition' => 2 })
|
291
|
+
assert_template_result(' its 1 or 2 or 3 ', code, {'condition' => 3 })
|
292
|
+
assert_template_result(' its 4 ', code, {'condition' => 4 })
|
293
|
+
assert_template_result('', code, {'condition' => 5 })
|
294
|
+
|
295
|
+
code = '{% case condition %}{% when 1 or "string" or null %} its 1 or 2 or 3 {% when 4 %} its 4 {% endcase %}'
|
296
|
+
assert_template_result(' its 1 or 2 or 3 ', code, {'condition' => 1 })
|
297
|
+
assert_template_result(' its 1 or 2 or 3 ', code, {'condition' => 'string' })
|
298
|
+
assert_template_result(' its 1 or 2 or 3 ', code, {'condition' => nil })
|
299
|
+
assert_template_result('', code, {'condition' => 'something else' })
|
300
|
+
end
|
301
|
+
|
302
|
+
def test_case_when_comma
|
303
|
+
code = '{% case condition %}{% when 1, 2, 3 %} its 1 or 2 or 3 {% when 4 %} its 4 {% endcase %}'
|
304
|
+
assert_template_result(' its 1 or 2 or 3 ', code, {'condition' => 1 })
|
305
|
+
assert_template_result(' its 1 or 2 or 3 ', code, {'condition' => 2 })
|
306
|
+
assert_template_result(' its 1 or 2 or 3 ', code, {'condition' => 3 })
|
307
|
+
assert_template_result(' its 4 ', code, {'condition' => 4 })
|
308
|
+
assert_template_result('', code, {'condition' => 5 })
|
309
|
+
|
310
|
+
code = '{% case condition %}{% when 1, "string", null %} its 1 or 2 or 3 {% when 4 %} its 4 {% endcase %}'
|
311
|
+
assert_template_result(' its 1 or 2 or 3 ', code, {'condition' => 1 })
|
312
|
+
assert_template_result(' its 1 or 2 or 3 ', code, {'condition' => 'string' })
|
313
|
+
assert_template_result(' its 1 or 2 or 3 ', code, {'condition' => nil })
|
314
|
+
assert_template_result('', code, {'condition' => 'something else' })
|
315
|
+
end
|
316
|
+
|
317
|
+
def test_assign
|
318
|
+
assert_equal 'variable', Liquid::Template.parse( '{% assign a = "variable"%}{{a}}' ).render
|
319
|
+
end
|
320
|
+
|
321
|
+
def test_assign_is_global
|
322
|
+
assert_equal 'variable', Liquid::Template.parse( '{%for i in (1..2) %}{% assign a = "variable"%}{% endfor %}{{a}}' ).render
|
323
|
+
end
|
324
|
+
|
278
325
|
def test_case_detects_bad_syntax
|
279
326
|
assert_raise(SyntaxError) do
|
280
327
|
assert_template_result('', '{% case false %}{% when %}true{% endcase %}', {})
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__)+ '/extra')
|
3
|
+
|
4
|
+
require 'test/unit'
|
5
|
+
require 'test/unit/assertions'
|
6
|
+
require 'caller'
|
7
|
+
require 'breakpoint'
|
8
|
+
require File.dirname(__FILE__) + '/../lib/liquid'
|
9
|
+
|
10
|
+
|
11
|
+
module Test
|
12
|
+
module Unit
|
13
|
+
module Assertions
|
14
|
+
include Liquid
|
15
|
+
def assert_template_result(expected, template, assigns={}, message=nil)
|
16
|
+
assert_equal expected, Template.parse(template).render(assigns)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/test/unless_else_test.rb
CHANGED
@@ -16,4 +16,12 @@ class UnlessElseTest < Test::Unit::TestCase
|
|
16
16
|
assert_template_result(' YES ','{% unless "foo" %} NO {% else %} YES {% endunless %}')
|
17
17
|
end
|
18
18
|
|
19
|
+
def test_unless_in_loop
|
20
|
+
assert_template_result '23', '{% for i in choices %}{% unless i %}{{ forloop.index }}{% endunless %}{% endfor %}', 'choices' => [1, nil, false]
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_unless_else_in_loop
|
24
|
+
assert_template_result ' TRUE 2 3 ', '{% for i in choices %}{% unless i %} {{ forloop.index }} {% else %} TRUE {% endunless %}{% endfor %}', 'choices' => [1, nil, false]
|
25
|
+
end
|
26
|
+
|
19
27
|
end
|
metadata
CHANGED
@@ -1,39 +1,42 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.0
|
3
|
-
specification_version: 1
|
4
2
|
name: liquid
|
5
3
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 1.
|
7
|
-
date: 2006-10-09 00:00:00 -04:00
|
8
|
-
summary: A secure non evaling end user template engine with aesthetic markup.
|
9
|
-
require_paths:
|
10
|
-
- lib
|
11
|
-
- test
|
12
|
-
email: tobi@leetsoft.com
|
13
|
-
homepage: http://home.leetsoft.com/liquid
|
14
|
-
rubyforge_project: liquid
|
15
|
-
description:
|
16
|
-
autorequire:
|
17
|
-
default_executable:
|
18
|
-
bindir: bin
|
19
|
-
has_rdoc: true
|
20
|
-
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
21
|
-
requirements:
|
22
|
-
- - ">"
|
23
|
-
- !ruby/object:Gem::Version
|
24
|
-
version: 0.0.0
|
25
|
-
version:
|
4
|
+
version: 1.9.0
|
26
5
|
platform: ruby
|
27
|
-
signing_key:
|
28
|
-
cert_chain:
|
29
|
-
post_install_message:
|
30
6
|
authors:
|
31
7
|
- Tobias Luetke
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-05-04 00:00:00 -04:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: hoe
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.5.1
|
23
|
+
version:
|
24
|
+
description: A secure non evaling end user template engine with aesthetic markup.
|
25
|
+
email: tobi@leetsoft.com
|
26
|
+
executables: []
|
27
|
+
|
28
|
+
extensions: []
|
29
|
+
|
30
|
+
extra_rdoc_files:
|
31
|
+
- History.txt
|
32
|
+
- Manifest.txt
|
33
|
+
- README.txt
|
32
34
|
files:
|
33
35
|
- CHANGELOG
|
36
|
+
- History.txt
|
34
37
|
- MIT-LICENSE
|
35
38
|
- Manifest.txt
|
36
|
-
- README
|
39
|
+
- README.txt
|
37
40
|
- Rakefile
|
38
41
|
- example/server/example_servlet.rb
|
39
42
|
- example/server/liquid_servlet.rb
|
@@ -52,6 +55,7 @@ files:
|
|
52
55
|
- lib/liquid/extensions.rb
|
53
56
|
- lib/liquid/file_system.rb
|
54
57
|
- lib/liquid/htmltags.rb
|
58
|
+
- lib/liquid/module_ex.rb
|
55
59
|
- lib/liquid/standardfilters.rb
|
56
60
|
- lib/liquid/strainer.rb
|
57
61
|
- lib/liquid/tag.rb
|
@@ -68,6 +72,7 @@ files:
|
|
68
72
|
- lib/liquid/template.rb
|
69
73
|
- lib/liquid/variable.rb
|
70
74
|
- test/block_test.rb
|
75
|
+
- test/condition_test.rb
|
71
76
|
- test/context_test.rb
|
72
77
|
- test/drop_test.rb
|
73
78
|
- test/error_handling_test.rb
|
@@ -79,6 +84,7 @@ files:
|
|
79
84
|
- test/html_tag_test.rb
|
80
85
|
- test/if_else_test.rb
|
81
86
|
- test/include_tag_test.rb
|
87
|
+
- test/module_ex_test.rb
|
82
88
|
- test/output_test.rb
|
83
89
|
- test/parsing_quirks_test.rb
|
84
90
|
- test/regexp_test.rb
|
@@ -88,27 +94,35 @@ files:
|
|
88
94
|
- test/statements_test.rb
|
89
95
|
- test/strainer_test.rb
|
90
96
|
- test/template_test.rb
|
97
|
+
- test/test_helper.rb
|
91
98
|
- test/unless_else_test.rb
|
92
99
|
- test/variable_test.rb
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
100
|
+
has_rdoc: true
|
101
|
+
homepage: http://www.liquidmarkup.org
|
102
|
+
post_install_message:
|
103
|
+
rdoc_options:
|
104
|
+
- --main
|
105
|
+
- README.txt
|
106
|
+
require_paths:
|
107
|
+
- lib
|
108
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: "0"
|
113
|
+
version:
|
114
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: "0"
|
119
|
+
version:
|
103
120
|
requirements: []
|
104
121
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
- !ruby/object:Gem::Version
|
113
|
-
version: 1.1.0
|
114
|
-
version:
|
122
|
+
rubyforge_project: liquid
|
123
|
+
rubygems_version: 1.1.0
|
124
|
+
signing_key:
|
125
|
+
specification_version: 2
|
126
|
+
summary: A secure non evaling end user template engine with aesthetic markup.
|
127
|
+
test_files:
|
128
|
+
- test/test_helper.rb
|