liquid 2.6.3 → 5.4.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.
Files changed (100) hide show
  1. checksums.yaml +5 -5
  2. data/History.md +272 -26
  3. data/README.md +67 -3
  4. data/lib/liquid/block.rb +62 -94
  5. data/lib/liquid/block_body.rb +255 -0
  6. data/lib/liquid/condition.rb +96 -38
  7. data/lib/liquid/context.rb +172 -154
  8. data/lib/liquid/document.rb +57 -9
  9. data/lib/liquid/drop.rb +33 -14
  10. data/lib/liquid/errors.rb +56 -10
  11. data/lib/liquid/expression.rb +45 -0
  12. data/lib/liquid/extensions.rb +21 -7
  13. data/lib/liquid/file_system.rb +27 -14
  14. data/lib/liquid/forloop_drop.rb +92 -0
  15. data/lib/liquid/i18n.rb +41 -0
  16. data/lib/liquid/interrupts.rb +3 -2
  17. data/lib/liquid/lexer.rb +62 -0
  18. data/lib/liquid/locales/en.yml +29 -0
  19. data/lib/liquid/parse_context.rb +54 -0
  20. data/lib/liquid/parse_tree_visitor.rb +42 -0
  21. data/lib/liquid/parser.rb +102 -0
  22. data/lib/liquid/parser_switching.rb +45 -0
  23. data/lib/liquid/partial_cache.rb +24 -0
  24. data/lib/liquid/profiler/hooks.rb +35 -0
  25. data/lib/liquid/profiler.rb +139 -0
  26. data/lib/liquid/range_lookup.rb +47 -0
  27. data/lib/liquid/registers.rb +51 -0
  28. data/lib/liquid/resource_limits.rb +62 -0
  29. data/lib/liquid/standardfilters.rb +789 -118
  30. data/lib/liquid/strainer_factory.rb +41 -0
  31. data/lib/liquid/strainer_template.rb +62 -0
  32. data/lib/liquid/tablerowloop_drop.rb +121 -0
  33. data/lib/liquid/tag/disableable.rb +22 -0
  34. data/lib/liquid/tag/disabler.rb +21 -0
  35. data/lib/liquid/tag.rb +49 -10
  36. data/lib/liquid/tags/assign.rb +61 -19
  37. data/lib/liquid/tags/break.rb +14 -4
  38. data/lib/liquid/tags/capture.rb +29 -21
  39. data/lib/liquid/tags/case.rb +80 -31
  40. data/lib/liquid/tags/comment.rb +24 -2
  41. data/lib/liquid/tags/continue.rb +14 -13
  42. data/lib/liquid/tags/cycle.rb +50 -32
  43. data/lib/liquid/tags/decrement.rb +24 -26
  44. data/lib/liquid/tags/echo.rb +41 -0
  45. data/lib/liquid/tags/for.rb +164 -100
  46. data/lib/liquid/tags/if.rb +105 -44
  47. data/lib/liquid/tags/ifchanged.rb +10 -11
  48. data/lib/liquid/tags/include.rb +85 -65
  49. data/lib/liquid/tags/increment.rb +24 -22
  50. data/lib/liquid/tags/inline_comment.rb +43 -0
  51. data/lib/liquid/tags/raw.rb +50 -11
  52. data/lib/liquid/tags/render.rb +109 -0
  53. data/lib/liquid/tags/table_row.rb +88 -0
  54. data/lib/liquid/tags/unless.rb +37 -21
  55. data/lib/liquid/template.rb +124 -46
  56. data/lib/liquid/template_factory.rb +9 -0
  57. data/lib/liquid/tokenizer.rb +39 -0
  58. data/lib/liquid/usage.rb +8 -0
  59. data/lib/liquid/utils.rb +68 -5
  60. data/lib/liquid/variable.rb +128 -32
  61. data/lib/liquid/variable_lookup.rb +96 -0
  62. data/lib/liquid/version.rb +3 -1
  63. data/lib/liquid.rb +36 -13
  64. metadata +69 -77
  65. data/lib/extras/liquid_view.rb +0 -51
  66. data/lib/liquid/htmltags.rb +0 -73
  67. data/lib/liquid/module_ex.rb +0 -62
  68. data/lib/liquid/strainer.rb +0 -53
  69. data/test/liquid/assign_test.rb +0 -21
  70. data/test/liquid/block_test.rb +0 -58
  71. data/test/liquid/capture_test.rb +0 -40
  72. data/test/liquid/condition_test.rb +0 -127
  73. data/test/liquid/context_test.rb +0 -478
  74. data/test/liquid/drop_test.rb +0 -180
  75. data/test/liquid/error_handling_test.rb +0 -81
  76. data/test/liquid/file_system_test.rb +0 -29
  77. data/test/liquid/filter_test.rb +0 -125
  78. data/test/liquid/hash_ordering_test.rb +0 -25
  79. data/test/liquid/module_ex_test.rb +0 -87
  80. data/test/liquid/output_test.rb +0 -116
  81. data/test/liquid/parsing_quirks_test.rb +0 -52
  82. data/test/liquid/regexp_test.rb +0 -44
  83. data/test/liquid/security_test.rb +0 -64
  84. data/test/liquid/standard_filter_test.rb +0 -263
  85. data/test/liquid/strainer_test.rb +0 -52
  86. data/test/liquid/tags/break_tag_test.rb +0 -16
  87. data/test/liquid/tags/continue_tag_test.rb +0 -16
  88. data/test/liquid/tags/for_tag_test.rb +0 -297
  89. data/test/liquid/tags/html_tag_test.rb +0 -63
  90. data/test/liquid/tags/if_else_tag_test.rb +0 -166
  91. data/test/liquid/tags/include_tag_test.rb +0 -166
  92. data/test/liquid/tags/increment_tag_test.rb +0 -24
  93. data/test/liquid/tags/raw_tag_test.rb +0 -24
  94. data/test/liquid/tags/standard_tag_test.rb +0 -295
  95. data/test/liquid/tags/statements_test.rb +0 -134
  96. data/test/liquid/tags/unless_else_tag_test.rb +0 -26
  97. data/test/liquid/template_test.rb +0 -146
  98. data/test/liquid/variable_test.rb +0 -186
  99. data/test/test_helper.rb +0 -29
  100. /data/{MIT-LICENSE → LICENSE} +0 -0
