liquid 2.2.2 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/{History.txt → History.md} +26 -23
- data/README.md +18 -16
- data/lib/liquid.rb +1 -4
- data/lib/liquid/block.rb +2 -2
- data/lib/liquid/context.rb +29 -33
- data/lib/liquid/drop.rb +11 -13
- data/lib/liquid/extensions.rb +13 -7
- data/lib/liquid/file_system.rb +2 -2
- data/lib/liquid/htmltags.rb +5 -4
- data/lib/liquid/standardfilters.rb +12 -1
- data/lib/liquid/strainer.rb +1 -1
- data/lib/liquid/tags/capture.rb +1 -1
- data/lib/liquid/tags/case.rb +4 -8
- data/lib/liquid/tags/decrement.rb +39 -0
- data/lib/liquid/tags/for.rb +20 -5
- data/lib/liquid/tags/include.rb +21 -12
- data/lib/liquid/tags/increment.rb +35 -0
- data/lib/liquid/tags/raw.rb +21 -0
- data/lib/liquid/tags/unless.rb +5 -5
- data/lib/liquid/template.rb +3 -2
- data/lib/liquid/variable.rb +1 -1
- data/test/liquid/assign_test.rb +15 -0
- data/test/liquid/block_test.rb +58 -0
- data/test/liquid/capture_test.rb +40 -0
- data/test/liquid/condition_test.rb +122 -0
- data/test/liquid/context_test.rb +478 -0
- data/test/liquid/drop_test.rb +162 -0
- data/test/liquid/error_handling_test.rb +81 -0
- data/test/liquid/file_system_test.rb +29 -0
- data/test/liquid/filter_test.rb +106 -0
- data/test/liquid/module_ex_test.rb +87 -0
- data/test/liquid/output_test.rb +116 -0
- data/test/liquid/parsing_quirks_test.rb +52 -0
- data/test/liquid/regexp_test.rb +44 -0
- data/test/liquid/security_test.rb +41 -0
- data/test/liquid/standard_filter_test.rb +191 -0
- data/test/liquid/strainer_test.rb +25 -0
- data/test/liquid/tags/html_tag_test.rb +29 -0
- data/test/liquid/tags/if_else_tag_test.rb +160 -0
- data/test/liquid/tags/include_tag_test.rb +139 -0
- data/test/liquid/tags/increment_tag_test.rb +24 -0
- data/test/liquid/tags/raw_tag_test.rb +15 -0
- data/test/liquid/tags/standard_tag_test.rb +461 -0
- data/test/liquid/tags/statements_test.rb +134 -0
- data/test/liquid/tags/unless_else_tag_test.rb +26 -0
- data/test/liquid/template_test.rb +74 -0
- data/test/liquid/variable_test.rb +170 -0
- data/test/test_helper.rb +29 -0
- metadata +67 -16
- data/Manifest.txt +0 -34
- data/lib/liquid/tags/literal.rb +0 -42
@@ -0,0 +1,134 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class StatementsTest < Test::Unit::TestCase
|
4
|
+
include Liquid
|
5
|
+
|
6
|
+
def test_true_eql_true
|
7
|
+
text = %| {% if true == true %} true {% else %} false {% endif %} |
|
8
|
+
expected = %| true |
|
9
|
+
assert_equal expected, Template.parse(text).render
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_true_not_eql_true
|
13
|
+
text = %| {% if true != true %} true {% else %} false {% endif %} |
|
14
|
+
expected = %| false |
|
15
|
+
assert_equal expected, Template.parse(text).render
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_true_lq_true
|
19
|
+
text = %| {% if 0 > 0 %} true {% else %} false {% endif %} |
|
20
|
+
expected = %| false |
|
21
|
+
assert_equal expected, Template.parse(text).render
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_one_lq_zero
|
25
|
+
text = %| {% if 1 > 0 %} true {% else %} false {% endif %} |
|
26
|
+
expected = %| true |
|
27
|
+
assert_equal expected, Template.parse(text).render
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_zero_lq_one
|
31
|
+
text = %| {% if 0 < 1 %} true {% else %} false {% endif %} |
|
32
|
+
expected = %| true |
|
33
|
+
assert_equal expected, Template.parse(text).render
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_zero_lq_or_equal_one
|
37
|
+
text = %| {% if 0 <= 0 %} true {% else %} false {% endif %} |
|
38
|
+
expected = %| true |
|
39
|
+
assert_equal expected, Template.parse(text).render
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_zero_lq_or_equal_one_involving_nil
|
43
|
+
text = %| {% if null <= 0 %} true {% else %} false {% endif %} |
|
44
|
+
expected = %| false |
|
45
|
+
assert_equal expected, Template.parse(text).render
|
46
|
+
|
47
|
+
|
48
|
+
text = %| {% if 0 <= null %} true {% else %} false {% endif %} |
|
49
|
+
expected = %| false |
|
50
|
+
assert_equal expected, Template.parse(text).render
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_zero_lqq_or_equal_one
|
54
|
+
text = %| {% if 0 >= 0 %} true {% else %} false {% endif %} |
|
55
|
+
expected = %| true |
|
56
|
+
assert_equal expected, Template.parse(text).render
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_strings
|
60
|
+
text = %| {% if 'test' == 'test' %} true {% else %} false {% endif %} |
|
61
|
+
expected = %| true |
|
62
|
+
assert_equal expected, Template.parse(text).render
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_strings_not_equal
|
66
|
+
text = %| {% if 'test' != 'test' %} true {% else %} false {% endif %} |
|
67
|
+
expected = %| false |
|
68
|
+
assert_equal expected, Template.parse(text).render
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_var_strings_equal
|
72
|
+
text = %| {% if var == "hello there!" %} true {% else %} false {% endif %} |
|
73
|
+
expected = %| true |
|
74
|
+
assert_equal expected, Template.parse(text).render('var' => 'hello there!')
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_var_strings_are_not_equal
|
78
|
+
text = %| {% if "hello there!" == var %} true {% else %} false {% endif %} |
|
79
|
+
expected = %| true |
|
80
|
+
assert_equal expected, Template.parse(text).render('var' => 'hello there!')
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_var_and_long_string_are_equal
|
84
|
+
text = %| {% if var == 'hello there!' %} true {% else %} false {% endif %} |
|
85
|
+
expected = %| true |
|
86
|
+
assert_equal expected, Template.parse(text).render('var' => 'hello there!')
|
87
|
+
end
|
88
|
+
|
89
|
+
|
90
|
+
def test_var_and_long_string_are_equal_backwards
|
91
|
+
text = %| {% if 'hello there!' == var %} true {% else %} false {% endif %} |
|
92
|
+
expected = %| true |
|
93
|
+
assert_equal expected, Template.parse(text).render('var' => 'hello there!')
|
94
|
+
end
|
95
|
+
|
96
|
+
#def test_is_nil
|
97
|
+
# text = %| {% if var != nil %} true {% else %} false {% end %} |
|
98
|
+
# @template.assigns = { 'var' => 'hello there!'}
|
99
|
+
# expected = %| true |
|
100
|
+
# assert_equal expected, @template.parse(text)
|
101
|
+
#end
|
102
|
+
|
103
|
+
def test_is_collection_empty
|
104
|
+
text = %| {% if array == empty %} true {% else %} false {% endif %} |
|
105
|
+
expected = %| true |
|
106
|
+
assert_equal expected, Template.parse(text).render('array' => [])
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_is_not_collection_empty
|
110
|
+
text = %| {% if array == empty %} true {% else %} false {% endif %} |
|
111
|
+
expected = %| false |
|
112
|
+
assert_equal expected, Template.parse(text).render('array' => [1,2,3])
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_nil
|
116
|
+
text = %| {% if var == nil %} true {% else %} false {% endif %} |
|
117
|
+
expected = %| true |
|
118
|
+
assert_equal expected, Template.parse(text).render('var' => nil)
|
119
|
+
|
120
|
+
text = %| {% if var == null %} true {% else %} false {% endif %} |
|
121
|
+
expected = %| true |
|
122
|
+
assert_equal expected, Template.parse(text).render('var' => nil)
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_not_nil
|
126
|
+
text = %| {% if var != nil %} true {% else %} false {% endif %} |
|
127
|
+
expected = %| true |
|
128
|
+
assert_equal expected, Template.parse(text).render('var' => 1 )
|
129
|
+
|
130
|
+
text = %| {% if var != null %} true {% else %} false {% endif %} |
|
131
|
+
expected = %| true |
|
132
|
+
assert_equal expected, Template.parse(text).render('var' => 1 )
|
133
|
+
end
|
134
|
+
end # StatementsTest
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class UnlessElseTagTest < Test::Unit::TestCase
|
4
|
+
include Liquid
|
5
|
+
|
6
|
+
def test_unless
|
7
|
+
assert_template_result(' ',' {% unless true %} this text should not go into the output {% endunless %} ')
|
8
|
+
assert_template_result(' this text should go into the output ',
|
9
|
+
' {% unless false %} this text should go into the output {% endunless %} ')
|
10
|
+
assert_template_result(' you rock ?','{% unless true %} you suck {% endunless %} {% unless false %} you rock {% endunless %}?')
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_unless_else
|
14
|
+
assert_template_result(' YES ','{% unless true %} NO {% else %} YES {% endunless %}')
|
15
|
+
assert_template_result(' YES ','{% unless false %} YES {% else %} NO {% endunless %}')
|
16
|
+
assert_template_result(' YES ','{% unless "foo" %} NO {% else %} YES {% endunless %}')
|
17
|
+
end
|
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
|
+
end # UnlessElseTest
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TemplateTest < Test::Unit::TestCase
|
4
|
+
include Liquid
|
5
|
+
|
6
|
+
def test_tokenize_strings
|
7
|
+
assert_equal [' '], Template.new.send(:tokenize, ' ')
|
8
|
+
assert_equal ['hello world'], Template.new.send(:tokenize, 'hello world')
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_tokenize_variables
|
12
|
+
assert_equal ['{{funk}}'], Template.new.send(:tokenize, '{{funk}}')
|
13
|
+
assert_equal [' ', '{{funk}}', ' '], Template.new.send(:tokenize, ' {{funk}} ')
|
14
|
+
assert_equal [' ', '{{funk}}', ' ', '{{so}}', ' ', '{{brother}}', ' '], Template.new.send(:tokenize, ' {{funk}} {{so}} {{brother}} ')
|
15
|
+
assert_equal [' ', '{{ funk }}', ' '], Template.new.send(:tokenize, ' {{ funk }} ')
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_tokenize_blocks
|
19
|
+
assert_equal ['{%comment%}'], Template.new.send(:tokenize, '{%comment%}')
|
20
|
+
assert_equal [' ', '{%comment%}', ' '], Template.new.send(:tokenize, ' {%comment%} ')
|
21
|
+
|
22
|
+
assert_equal [' ', '{%comment%}', ' ', '{%endcomment%}', ' '], Template.new.send(:tokenize, ' {%comment%} {%endcomment%} ')
|
23
|
+
assert_equal [' ', '{% comment %}', ' ', '{% endcomment %}', ' '], Template.new.send(:tokenize, " {% comment %} {% endcomment %} ")
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_instance_assigns_persist_on_same_template_object_between_parses
|
27
|
+
t = Template.new
|
28
|
+
assert_equal 'from instance assigns', t.parse("{% assign foo = 'from instance assigns' %}{{ foo }}").render
|
29
|
+
assert_equal 'from instance assigns', t.parse("{{ foo }}").render
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_instance_assigns_persist_on_same_template_parsing_between_renders
|
33
|
+
t = Template.new.parse("{{ foo }}{% assign foo = 'foo' %}{{ foo }}")
|
34
|
+
assert_equal 'foo', t.render
|
35
|
+
assert_equal 'foofoo', t.render
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_custom_assigns_do_not_persist_on_same_template
|
39
|
+
t = Template.new
|
40
|
+
assert_equal 'from custom assigns', t.parse("{{ foo }}").render('foo' => 'from custom assigns')
|
41
|
+
assert_equal '', t.parse("{{ foo }}").render
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_custom_assigns_squash_instance_assigns
|
45
|
+
t = Template.new
|
46
|
+
assert_equal 'from instance assigns', t.parse("{% assign foo = 'from instance assigns' %}{{ foo }}").render
|
47
|
+
assert_equal 'from custom assigns', t.parse("{{ foo }}").render('foo' => 'from custom assigns')
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_persistent_assigns_squash_instance_assigns
|
51
|
+
t = Template.new
|
52
|
+
assert_equal 'from instance assigns', t.parse("{% assign foo = 'from instance assigns' %}{{ foo }}").render
|
53
|
+
t.assigns['foo'] = 'from persistent assigns'
|
54
|
+
assert_equal 'from persistent assigns', t.parse("{{ foo }}").render
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_lambda_is_called_once_from_persistent_assigns_over_multiple_parses_and_renders
|
58
|
+
t = Template.new
|
59
|
+
t.assigns['number'] = lambda { @global ||= 0; @global += 1 }
|
60
|
+
assert_equal '1', t.parse("{{number}}").render
|
61
|
+
assert_equal '1', t.parse("{{number}}").render
|
62
|
+
assert_equal '1', t.render
|
63
|
+
@global = nil
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_lambda_is_called_once_from_custom_assigns_over_multiple_parses_and_renders
|
67
|
+
t = Template.new
|
68
|
+
assigns = {'number' => lambda { @global ||= 0; @global += 1 }}
|
69
|
+
assert_equal '1', t.parse("{{number}}").render(assigns)
|
70
|
+
assert_equal '1', t.parse("{{number}}").render(assigns)
|
71
|
+
assert_equal '1', t.render(assigns)
|
72
|
+
@global = nil
|
73
|
+
end
|
74
|
+
end # TemplateTest
|
@@ -0,0 +1,170 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class VariableTest < Test::Unit::TestCase
|
4
|
+
include Liquid
|
5
|
+
|
6
|
+
def test_variable
|
7
|
+
var = Variable.new('hello')
|
8
|
+
assert_equal 'hello', var.name
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_filters
|
12
|
+
var = Variable.new('hello | textileze')
|
13
|
+
assert_equal 'hello', var.name
|
14
|
+
assert_equal [[:textileze,[]]], var.filters
|
15
|
+
|
16
|
+
var = Variable.new('hello | textileze | paragraph')
|
17
|
+
assert_equal 'hello', var.name
|
18
|
+
assert_equal [[:textileze,[]], [:paragraph,[]]], var.filters
|
19
|
+
|
20
|
+
var = Variable.new(%! hello | strftime: '%Y'!)
|
21
|
+
assert_equal 'hello', var.name
|
22
|
+
assert_equal [[:strftime,["'%Y'"]]], var.filters
|
23
|
+
|
24
|
+
var = Variable.new(%! 'typo' | link_to: 'Typo', true !)
|
25
|
+
assert_equal %!'typo'!, var.name
|
26
|
+
assert_equal [[:link_to,["'Typo'", "true"]]], var.filters
|
27
|
+
|
28
|
+
var = Variable.new(%! 'typo' | link_to: 'Typo', false !)
|
29
|
+
assert_equal %!'typo'!, var.name
|
30
|
+
assert_equal [[:link_to,["'Typo'", "false"]]], var.filters
|
31
|
+
|
32
|
+
var = Variable.new(%! 'foo' | repeat: 3 !)
|
33
|
+
assert_equal %!'foo'!, var.name
|
34
|
+
assert_equal [[:repeat,["3"]]], var.filters
|
35
|
+
|
36
|
+
var = Variable.new(%! 'foo' | repeat: 3, 3 !)
|
37
|
+
assert_equal %!'foo'!, var.name
|
38
|
+
assert_equal [[:repeat,["3","3"]]], var.filters
|
39
|
+
|
40
|
+
var = Variable.new(%! 'foo' | repeat: 3, 3, 3 !)
|
41
|
+
assert_equal %!'foo'!, var.name
|
42
|
+
assert_equal [[:repeat,["3","3","3"]]], var.filters
|
43
|
+
|
44
|
+
var = Variable.new(%! hello | strftime: '%Y, okay?'!)
|
45
|
+
assert_equal 'hello', var.name
|
46
|
+
assert_equal [[:strftime,["'%Y, okay?'"]]], var.filters
|
47
|
+
|
48
|
+
var = Variable.new(%! hello | things: "%Y, okay?", 'the other one'!)
|
49
|
+
assert_equal 'hello', var.name
|
50
|
+
assert_equal [[:things,["\"%Y, okay?\"","'the other one'"]]], var.filters
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_filter_with_date_parameter
|
54
|
+
|
55
|
+
var = Variable.new(%! '2006-06-06' | date: "%m/%d/%Y"!)
|
56
|
+
assert_equal "'2006-06-06'", var.name
|
57
|
+
assert_equal [[:date,["\"%m/%d/%Y\""]]], var.filters
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_filters_without_whitespace
|
62
|
+
var = Variable.new('hello | textileze | paragraph')
|
63
|
+
assert_equal 'hello', var.name
|
64
|
+
assert_equal [[:textileze,[]], [:paragraph,[]]], var.filters
|
65
|
+
|
66
|
+
var = Variable.new('hello|textileze|paragraph')
|
67
|
+
assert_equal 'hello', var.name
|
68
|
+
assert_equal [[:textileze,[]], [:paragraph,[]]], var.filters
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_symbol
|
72
|
+
var = Variable.new("http://disney.com/logo.gif | image: 'med' ")
|
73
|
+
assert_equal 'http://disney.com/logo.gif', var.name
|
74
|
+
assert_equal [[:image,["'med'"]]], var.filters
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_string_single_quoted
|
78
|
+
var = Variable.new(%| "hello" |)
|
79
|
+
assert_equal '"hello"', var.name
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_string_double_quoted
|
83
|
+
var = Variable.new(%| 'hello' |)
|
84
|
+
assert_equal "'hello'", var.name
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_integer
|
88
|
+
var = Variable.new(%| 1000 |)
|
89
|
+
assert_equal "1000", var.name
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_float
|
93
|
+
var = Variable.new(%| 1000.01 |)
|
94
|
+
assert_equal "1000.01", var.name
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_string_with_special_chars
|
98
|
+
var = Variable.new(%| 'hello! $!@.;"ddasd" ' |)
|
99
|
+
assert_equal %|'hello! $!@.;"ddasd" '|, var.name
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_string_dot
|
103
|
+
var = Variable.new(%| test.test |)
|
104
|
+
assert_equal 'test.test', var.name
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
|
109
|
+
class VariableResolutionTest < Test::Unit::TestCase
|
110
|
+
include Liquid
|
111
|
+
|
112
|
+
def test_simple_variable
|
113
|
+
template = Template.parse(%|{{test}}|)
|
114
|
+
assert_equal 'worked', template.render('test' => 'worked')
|
115
|
+
assert_equal 'worked wonderfully', template.render('test' => 'worked wonderfully')
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_simple_with_whitespaces
|
119
|
+
template = Template.parse(%| {{ test }} |)
|
120
|
+
assert_equal ' worked ', template.render('test' => 'worked')
|
121
|
+
assert_equal ' worked wonderfully ', template.render('test' => 'worked wonderfully')
|
122
|
+
end
|
123
|
+
|
124
|
+
def test_ignore_unknown
|
125
|
+
template = Template.parse(%|{{ test }}|)
|
126
|
+
assert_equal '', template.render
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_hash_scoping
|
130
|
+
template = Template.parse(%|{{ test.test }}|)
|
131
|
+
assert_equal 'worked', template.render('test' => {'test' => 'worked'})
|
132
|
+
end
|
133
|
+
|
134
|
+
def test_preset_assigns
|
135
|
+
template = Template.parse(%|{{ test }}|)
|
136
|
+
template.assigns['test'] = 'worked'
|
137
|
+
assert_equal 'worked', template.render
|
138
|
+
end
|
139
|
+
|
140
|
+
def test_reuse_parsed_template
|
141
|
+
template = Template.parse(%|{{ greeting }} {{ name }}|)
|
142
|
+
template.assigns['greeting'] = 'Goodbye'
|
143
|
+
assert_equal 'Hello Tobi', template.render('greeting' => 'Hello', 'name' => 'Tobi')
|
144
|
+
assert_equal 'Hello ', template.render('greeting' => 'Hello', 'unknown' => 'Tobi')
|
145
|
+
assert_equal 'Hello Brian', template.render('greeting' => 'Hello', 'name' => 'Brian')
|
146
|
+
assert_equal 'Goodbye Brian', template.render('name' => 'Brian')
|
147
|
+
assert_equal({'greeting'=>'Goodbye'}, template.assigns)
|
148
|
+
end
|
149
|
+
|
150
|
+
def test_assigns_not_polluted_from_template
|
151
|
+
template = Template.parse(%|{{ test }}{% assign test = 'bar' %}{{ test }}|)
|
152
|
+
template.assigns['test'] = 'baz'
|
153
|
+
assert_equal 'bazbar', template.render
|
154
|
+
assert_equal 'bazbar', template.render
|
155
|
+
assert_equal 'foobar', template.render('test' => 'foo')
|
156
|
+
assert_equal 'bazbar', template.render
|
157
|
+
end
|
158
|
+
|
159
|
+
def test_hash_with_default_proc
|
160
|
+
template = Template.parse(%|Hello {{ test }}|)
|
161
|
+
assigns = Hash.new { |h,k| raise "Unknown variable '#{k}'" }
|
162
|
+
assigns['test'] = 'Tobi'
|
163
|
+
assert_equal 'Hello Tobi', template.render!(assigns)
|
164
|
+
assigns.delete('test')
|
165
|
+
e = assert_raises(RuntimeError) {
|
166
|
+
template.render!(assigns)
|
167
|
+
}
|
168
|
+
assert_equal "Unknown variable 'test'", e.message
|
169
|
+
end
|
170
|
+
end # VariableTest
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'test/unit/assertions'
|
5
|
+
begin
|
6
|
+
require 'ruby-debug'
|
7
|
+
rescue LoadError
|
8
|
+
puts "Couldn't load ruby-debug. gem install ruby-debug if you need it."
|
9
|
+
end
|
10
|
+
require File.join(File.dirname(__FILE__), '..', 'lib', 'liquid')
|
11
|
+
|
12
|
+
|
13
|
+
module Test
|
14
|
+
module Unit
|
15
|
+
module Assertions
|
16
|
+
include Liquid
|
17
|
+
|
18
|
+
def assert_template_result(expected, template, assigns = {}, message = nil)
|
19
|
+
assert_equal expected, Template.parse(template).render(assigns)
|
20
|
+
end
|
21
|
+
|
22
|
+
def assert_template_result_matches(expected, template, assigns = {}, message = nil)
|
23
|
+
return assert_template_result(expected, template, assigns, message) unless expected.is_a? Regexp
|
24
|
+
|
25
|
+
assert_match expected, Template.parse(template).render(assigns)
|
26
|
+
end
|
27
|
+
end # Assertions
|
28
|
+
end # Unit
|
29
|
+
end # Test
|
metadata
CHANGED
@@ -2,12 +2,12 @@
|
|
2
2
|
name: liquid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
hash: 3
|
5
|
-
prerelease:
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 2.
|
8
|
+
- 3
|
9
|
+
- 0
|
10
|
+
version: 2.3.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Tobias Luetke
|
@@ -15,11 +15,10 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
19
|
-
default_executable:
|
18
|
+
date: 2011-10-16 00:00:00 Z
|
20
19
|
dependencies: []
|
21
20
|
|
22
|
-
description:
|
21
|
+
description:
|
23
22
|
email:
|
24
23
|
- tobi@leetsoft.com
|
25
24
|
executables: []
|
@@ -27,8 +26,7 @@ executables: []
|
|
27
26
|
extensions: []
|
28
27
|
|
29
28
|
extra_rdoc_files:
|
30
|
-
- History.
|
31
|
-
- Manifest.txt
|
29
|
+
- History.md
|
32
30
|
- README.md
|
33
31
|
files:
|
34
32
|
- lib/extras/liquid_view.rb
|
@@ -50,20 +48,47 @@ files:
|
|
50
48
|
- lib/liquid/tags/case.rb
|
51
49
|
- lib/liquid/tags/comment.rb
|
52
50
|
- lib/liquid/tags/cycle.rb
|
51
|
+
- lib/liquid/tags/decrement.rb
|
53
52
|
- lib/liquid/tags/for.rb
|
54
53
|
- lib/liquid/tags/if.rb
|
55
54
|
- lib/liquid/tags/ifchanged.rb
|
56
55
|
- lib/liquid/tags/include.rb
|
57
|
-
- lib/liquid/tags/
|
56
|
+
- lib/liquid/tags/increment.rb
|
57
|
+
- lib/liquid/tags/raw.rb
|
58
58
|
- lib/liquid/tags/unless.rb
|
59
59
|
- lib/liquid/template.rb
|
60
60
|
- lib/liquid/variable.rb
|
61
61
|
- lib/liquid.rb
|
62
62
|
- MIT-LICENSE
|
63
63
|
- README.md
|
64
|
-
-
|
65
|
-
-
|
66
|
-
|
64
|
+
- test/liquid/assign_test.rb
|
65
|
+
- test/liquid/block_test.rb
|
66
|
+
- test/liquid/capture_test.rb
|
67
|
+
- test/liquid/condition_test.rb
|
68
|
+
- test/liquid/context_test.rb
|
69
|
+
- test/liquid/drop_test.rb
|
70
|
+
- test/liquid/error_handling_test.rb
|
71
|
+
- test/liquid/file_system_test.rb
|
72
|
+
- test/liquid/filter_test.rb
|
73
|
+
- test/liquid/module_ex_test.rb
|
74
|
+
- test/liquid/output_test.rb
|
75
|
+
- test/liquid/parsing_quirks_test.rb
|
76
|
+
- test/liquid/regexp_test.rb
|
77
|
+
- test/liquid/security_test.rb
|
78
|
+
- test/liquid/standard_filter_test.rb
|
79
|
+
- test/liquid/strainer_test.rb
|
80
|
+
- test/liquid/tags/html_tag_test.rb
|
81
|
+
- test/liquid/tags/if_else_tag_test.rb
|
82
|
+
- test/liquid/tags/include_tag_test.rb
|
83
|
+
- test/liquid/tags/increment_tag_test.rb
|
84
|
+
- test/liquid/tags/raw_tag_test.rb
|
85
|
+
- test/liquid/tags/standard_tag_test.rb
|
86
|
+
- test/liquid/tags/statements_test.rb
|
87
|
+
- test/liquid/tags/unless_else_tag_test.rb
|
88
|
+
- test/liquid/template_test.rb
|
89
|
+
- test/liquid/variable_test.rb
|
90
|
+
- test/test_helper.rb
|
91
|
+
- History.md
|
67
92
|
homepage: http://www.liquidmarkup.org
|
68
93
|
licenses: []
|
69
94
|
|
@@ -95,9 +120,35 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
95
120
|
requirements: []
|
96
121
|
|
97
122
|
rubyforge_project:
|
98
|
-
rubygems_version: 1.
|
123
|
+
rubygems_version: 1.8.11
|
99
124
|
signing_key:
|
100
125
|
specification_version: 3
|
101
126
|
summary: A secure, non-evaling end user template engine with aesthetic markup.
|
102
|
-
test_files:
|
103
|
-
|
127
|
+
test_files:
|
128
|
+
- test/liquid/assign_test.rb
|
129
|
+
- test/liquid/block_test.rb
|
130
|
+
- test/liquid/capture_test.rb
|
131
|
+
- test/liquid/condition_test.rb
|
132
|
+
- test/liquid/context_test.rb
|
133
|
+
- test/liquid/drop_test.rb
|
134
|
+
- test/liquid/error_handling_test.rb
|
135
|
+
- test/liquid/file_system_test.rb
|
136
|
+
- test/liquid/filter_test.rb
|
137
|
+
- test/liquid/module_ex_test.rb
|
138
|
+
- test/liquid/output_test.rb
|
139
|
+
- test/liquid/parsing_quirks_test.rb
|
140
|
+
- test/liquid/regexp_test.rb
|
141
|
+
- test/liquid/security_test.rb
|
142
|
+
- test/liquid/standard_filter_test.rb
|
143
|
+
- test/liquid/strainer_test.rb
|
144
|
+
- test/liquid/tags/html_tag_test.rb
|
145
|
+
- test/liquid/tags/if_else_tag_test.rb
|
146
|
+
- test/liquid/tags/include_tag_test.rb
|
147
|
+
- test/liquid/tags/increment_tag_test.rb
|
148
|
+
- test/liquid/tags/raw_tag_test.rb
|
149
|
+
- test/liquid/tags/standard_tag_test.rb
|
150
|
+
- test/liquid/tags/statements_test.rb
|
151
|
+
- test/liquid/tags/unless_else_tag_test.rb
|
152
|
+
- test/liquid/template_test.rb
|
153
|
+
- test/liquid/variable_test.rb
|
154
|
+
- test/test_helper.rb
|