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.
Files changed (89) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +42 -13
  3. data/README.md +27 -2
  4. data/lib/liquid.rb +11 -11
  5. data/lib/liquid/block.rb +75 -45
  6. data/lib/liquid/condition.rb +15 -11
  7. data/lib/liquid/context.rb +68 -29
  8. data/lib/liquid/document.rb +3 -3
  9. data/lib/liquid/drop.rb +17 -1
  10. data/lib/liquid/file_system.rb +17 -6
  11. data/lib/liquid/i18n.rb +39 -0
  12. data/lib/liquid/interrupts.rb +1 -1
  13. data/lib/liquid/lexer.rb +51 -0
  14. data/lib/liquid/locales/en.yml +22 -0
  15. data/lib/liquid/parser.rb +90 -0
  16. data/lib/liquid/standardfilters.rb +115 -52
  17. data/lib/liquid/strainer.rb +14 -4
  18. data/lib/liquid/tag.rb +42 -7
  19. data/lib/liquid/tags/assign.rb +10 -8
  20. data/lib/liquid/tags/break.rb +1 -1
  21. data/lib/liquid/tags/capture.rb +10 -8
  22. data/lib/liquid/tags/case.rb +13 -13
  23. data/lib/liquid/tags/comment.rb +9 -2
  24. data/lib/liquid/tags/continue.rb +1 -4
  25. data/lib/liquid/tags/cycle.rb +5 -7
  26. data/lib/liquid/tags/decrement.rb +3 -4
  27. data/lib/liquid/tags/for.rb +69 -36
  28. data/lib/liquid/tags/if.rb +52 -25
  29. data/lib/liquid/tags/ifchanged.rb +2 -2
  30. data/lib/liquid/tags/include.rb +8 -7
  31. data/lib/liquid/tags/increment.rb +4 -8
  32. data/lib/liquid/tags/raw.rb +3 -3
  33. data/lib/liquid/tags/table_row.rb +73 -0
  34. data/lib/liquid/tags/unless.rb +2 -4
  35. data/lib/liquid/template.rb +69 -10
  36. data/lib/liquid/utils.rb +13 -4
  37. data/lib/liquid/variable.rb +59 -8
  38. data/lib/liquid/version.rb +1 -1
  39. data/test/fixtures/en_locale.yml +9 -0
  40. data/test/{liquid → integration}/assign_test.rb +6 -0
  41. data/test/integration/blank_test.rb +106 -0
  42. data/test/{liquid → integration}/capture_test.rb +2 -2
  43. data/test/integration/context_test.rb +33 -0
  44. data/test/integration/drop_test.rb +245 -0
  45. data/test/{liquid → integration}/error_handling_test.rb +31 -2
  46. data/test/{liquid → integration}/filter_test.rb +7 -7
  47. data/test/{liquid → integration}/hash_ordering_test.rb +0 -0
  48. data/test/{liquid → integration}/output_test.rb +12 -12
  49. data/test/integration/parsing_quirks_test.rb +94 -0
  50. data/test/{liquid → integration}/security_test.rb +9 -9
  51. data/test/{liquid → integration}/standard_filter_test.rb +103 -33
  52. data/test/{liquid → integration}/tags/break_tag_test.rb +0 -0
  53. data/test/{liquid → integration}/tags/continue_tag_test.rb +0 -0
  54. data/test/{liquid → integration}/tags/for_tag_test.rb +78 -0
  55. data/test/{liquid → integration}/tags/if_else_tag_test.rb +1 -1
  56. data/test/integration/tags/include_tag_test.rb +212 -0
  57. data/test/{liquid → integration}/tags/increment_tag_test.rb +0 -0
  58. data/test/{liquid → integration}/tags/raw_tag_test.rb +1 -0
  59. data/test/{liquid → integration}/tags/standard_tag_test.rb +24 -22
  60. data/test/integration/tags/statements_test.rb +113 -0
  61. data/test/{liquid/tags/html_tag_test.rb → integration/tags/table_row_test.rb} +5 -5
  62. data/test/{liquid → integration}/tags/unless_else_tag_test.rb +0 -0
  63. data/test/{liquid → integration}/template_test.rb +66 -42
  64. data/test/integration/variable_test.rb +72 -0
  65. data/test/test_helper.rb +32 -7
  66. data/test/{liquid/block_test.rb → unit/block_unit_test.rb} +1 -1
  67. data/test/{liquid/condition_test.rb → unit/condition_unit_test.rb} +19 -1
  68. data/test/{liquid/context_test.rb → unit/context_unit_test.rb} +27 -19
  69. data/test/{liquid/file_system_test.rb → unit/file_system_unit_test.rb} +7 -1
  70. data/test/unit/i18n_unit_test.rb +37 -0
  71. data/test/unit/lexer_unit_test.rb +48 -0
  72. data/test/{liquid/module_ex_test.rb → unit/module_ex_unit_test.rb} +7 -7
  73. data/test/unit/parser_unit_test.rb +82 -0
  74. data/test/{liquid/regexp_test.rb → unit/regexp_unit_test.rb} +3 -3
  75. data/test/{liquid/strainer_test.rb → unit/strainer_unit_test.rb} +19 -1
  76. data/test/unit/tag_unit_test.rb +11 -0
  77. data/test/unit/tags/case_tag_unit_test.rb +10 -0
  78. data/test/unit/tags/for_tag_unit_test.rb +13 -0
  79. data/test/unit/tags/if_tag_unit_test.rb +8 -0
  80. data/test/unit/template_unit_test.rb +69 -0
  81. data/test/unit/tokenizer_unit_test.rb +29 -0
  82. data/test/{liquid/variable_test.rb → unit/variable_unit_test.rb} +17 -67
  83. metadata +117 -73
  84. data/lib/extras/liquid_view.rb +0 -51
  85. data/lib/liquid/htmltags.rb +0 -73
  86. data/test/liquid/drop_test.rb +0 -180
  87. data/test/liquid/parsing_quirks_test.rb +0 -52
  88. data/test/liquid/tags/include_tag_test.rb +0 -166
  89. data/test/liquid/tags/statements_test.rb +0 -134