@@ -1,63 +0,0 @@
1
- require 'test_helper'
2
-
3
- class HtmlTagTest < Test::Unit::TestCase
4
- include Liquid
5
-
6
- class ArrayDrop < Liquid::Drop
7
- include Enumerable
8
-
9
- def initialize(array)
10
- @array = array
11
- end
12
-
13
- def each(&block)
14
- @array.each(&block)
15
- end
16
- end
17
-
18
- def test_html_table
19
-
20
- assert_template_result("<tr class=\"row1\">\n<td class=\"col1\"> 1 </td><td class=\"col2\"> 2 </td><td class=\"col3\"> 3 </td></tr>\n<tr class=\"row2\"><td class=\"col1\"> 4 </td><td class=\"col2\"> 5 </td><td class=\"col3\"> 6 </td></tr>\n",
21
- '{% tablerow n in numbers cols:3%} {{n}} {% endtablerow %}',
22
- 'numbers' => [1,2,3,4,5,6])
23
-
24
- assert_template_result("<tr class=\"row1\">\n</tr>\n",
25
- '{% tablerow n in numbers cols:3%} {{n}} {% endtablerow %}',
26
- 'numbers' => [])
27
- end
28
-
29
- def test_html_table_with_different_cols
30
- assert_template_result("<tr class=\"row1\">\n<td class=\"col1\"> 1 </td><td class=\"col2\"> 2 </td><td class=\"col3\"> 3 </td><td class=\"col4\"> 4 </td><td class=\"col5\"> 5 </td></tr>\n<tr class=\"row2\"><td class=\"col1\"> 6 </td></tr>\n",
31
- '{% tablerow n in numbers cols:5%} {{n}} {% endtablerow %}',
32
- 'numbers' => [1,2,3,4,5,6])
33
-
34
- end
35
-
36
- def test_html_col_counter
37
- assert_template_result("<tr class=\"row1\">\n<td class=\"col1\">1</td><td class=\"col2\">2</td></tr>\n<tr class=\"row2\"><td class=\"col1\">1</td><td class=\"col2\">2</td></tr>\n<tr class=\"row3\"><td class=\"col1\">1</td><td class=\"col2\">2</td></tr>\n",
38
- '{% tablerow n in numbers cols:2%}{{tablerowloop.col}}{% endtablerow %}',
39
- 'numbers' => [1,2,3,4,5,6])
40
- end
41
-
42
- def test_quoted_fragment
43
- assert_template_result("<tr class=\"row1\">\n<td class=\"col1\"> 1 </td><td class=\"col2\"> 2 </td><td class=\"col3\"> 3 </td></tr>\n<tr class=\"row2\"><td class=\"col1\"> 4 </td><td class=\"col2\"> 5 </td><td class=\"col3\"> 6 </td></tr>\n",
44
- "{% tablerow n in collections.frontpage cols:3%} {{n}} {% endtablerow %}",
45
- 'collections' => {'frontpage' => [1,2,3,4,5,6]})
46
- assert_template_result("<tr class=\"row1\">\n<td class=\"col1\"> 1 </td><td class=\"col2\"> 2 </td><td class=\"col3\"> 3 </td></tr>\n<tr class=\"row2\"><td class=\"col1\"> 4 </td><td class=\"col2\"> 5 </td><td class=\"col3\"> 6 </td></tr>\n",
47
- "{% tablerow n in collections['frontpage'] cols:3%} {{n}} {% endtablerow %}",
48
- 'collections' => {'frontpage' => [1,2,3,4,5,6]})
49
-
50
- end
51
-
52
- def test_enumerable_drop
53
- assert_template_result("<tr class=\"row1\">\n<td class=\"col1\"> 1 </td><td class=\"col2\"> 2 </td><td class=\"col3\"> 3 </td></tr>\n<tr class=\"row2\"><td class=\"col1\"> 4 </td><td class=\"col2\"> 5 </td><td class=\"col3\"> 6 </td></tr>\n",
54
- '{% tablerow n in numbers cols:3%} {{n}} {% endtablerow %}',
55
- 'numbers' => ArrayDrop.new([1,2,3,4,5,6]))
56
- end
57
-
58
- def test_offset_and_limit
59
- assert_template_result("<tr class=\"row1\">\n<td class=\"col1\"> 1 </td><td class=\"col2\"> 2 </td><td class=\"col3\"> 3 </td></tr>\n<tr class=\"row2\"><td class=\"col1\"> 4 </td><td class=\"col2\"> 5 </td><td class=\"col3\"> 6 </td></tr>\n",
60
- '{% tablerow n in numbers cols:3 offset:1 limit:6%} {{n}} {% endtablerow %}',
61
- 'numbers' => [0,1,2,3,4,5,6,7])
62
- end
63
- end # HtmlTagTest
@@ -1,166 +0,0 @@
1
- require 'test_helper'
2
-
3
- class IfElseTagTest < Test::Unit::TestCase
4
- include Liquid
5
-
6
- def test_if
7
- assert_template_result(' ',' {% if false %} this text should not go into the output {% endif %} ')
8
- assert_template_result(' this text should go into the output ',
9
- ' {% if true %} this text should go into the output {% endif %} ')
10
- assert_template_result(' you rock ?','{% if false %} you suck {% endif %} {% if true %} you rock {% endif %}?')
11
- end
12
-
13
- def test_if_else
14
- assert_template_result(' YES ','{% if false %} NO {% else %} YES {% endif %}')
15
- assert_template_result(' YES ','{% if true %} YES {% else %} NO {% endif %}')
16
- assert_template_result(' YES ','{% if "foo" %} YES {% else %} NO {% endif %}')
17
- end
18
-
19
- def test_if_boolean
20
- assert_template_result(' YES ','{% if var %} YES {% endif %}', 'var' => true)
21
- end
22
-
23
- def test_if_or
24
- assert_template_result(' YES ','{% if a or b %} YES {% endif %}', 'a' => true, 'b' => true)
25
- assert_template_result(' YES ','{% if a or b %} YES {% endif %}', 'a' => true, 'b' => false)
26
- assert_template_result(' YES ','{% if a or b %} YES {% endif %}', 'a' => false, 'b' => true)
27
- assert_template_result('', '{% if a or b %} YES {% endif %}', 'a' => false, 'b' => false)
28
-
29
- assert_template_result(' YES ','{% if a or b or c %} YES {% endif %}', 'a' => false, 'b' => false, 'c' => true)
30
- assert_template_result('', '{% if a or b or c %} YES {% endif %}', 'a' => false, 'b' => false, 'c' => false)
31
- end
32
-
33
- def test_if_or_with_operators
34
- assert_template_result(' YES ','{% if a == true or b == true %} YES {% endif %}', 'a' => true, 'b' => true)
35
- assert_template_result(' YES ','{% if a == true or b == false %} YES {% endif %}', 'a' => true, 'b' => true)
36
- assert_template_result('','{% if a == false or b == false %} YES {% endif %}', 'a' => true, 'b' => true)
37
- end
38
-
39
- def test_comparison_of_strings_containing_and_or_or
40
- assert_nothing_raised do
41
- awful_markup = "a == 'and' and b == 'or' and c == 'foo and bar' and d == 'bar or baz' and e == 'foo' and foo and bar"
42
- assigns = {'a' => 'and', 'b' => 'or', 'c' => 'foo and bar', 'd' => 'bar or baz', 'e' => 'foo', 'foo' => true, 'bar' => true}
43
- assert_template_result(' YES ',"{% if #{awful_markup} %} YES {% endif %}", assigns)
44
- end
45
- end
46
-
47
- def test_comparison_of_expressions_starting_with_and_or_or
48
- assigns = {'order' => {'items_count' => 0}, 'android' => {'name' => 'Roy'}}
49
- assert_nothing_raised do
50
- assert_template_result( "YES",
51
- "{% if android.name == 'Roy' %}YES{% endif %}",
52
- assigns)
53
- end
54
- assert_nothing_raised do
55
- assert_template_result( "YES",
56
- "{% if order.items_count == 0 %}YES{% endif %}",
57
- assigns)
58
- end
59
- end
60
-
61
- def test_if_and
62
- assert_template_result(' YES ','{% if true and true %} YES {% endif %}')
63
- assert_template_result('','{% if false and true %} YES {% endif %}')
64
- assert_template_result('','{% if false and true %} YES {% endif %}')
65
- end
66
-
67
-
68
- def test_hash_miss_generates_false
69
- assert_template_result('','{% if foo.bar %} NO {% endif %}', 'foo' => {})
70
- end
71
-
72
- def test_if_from_variable
73
- assert_template_result('','{% if var %} NO {% endif %}', 'var' => false)
74
- assert_template_result('','{% if var %} NO {% endif %}', 'var' => nil)
75
- assert_template_result('','{% if foo.bar %} NO {% endif %}', 'foo' => {'bar' => false})
76
- assert_template_result('','{% if foo.bar %} NO {% endif %}', 'foo' => {})
77
- assert_template_result('','{% if foo.bar %} NO {% endif %}', 'foo' => nil)
78
- assert_template_result('','{% if foo.bar %} NO {% endif %}', 'foo' => true)
79
-
80
- assert_template_result(' YES ','{% if var %} YES {% endif %}', 'var' => "text")
81
- assert_template_result(' YES ','{% if var %} YES {% endif %}', 'var' => true)
82
- assert_template_result(' YES ','{% if var %} YES {% endif %}', 'var' => 1)
83
- assert_template_result(' YES ','{% if var %} YES {% endif %}', 'var' => {})
84
- assert_template_result(' YES ','{% if var %} YES {% endif %}', 'var' => [])
85
- assert_template_result(' YES ','{% if "foo" %} YES {% endif %}')
86
- assert_template_result(' YES ','{% if foo.bar %} YES {% endif %}', 'foo' => {'bar' => true})
87
- assert_template_result(' YES ','{% if foo.bar %} YES {% endif %}', 'foo' => {'bar' => "text"})
88
- assert_template_result(' YES ','{% if foo.bar %} YES {% endif %}', 'foo' => {'bar' => 1 })
89
- assert_template_result(' YES ','{% if foo.bar %} YES {% endif %}', 'foo' => {'bar' => {} })
90
- assert_template_result(' YES ','{% if foo.bar %} YES {% endif %}', 'foo' => {'bar' => [] })
91
-
92
- assert_template_result(' YES ','{% if var %} NO {% else %} YES {% endif %}', 'var' => false)
93
- assert_template_result(' YES ','{% if var %} NO {% else %} YES {% endif %}', 'var' => nil)
94
- assert_template_result(' YES ','{% if var %} YES {% else %} NO {% endif %}', 'var' => true)
95
- assert_template_result(' YES ','{% if "foo" %} YES {% else %} NO {% endif %}', 'var' => "text")
96
-
97
- assert_template_result(' YES ','{% if foo.bar %} NO {% else %} YES {% endif %}', 'foo' => {'bar' => false})
98
- assert_template_result(' YES ','{% if foo.bar %} YES {% else %} NO {% endif %}', 'foo' => {'bar' => true})
99
- assert_template_result(' YES ','{% if foo.bar %} YES {% else %} NO {% endif %}', 'foo' => {'bar' => "text"})
100
- assert_template_result(' YES ','{% if foo.bar %} NO {% else %} YES {% endif %}', 'foo' => {'notbar' => true})
101
- assert_template_result(' YES ','{% if foo.bar %} NO {% else %} YES {% endif %}', 'foo' => {})
102
- assert_template_result(' YES ','{% if foo.bar %} NO {% else %} YES {% endif %}', 'notfoo' => {'bar' => true})
103
- end
104
-
105
- def test_nested_if
106
- assert_template_result('', '{% if false %}{% if false %} NO {% endif %}{% endif %}')
107
- assert_template_result('', '{% if false %}{% if true %} NO {% endif %}{% endif %}')
108
- assert_template_result('', '{% if true %}{% if false %} NO {% endif %}{% endif %}')
109
- assert_template_result(' YES ', '{% if true %}{% if true %} YES {% endif %}{% endif %}')
110
-
111
- assert_template_result(' YES ', '{% if true %}{% if true %} YES {% else %} NO {% endif %}{% else %} NO {% endif %}')
112
- assert_template_result(' YES ', '{% if true %}{% if false %} NO {% else %} YES {% endif %}{% else %} NO {% endif %}')
113
- assert_template_result(' YES ', '{% if false %}{% if true %} NO {% else %} NONO {% endif %}{% else %} YES {% endif %}')
114
-
115
- end
116
-
117
- def test_comparisons_on_null
118
- assert_template_result('','{% if null < 10 %} NO {% endif %}')
119
- assert_template_result('','{% if null <= 10 %} NO {% endif %}')
120
- assert_template_result('','{% if null >= 10 %} NO {% endif %}')
121
- assert_template_result('','{% if null > 10 %} NO {% endif %}')
122
-
123
- assert_template_result('','{% if 10 < null %} NO {% endif %}')
124
- assert_template_result('','{% if 10 <= null %} NO {% endif %}')
125
- assert_template_result('','{% if 10 >= null %} NO {% endif %}')
126
- assert_template_result('','{% if 10 > null %} NO {% endif %}')
127
- end
128
-
129
- def test_else_if
130
- assert_template_result('0','{% if 0 == 0 %}0{% elsif 1 == 1%}1{% else %}2{% endif %}')
131
- assert_template_result('1','{% if 0 != 0 %}0{% elsif 1 == 1%}1{% else %}2{% endif %}')
132
- assert_template_result('2','{% if 0 != 0 %}0{% elsif 1 != 1%}1{% else %}2{% endif %}')
133
-
134
- assert_template_result('elsif','{% if false %}if{% elsif true %}elsif{% endif %}')
135
- end
136
-
137
- def test_syntax_error_no_variable
138
- assert_raise(SyntaxError){ assert_template_result('', '{% if jerry == 1 %}')}
139
- end
140
-
141
- def test_syntax_error_no_expression
142
- assert_raise(SyntaxError) { assert_template_result('', '{% if %}') }
143
- end
144
-
145
- def test_if_with_custom_condition
146
- Condition.operators['contains'] = :[]
147
-
148
- assert_template_result('yes', %({% if 'bob' contains 'o' %}yes{% endif %}))
149
- assert_template_result('no', %({% if 'bob' contains 'f' %}yes{% else %}no{% endif %}))
150
- ensure
151
- Condition.operators.delete 'contains'
152
- end
153
-
154
- def test_operators_are_ignored_unless_isolated
155
- Condition.operators['contains'] = :[]
156
-
157
- assert_template_result('yes',
158
- %({% if 'gnomeslab-and-or-liquid' contains 'gnomeslab-and-or-liquid' %}yes{% endif %}))
159
- end
160
-
161
- def test_operators_are_whitelisted
162
- assert_raise(SyntaxError) do
163
- assert_template_result('', %({% if 1 or throw or or 1 %}yes{% endif %}))
164
- end
165
- end
166
- end # IfElseTest
@@ -1,166 +0,0 @@
1
- require 'test_helper'
2
-
3
- class TestFileSystem
4
- def read_template_file(template_path, context)
5
- case template_path
6
- when "product"
7
- "Product: {{ product.title }} "
8
-
9
- when "locale_variables"
10
- "Locale: {{echo1}} {{echo2}}"
11
-
12
- when "variant"
13
- "Variant: {{ variant.title }}"
14
-
15
- when "nested_template"
16
- "{% include 'header' %} {% include 'body' %} {% include 'footer' %}"
17
-
18
- when "body"
19
- "body {% include 'body_detail' %}"
20
-
21
- when "nested_product_template"
22
- "Product: {{ nested_product_template.title }} {%include 'details'%} "
23
-
24
- when "recursively_nested_template"
25
- "-{% include 'recursively_nested_template' %}"
26
-
27
- when "pick_a_source"
28
- "from TestFileSystem"
29
-
30
- else
31
- template_path
32
- end
33
- end
34
- end
35
-
36
- class OtherFileSystem
37
- def read_template_file(template_path, context)
38
- 'from OtherFileSystem'
39
- end
40
- end
41
-
42
- class CountingFileSystem
43
- attr_reader :count
44
- def read_template_file(template_path, context)
45
- @count ||= 0
46
- @count += 1
47
- 'from CountingFileSystem'
48
- end
49
- end
50
-
51
- class IncludeTagTest < Test::Unit::TestCase
52
- include Liquid
53
-
54
- def setup
55
- Liquid::Template.file_system = TestFileSystem.new
56
- end
57
-
58
- def test_include_tag_looks_for_file_system_in_registers_first
59
- assert_equal 'from OtherFileSystem',
60
- Template.parse("{% include 'pick_a_source' %}").render({}, :registers => {:file_system => OtherFileSystem.new})
61
- end
62
-
63
-
64
- def test_include_tag_with
65
- assert_equal "Product: Draft 151cm ",
66
- Template.parse("{% include 'product' with products[0] %}").render( "products" => [ {'title' => 'Draft 151cm'}, {'title' => 'Element 155cm'} ] )
67
- end
68
-
69
- def test_include_tag_with_default_name
70
- assert_equal "Product: Draft 151cm ",
71
- Template.parse("{% include 'product' %}").render( "product" => {'title' => 'Draft 151cm'} )
72
- end
73
-
74
- def test_include_tag_for
75
-
76
- assert_equal "Product: Draft 151cm Product: Element 155cm ",
77
- Template.parse("{% include 'product' for products %}").render( "products" => [ {'title' => 'Draft 151cm'}, {'title' => 'Element 155cm'} ] )
78
- end
79
-
80
- def test_include_tag_with_local_variables
81
- assert_equal "Locale: test123 ",
82
- Template.parse("{% include 'locale_variables' echo1: 'test123' %}").render
83
- end
84
-
85
- def test_include_tag_with_multiple_local_variables
86
- assert_equal "Locale: test123 test321",
87
- Template.parse("{% include 'locale_variables' echo1: 'test123', echo2: 'test321' %}").render
88
- end
89
-
90
- def test_include_tag_with_multiple_local_variables_from_context
91
- assert_equal "Locale: test123 test321",
92
- Template.parse("{% include 'locale_variables' echo1: echo1, echo2: more_echos.echo2 %}").render('echo1' => 'test123', 'more_echos' => { "echo2" => 'test321'})
93
- end
94
-
95
- def test_nested_include_tag
96
- assert_equal "body body_detail",
97
- Template.parse("{% include 'body' %}").render
98
-
99
- assert_equal "header body body_detail footer",
100
- Template.parse("{% include 'nested_template' %}").render
101
- end
102
-
103
- def test_nested_include_with_variable
104
-
105
- assert_equal "Product: Draft 151cm details ",
106
- Template.parse("{% include 'nested_product_template' with product %}").render("product" => {"title" => 'Draft 151cm'})
107
-
108
- assert_equal "Product: Draft 151cm details Product: Element 155cm details ",
109
- Template.parse("{% include 'nested_product_template' for products %}").render("products" => [{"title" => 'Draft 151cm'}, {"title" => 'Element 155cm'}])
110
-
111
- end
112
-
113
- def test_recursively_included_template_does_not_produce_endless_loop
114
-
115
- infinite_file_system = Class.new do
116
- def read_template_file(template_path, context)
117
- "-{% include 'loop' %}"
118
- end
119
- end
120
-
121
- Liquid::Template.file_system = infinite_file_system.new
122
-
123
- assert_raise(Liquid::StackLevelError) do
124
- Template.parse("{% include 'loop' %}").render!
125
- end
126
-
127
- end
128
-
129
- def test_backwards_compatability_support_for_overridden_read_template_file
130
- infinite_file_system = Class.new do
131
- def read_template_file(template_path) # testing only one argument here.
132
- "- hi mom"
133
- end
134
- end
135
-
136
- Liquid::Template.file_system = infinite_file_system.new
137
-
138
- Template.parse("{% include 'hi_mom' %}").render!
139
- end
140
-
141
- def test_dynamically_choosen_template
142
-
143
- assert_equal "Test123", Template.parse("{% include template %}").render("template" => 'Test123')
144
- assert_equal "Test321", Template.parse("{% include template %}").render("template" => 'Test321')
145
-
146
- assert_equal "Product: Draft 151cm ", Template.parse("{% include template for product %}").render("template" => 'product', 'product' => { 'title' => 'Draft 151cm'})
147
- end
148
-
149
- def test_include_tag_caches_second_read_of_same_partial
150
- file_system = CountingFileSystem.new
151
- assert_equal 'from CountingFileSystemfrom CountingFileSystem',
152
- Template.parse("{% include 'pick_a_source' %}{% include 'pick_a_source' %}").render({}, :registers => {:file_system => file_system})
153
- assert_equal 1, file_system.count
154
- end
155
-
156
- def test_include_tag_doesnt_cache_partials_across_renders
157
- file_system = CountingFileSystem.new
158
- assert_equal 'from CountingFileSystem',
159
- Template.parse("{% include 'pick_a_source' %}").render({}, :registers => {:file_system => file_system})
160
- assert_equal 1, file_system.count
161
-
162
- assert_equal 'from CountingFileSystem',
163
- Template.parse("{% include 'pick_a_source' %}").render({}, :registers => {:file_system => file_system})
164
- assert_equal 2, file_system.count
165
- end
166
- end # IncludeTagTest
@@ -1,24 +0,0 @@
1
- require 'test_helper'
2
-
3
- class IncrementTagTest < Test::Unit::TestCase
4
- include Liquid
5
-
6
- def test_inc
7
- assert_template_result('0','{%increment port %}', {})
8
- assert_template_result('0 1','{%increment port %} {%increment port%}', {})
9
- assert_template_result('0 0 1 2 1',
10
- '{%increment port %} {%increment starboard%} ' +
11
- '{%increment port %} {%increment port%} ' +
12
- '{%increment starboard %}', {})
13
- end
14
-
15
- def test_dec
16
- assert_template_result('9','{%decrement port %}', { 'port' => 10})
17
- assert_template_result('-1 -2','{%decrement port %} {%decrement port%}', {})
18
- assert_template_result('1 5 2 2 5',
19
- '{%increment port %} {%increment starboard%} ' +
20
- '{%increment port %} {%decrement port%} ' +
21
- '{%decrement starboard %}', { 'port' => 1, 'starboard' => 5 })
22
- end
23
-
24
- end
@@ -1,24 +0,0 @@
1
- require 'test_helper'
2
-
3
- class RawTagTest < Test::Unit::TestCase
4
- include Liquid
5
-
6
- def test_tag_in_raw
7
- assert_template_result '{% comment %} test {% endcomment %}',
8
- '{% raw %}{% comment %} test {% endcomment %}{% endraw %}'
9
- end
10
-
11
- def test_output_in_raw
12
- assert_template_result '{{ test }}', '{% raw %}{{ test }}{% endraw %}'
13
- end
14
-
15
- def test_open_tag_in_raw
16
- assert_template_result ' Foobar {% invalid ', '{% raw %} Foobar {% invalid {% endraw %}'
17
- assert_template_result ' Foobar invalid %} ', '{% raw %} Foobar invalid %} {% endraw %}'
18
- assert_template_result ' Foobar {{ invalid ', '{% raw %} Foobar {{ invalid {% endraw %}'
19
- assert_template_result ' Foobar invalid }} ', '{% raw %} Foobar invalid }} {% endraw %}'
20
- assert_template_result ' Foobar {% invalid {% {% endraw ', '{% raw %} Foobar {% invalid {% {% endraw {% endraw %}'
21
- assert_template_result ' Foobar {% {% {% ', '{% raw %} Foobar {% {% {% {% endraw %}'
22
- assert_template_result ' test {% raw %} {% endraw %}', '{% raw %} test {% raw %} {% {% endraw %}endraw %}'
23
- end
24
- end