@@ -1,52 +0,0 @@
1
- require 'test_helper'
2
-
3
- class ParsingQuirksTest < Test::Unit::TestCase
4
- include Liquid
5
-
6
- def test_error_with_css
7
- text = %| div { font-weight: bold; } |
8
- template = Template.parse(text)
9
-
10
- assert_equal text, template.render
11
- assert_equal [String], template.root.nodelist.collect {|i| i.class}
12
- end
13
-
14
- def test_raise_on_single_close_bracet
15
- assert_raise(SyntaxError) do
16
- Template.parse("text {{method} oh nos!")
17
- end
18
- end
19
-
20
- def test_raise_on_label_and_no_close_bracets
21
- assert_raise(SyntaxError) do
22
- Template.parse("TEST {{ ")
23
- end
24
- end
25
-
26
- def test_raise_on_label_and_no_close_bracets_percent
27
- assert_raise(SyntaxError) do
28
- Template.parse("TEST {% ")
29
- end
30
- end
31
-
32
- def test_error_on_empty_filter
33
- assert_nothing_raised do
34
- Template.parse("{{test |a|b|}}")
35
- Template.parse("{{test}}")
36
- Template.parse("{{|test|}}")
37
- end
38
- end
39
-
40
- def test_meaningless_parens
41
- assigns = {'b' => 'bar', 'c' => 'baz'}
42
- markup = "a == 'foo' or (b == 'bar' and c == 'baz') or false"
43
- assert_template_result(' YES ',"{% if #{markup} %} YES {% endif %}", assigns)
44
- end
45
-
46
- def test_unexpected_characters_silently_eat_logic
47
- markup = "true && false"
48
- assert_template_result(' YES ',"{% if #{markup} %} YES {% endif %}")
49
- markup = "false || true"
50
- assert_template_result('',"{% if #{markup} %} YES {% endif %}")
51
- end
52
- end # ParsingQuirksTest
@@ -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,134 +0,0 @@
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