liquor 0.1.1 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (176) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +3 -9
  5. data/Gemfile +7 -0
  6. data/Guardfile +11 -0
  7. data/MIT-LICENSE +6 -2
  8. data/README.md +4 -122
  9. data/Rakefile +20 -23
  10. data/doc/language-spec.html +768 -0
  11. data/doc/language-spec.md +698 -0
  12. data/lib/liquor.rb +39 -68
  13. data/lib/liquor/ast_tools.rb +28 -0
  14. data/lib/liquor/compiler.rb +110 -0
  15. data/lib/liquor/context.rb +76 -254
  16. data/lib/liquor/diagnostics.rb +151 -0
  17. data/lib/liquor/drop/drop.rb +168 -0
  18. data/lib/liquor/drop/drop_delegation.rb +24 -0
  19. data/lib/liquor/drop/drop_scope.rb +118 -0
  20. data/lib/liquor/drop/dropable.rb +17 -0
  21. data/lib/liquor/emitter.rb +313 -0
  22. data/lib/liquor/extensions/kaminari.rb +14 -0
  23. data/lib/liquor/extensions/pagination.rb +235 -0
  24. data/lib/liquor/extensions/rails.rb +97 -0
  25. data/lib/liquor/extensions/thinking_sphinx.rb +14 -0
  26. data/lib/liquor/extensions/tire.rb +30 -0
  27. data/lib/liquor/external.rb +79 -0
  28. data/lib/liquor/function.rb +94 -0
  29. data/lib/liquor/grammar/lexer.rb +1223 -0
  30. data/lib/liquor/grammar/lexer.rl +297 -0
  31. data/lib/liquor/grammar/parser.racc +288 -0
  32. data/lib/liquor/grammar/parser.rb +885 -0
  33. data/lib/liquor/library.rb +41 -0
  34. data/lib/liquor/manager.rb +146 -0
  35. data/lib/liquor/runtime.rb +167 -0
  36. data/lib/liquor/stdlib/builtin_functions.rb +315 -0
  37. data/lib/liquor/stdlib/builtin_tags.rb +228 -0
  38. data/lib/liquor/stdlib/html_truncater.rb +162 -0
  39. data/lib/liquor/stdlib/partial_tags.rb +76 -0
  40. data/lib/liquor/tag.rb +83 -14
  41. data/lib/liquor/version.rb +1 -1
  42. data/liquor.gemspec +29 -6
  43. data/spec/builtins_spec.rb +264 -0
  44. data/spec/compiler_spec.rb +136 -0
  45. data/spec/context_spec.rb +49 -0
  46. data/spec/drop_delegation_spec.rb +21 -0
  47. data/spec/drop_spec.rb +222 -0
  48. data/spec/errors_spec.rb +40 -0
  49. data/spec/external_spec.rb +207 -0
  50. data/spec/function_spec.rb +80 -0
  51. data/spec/lexer_spec.rb +173 -0
  52. data/spec/library_spec.rb +18 -0
  53. data/spec/manager_spec.rb +84 -0
  54. data/spec/parser_spec.rb +381 -0
  55. data/spec/partials_spec.rb +74 -0
  56. data/spec/runtime_spec.rb +97 -0
  57. data/spec/spec_helper.rb +94 -0
  58. data/spec/tag_spec.rb +7 -0
  59. metadata +216 -173
  60. data/AUTHORS +0 -2
  61. data/CHANGELOG +0 -48
  62. data/Gemfile.lock +0 -91
  63. data/History.txt +0 -44
  64. data/LICENSE +0 -23
  65. data/example/server/example_servlet.rb +0 -37
  66. data/example/server/liquid_servlet.rb +0 -28
  67. data/example/server/liquor_servlet.rb +0 -28
  68. data/example/server/server.rb +0 -12
  69. data/example/server/templates/index.liquid +0 -6
  70. data/example/server/templates/index.liquor +0 -6
  71. data/example/server/templates/products.liquid +0 -45
  72. data/example/server/templates/products.liquor +0 -45
  73. data/init.rb +0 -8
  74. data/lib/extras/liquid_view.rb +0 -51
  75. data/lib/extras/liquor_view.rb +0 -51
  76. data/lib/liquor/block.rb +0 -101
  77. data/lib/liquor/condition.rb +0 -120
  78. data/lib/liquor/document.rb +0 -17
  79. data/lib/liquor/drop.rb +0 -256
  80. data/lib/liquor/errors.rb +0 -11
  81. data/lib/liquor/extensions.rb +0 -72
  82. data/lib/liquor/file_system.rb +0 -62
  83. data/lib/liquor/htmltags.rb +0 -74
  84. data/lib/liquor/module_ex.rb +0 -60
  85. data/lib/liquor/standardfilters.rb +0 -315
  86. data/lib/liquor/strainer.rb +0 -58
  87. data/lib/liquor/tags/assign.rb +0 -33
  88. data/lib/liquor/tags/capture.rb +0 -35
  89. data/lib/liquor/tags/case.rb +0 -83
  90. data/lib/liquor/tags/comment.rb +0 -9
  91. data/lib/liquor/tags/content_for.rb +0 -54
  92. data/lib/liquor/tags/cycle.rb +0 -59
  93. data/lib/liquor/tags/for.rb +0 -136
  94. data/lib/liquor/tags/if.rb +0 -80
  95. data/lib/liquor/tags/ifchanged.rb +0 -20
  96. data/lib/liquor/tags/include.rb +0 -56
  97. data/lib/liquor/tags/unless.rb +0 -33
  98. data/lib/liquor/tags/yield.rb +0 -49
  99. data/lib/liquor/template.rb +0 -181
  100. data/lib/liquor/variable.rb +0 -52
  101. data/performance/shopify.rb +0 -92
  102. data/performance/shopify/comment_form.rb +0 -33
  103. data/performance/shopify/database.rb +0 -45
  104. data/performance/shopify/json_filter.rb +0 -7
  105. data/performance/shopify/liquid.rb +0 -18
  106. data/performance/shopify/liquor.rb +0 -18
  107. data/performance/shopify/money_filter.rb +0 -18
  108. data/performance/shopify/paginate.rb +0 -93
  109. data/performance/shopify/shop_filter.rb +0 -98
  110. data/performance/shopify/tag_filter.rb +0 -25
  111. data/performance/shopify/vision.database.yml +0 -945
  112. data/performance/shopify/weight_filter.rb +0 -11
  113. data/performance/tests/dropify/article.liquid +0 -74
  114. data/performance/tests/dropify/blog.liquid +0 -33
  115. data/performance/tests/dropify/cart.liquid +0 -66
  116. data/performance/tests/dropify/collection.liquid +0 -22
  117. data/performance/tests/dropify/index.liquid +0 -47
  118. data/performance/tests/dropify/page.liquid +0 -8
  119. data/performance/tests/dropify/product.liquid +0 -68
  120. data/performance/tests/dropify/theme.liquid +0 -105
  121. data/performance/tests/ripen/article.liquid +0 -74
  122. data/performance/tests/ripen/blog.liquid +0 -13
  123. data/performance/tests/ripen/cart.liquid +0 -54
  124. data/performance/tests/ripen/collection.liquid +0 -29
  125. data/performance/tests/ripen/index.liquid +0 -32
  126. data/performance/tests/ripen/page.liquid +0 -4
  127. data/performance/tests/ripen/product.liquid +0 -75
  128. data/performance/tests/ripen/theme.liquid +0 -85
  129. data/performance/tests/tribble/404.liquid +0 -56
  130. data/performance/tests/tribble/article.liquid +0 -98
  131. data/performance/tests/tribble/blog.liquid +0 -41
  132. data/performance/tests/tribble/cart.liquid +0 -134
  133. data/performance/tests/tribble/collection.liquid +0 -70
  134. data/performance/tests/tribble/index.liquid +0 -94
  135. data/performance/tests/tribble/page.liquid +0 -56
  136. data/performance/tests/tribble/product.liquid +0 -116
  137. data/performance/tests/tribble/search.liquid +0 -51
  138. data/performance/tests/tribble/theme.liquid +0 -90
  139. data/performance/tests/vogue/article.liquid +0 -66
  140. data/performance/tests/vogue/blog.liquid +0 -32
  141. data/performance/tests/vogue/cart.liquid +0 -58
  142. data/performance/tests/vogue/collection.liquid +0 -19
  143. data/performance/tests/vogue/index.liquid +0 -22
  144. data/performance/tests/vogue/page.liquid +0 -3
  145. data/performance/tests/vogue/product.liquid +0 -62
  146. data/performance/tests/vogue/theme.liquid +0 -122
  147. data/test/assign_test.rb +0 -11
  148. data/test/block_test.rb +0 -58
  149. data/test/capture_test.rb +0 -41
  150. data/test/condition_test.rb +0 -115
  151. data/test/content_for_test.rb +0 -15
  152. data/test/context_test.rb +0 -479
  153. data/test/drop_test.rb +0 -162
  154. data/test/error_handling_test.rb +0 -89
  155. data/test/extra/breakpoint.rb +0 -547
  156. data/test/extra/caller.rb +0 -80
  157. data/test/file_system_test.rb +0 -30
  158. data/test/filter_test.rb +0 -147
  159. data/test/helper.rb +0 -24
  160. data/test/html_tag_test.rb +0 -31
  161. data/test/if_else_test.rb +0 -139
  162. data/test/include_tag_test.rb +0 -129
  163. data/test/module_ex_test.rb +0 -89
  164. data/test/output_test.rb +0 -121
  165. data/test/parsing_quirks_test.rb +0 -54
  166. data/test/regexp_test.rb +0 -45
  167. data/test/security_test.rb +0 -41
  168. data/test/standard_filter_test.rb +0 -170
  169. data/test/standard_tag_test.rb +0 -405
  170. data/test/statements_test.rb +0 -137
  171. data/test/strainer_test.rb +0 -27
  172. data/test/template_test.rb +0 -82
  173. data/test/test_helper.rb +0 -28
  174. data/test/unless_else_test.rb +0 -27
  175. data/test/variable_test.rb +0 -173
  176. data/test/yield_test.rb +0 -24
@@ -1,137 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require File.dirname(__FILE__) + '/helper'
3
-
4
- class StatementsTest < Test::Unit::TestCase
5
- include Liquor
6
-
7
-
8
- def test_true_eql_true
9
- text = %| {% if true == true %} true {% else %} false {% endif %} |
10
- expected = %| true |
11
- assert_equal expected, Template.parse(text).render
12
- end
13
-
14
- def test_true_not_eql_true
15
- text = %| {% if true != true %} true {% else %} false {% endif %} |
16
- expected = %| false |
17
- assert_equal expected, Template.parse(text).render
18
- end
19
-
20
- def test_true_lq_true
21
- text = %| {% if 0 > 0 %} true {% else %} false {% endif %} |
22
- expected = %| false |
23
- assert_equal expected, Template.parse(text).render
24
- end
25
-
26
- def test_one_lq_zero
27
- text = %| {% if 1 > 0 %} true {% else %} false {% endif %} |
28
- expected = %| true |
29
- assert_equal expected, Template.parse(text).render
30
- end
31
-
32
- def test_zero_lq_one
33
- text = %| {% if 0 < 1 %} true {% else %} false {% endif %} |
34
- expected = %| true |
35
- assert_equal expected, Template.parse(text).render
36
- end
37
-
38
- def test_zero_lq_or_equal_one
39
- text = %| {% if 0 <= 0 %} true {% else %} false {% endif %} |
40
- expected = %| true |
41
- assert_equal expected, Template.parse(text).render
42
- end
43
-
44
- def test_zero_lq_or_equal_one_involving_nil
45
- text = %| {% if null <= 0 %} true {% else %} false {% endif %} |
46
- expected = %| false |
47
- assert_equal expected, Template.parse(text).render
48
-
49
-
50
- text = %| {% if 0 <= null %} true {% else %} false {% endif %} |
51
- expected = %| false |
52
- assert_equal expected, Template.parse(text).render
53
- end
54
-
55
- def test_zero_lqq_or_equal_one
56
- text = %| {% if 0 >= 0 %} true {% else %} false {% endif %} |
57
- expected = %| true |
58
- assert_equal expected, Template.parse(text).render
59
- end
60
-
61
- def test_strings
62
- text = %| {% if 'test' == 'test' %} true {% else %} false {% endif %} |
63
- expected = %| true |
64
- assert_equal expected, Template.parse(text).render
65
- end
66
-
67
- def test_strings_not_equal
68
- text = %| {% if 'test' != 'test' %} true {% else %} false {% endif %} |
69
- expected = %| false |
70
- assert_equal expected, Template.parse(text).render
71
- end
72
-
73
- def test_var_strings_equal
74
- text = %| {% if var == "hello there!" %} true {% else %} false {% endif %} |
75
- expected = %| true |
76
- assert_equal expected, Template.parse(text).render('var' => 'hello there!')
77
- end
78
-
79
- def test_var_strings_are_not_equal
80
- text = %| {% if "hello there!" == var %} true {% else %} false {% endif %} |
81
- expected = %| true |
82
- assert_equal expected, Template.parse(text).render('var' => 'hello there!')
83
- end
84
-
85
- def test_var_and_long_string_are_equal
86
- text = %| {% if var == 'hello there!' %} true {% else %} false {% endif %} |
87
- expected = %| true |
88
- assert_equal expected, Template.parse(text).render('var' => 'hello there!')
89
- end
90
-
91
-
92
- def test_var_and_long_string_are_equal_backwards
93
- text = %| {% if 'hello there!' == var %} true {% else %} false {% endif %} |
94
- expected = %| true |
95
- assert_equal expected, Template.parse(text).render('var' => 'hello there!')
96
- end
97
-
98
- #def test_is_nil
99
- # text = %| {% if var != nil %} true {% else %} false {% end %} |
100
- # @template.assigns = { 'var' => 'hello there!'}
101
- # expected = %| true |
102
- # assert_equal expected, @template.parse(text)
103
- #end
104
-
105
- def test_is_collection_empty
106
- text = %| {% if array == empty %} true {% else %} false {% endif %} |
107
- expected = %| true |
108
- assert_equal expected, Template.parse(text).render('array' => [])
109
- end
110
-
111
- def test_is_not_collection_empty
112
- text = %| {% if array == empty %} true {% else %} false {% endif %} |
113
- expected = %| false |
114
- assert_equal expected, Template.parse(text).render('array' => [1,2,3])
115
- end
116
-
117
- def test_nil
118
- text = %| {% if var == nil %} true {% else %} false {% endif %} |
119
- expected = %| true |
120
- assert_equal expected, Template.parse(text).render('var' => nil)
121
-
122
- text = %| {% if var == null %} true {% else %} false {% endif %} |
123
- expected = %| true |
124
- assert_equal expected, Template.parse(text).render('var' => nil)
125
- end
126
-
127
- def test_not_nil
128
- text = %| {% if var != nil %} true {% else %} false {% endif %} |
129
- expected = %| true |
130
- assert_equal expected, Template.parse(text).render('var' => 1 )
131
-
132
- text = %| {% if var != null %} true {% else %} false {% endif %} |
133
- expected = %| true |
134
- assert_equal expected, Template.parse(text).render('var' => 1 )
135
- end
136
-
137
- end
@@ -1,27 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require File.dirname(__FILE__) + '/helper'
3
-
4
- class StrainerTest < Test::Unit::TestCase
5
- include Liquor
6
-
7
- def test_strainer
8
- strainer = Strainer.create(nil)
9
- assert_equal false, strainer.respond_to?('__test__')
10
- assert_equal false, strainer.respond_to?('test')
11
- assert_equal false, strainer.respond_to?('instance_eval')
12
- assert_equal false, strainer.respond_to?('__send__')
13
- assert_equal true, strainer.respond_to?('size') # from the standard lib
14
- end
15
-
16
- def test_should_respond_to_two_parameters
17
- strainer = Strainer.create(nil)
18
- assert_equal true, strainer.respond_to?('size', false)
19
- end
20
-
21
- # Asserts that Object#respond_to_missing? is not being undefined in Ruby versions where it has been implemented
22
- # Currently this method is only present in Ruby v1.9.2, or higher
23
- def test_object_respond_to_missing
24
- assert_equal Object.respond_to?(:respond_to_missing?), Strainer.create(nil).respond_to?(:respond_to_missing?)
25
- end
26
-
27
- end
@@ -1,82 +0,0 @@
1
- require File.dirname(__FILE__) + '/helper'
2
-
3
- class TemplateTest < Test::Unit::TestCase
4
- include Liquor
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
-
75
- def test_raise_exception_when_layout_is_not_a_template_object
76
- layout_template = '<title>{% yield title %}</title> <body>{% yield %}</body>'
77
- view_template = '{% content_for title %}{% assign text="aaa" %}{{ text }}{% end_content_for %}{% assign text="body" %}{{ text }}'
78
-
79
- assert_raise (ArgumentError) { Template.parse(view_template).render({ :layout => layout_template }) }
80
- end
81
-
82
- end
@@ -1,28 +0,0 @@
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 'active_record'
9
- require 'action_controller'
10
- require File.dirname(__FILE__) + '/../lib/liquid'
11
-
12
-
13
- ActiveRecord::Base.establish_connection(
14
- :adapter => "sqlite3",
15
- :database => ":memory:"
16
- )
17
-
18
-
19
- module Test
20
- module Unit
21
- module Assertions
22
- include Liquor
23
- def assert_template_result(expected, template, assigns={}, message=nil)
24
- assert_equal expected, Template.parse(template).render(assigns)
25
- end
26
- end
27
- end
28
- end
@@ -1,27 +0,0 @@
1
- require File.dirname(__FILE__) + '/helper'
2
-
3
- class UnlessElseTest < Test::Unit::TestCase
4
- include Liquor
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
-
27
- end
@@ -1,173 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require File.dirname(__FILE__) + '/helper'
3
-
4
- class VariableTest < Test::Unit::TestCase
5
- include Liquor
6
-
7
- def test_variable
8
- var = Variable.new('hello')
9
- assert_equal 'hello', var.name
10
- end
11
-
12
- def test_filters
13
- var = Variable.new('hello | textileze')
14
- assert_equal 'hello', var.name
15
- assert_equal [[:textileze,[]]], var.filters
16
-
17
- var = Variable.new('hello | textileze | paragraph')
18
- assert_equal 'hello', var.name
19
- assert_equal [[:textileze,[]], [:paragraph,[]]], var.filters
20
-
21
- var = Variable.new(%! hello | strftime: '%Y'!)
22
- assert_equal 'hello', var.name
23
- assert_equal [[:strftime,["'%Y'"]]], var.filters
24
-
25
- var = Variable.new(%! 'typo' | link_to: 'Typo', true !)
26
- assert_equal %!'typo'!, var.name
27
- assert_equal [[:link_to,["'Typo'", "true"]]], var.filters
28
-
29
- var = Variable.new(%! 'typo' | link_to: 'Typo', false !)
30
- assert_equal %!'typo'!, var.name
31
- assert_equal [[:link_to,["'Typo'", "false"]]], var.filters
32
-
33
- var = Variable.new(%! 'foo' | repeat: 3 !)
34
- assert_equal %!'foo'!, var.name
35
- assert_equal [[:repeat,["3"]]], var.filters
36
-
37
- var = Variable.new(%! 'foo' | repeat: 3, 3 !)
38
- assert_equal %!'foo'!, var.name
39
- assert_equal [[:repeat,["3","3"]]], var.filters
40
-
41
- var = Variable.new(%! 'foo' | repeat: 3, 3, 3 !)
42
- assert_equal %!'foo'!, var.name
43
- assert_equal [[:repeat,["3","3","3"]]], var.filters
44
-
45
- var = Variable.new(%! hello | strftime: '%Y, okay?'!)
46
- assert_equal 'hello', var.name
47
- assert_equal [[:strftime,["'%Y, okay?'"]]], var.filters
48
-
49
- var = Variable.new(%! hello | things: "%Y, okay?", 'the other one'!)
50
- assert_equal 'hello', var.name
51
- assert_equal [[:things,["\"%Y, okay?\"","'the other one'"]]], var.filters
52
- end
53
-
54
- def test_filter_with_date_parameter
55
-
56
- var = Variable.new(%! '2006-06-06' | date: "%m/%d/%Y"!)
57
- assert_equal "'2006-06-06'", var.name
58
- assert_equal [[:date,["\"%m/%d/%Y\""]]], var.filters
59
-
60
- end
61
-
62
- def test_filters_without_whitespace
63
- var = Variable.new('hello | textileze | paragraph')
64
- assert_equal 'hello', var.name
65
- assert_equal [[:textileze,[]], [:paragraph,[]]], var.filters
66
-
67
- var = Variable.new('hello|textileze|paragraph')
68
- assert_equal 'hello', var.name
69
- assert_equal [[:textileze,[]], [:paragraph,[]]], var.filters
70
- end
71
-
72
- def test_symbol
73
- var = Variable.new("http://disney.com/logo.gif | image: 'med' ")
74
- assert_equal 'http://disney.com/logo.gif', var.name
75
- assert_equal [[:image,["'med'"]]], var.filters
76
- end
77
-
78
- def test_string_single_quoted
79
- var = Variable.new(%| "hello" |)
80
- assert_equal '"hello"', var.name
81
- end
82
-
83
- def test_string_double_quoted
84
- var = Variable.new(%| 'hello' |)
85
- assert_equal "'hello'", var.name
86
- end
87
-
88
- def test_integer
89
- var = Variable.new(%| 1000 |)
90
- assert_equal "1000", var.name
91
- end
92
-
93
- def test_float
94
- var = Variable.new(%| 1000.01 |)
95
- assert_equal "1000.01", var.name
96
- end
97
-
98
- def test_string_with_special_chars
99
- var = Variable.new(%| 'hello! $!@.;"ddasd" ' |)
100
- assert_equal %|'hello! $!@.;"ddasd" '|, var.name
101
- end
102
-
103
- def test_string_dot
104
- var = Variable.new(%| test.test |)
105
- assert_equal 'test.test', var.name
106
- end
107
- end
108
-
109
-
110
- class VariableResolutionTest < Test::Unit::TestCase
111
- include Liquor
112
-
113
- def test_simple_variable
114
- template = Template.parse(%|{{test}}|)
115
- assert_equal 'worked', template.render('test' => 'worked')
116
- assert_equal 'worked wonderfully', template.render('test' => 'worked wonderfully')
117
- end
118
-
119
- def test_simple_with_whitespaces
120
- template = Template.parse(%| {{ test }} |)
121
- assert_equal ' worked ', template.render('test' => 'worked')
122
- assert_equal ' worked wonderfully ', template.render('test' => 'worked wonderfully')
123
- end
124
-
125
- def test_ignore_unknown
126
- template = Template.parse(%|{{ test }}|)
127
- assert_equal '', template.render
128
- end
129
-
130
- def test_hash_scoping
131
- template = Template.parse(%|{{ test.test }}|)
132
- assert_equal 'worked', template.render('test' => {'test' => 'worked'})
133
- end
134
-
135
- def test_preset_assigns
136
- template = Template.parse(%|{{ test }}|)
137
- template.assigns['test'] = 'worked'
138
- assert_equal 'worked', template.render
139
- end
140
-
141
- def test_reuse_parsed_template
142
- template = Template.parse(%|{{ greeting }} {{ name }}|)
143
- template.assigns['greeting'] = 'Goodbye'
144
- assert_equal 'Hello Tobi', template.render('greeting' => 'Hello', 'name' => 'Tobi')
145
- assert_equal 'Hello ', template.render('greeting' => 'Hello', 'unknown' => 'Tobi')
146
- assert_equal 'Hello Brian', template.render('greeting' => 'Hello', 'name' => 'Brian')
147
- assert_equal 'Goodbye Brian', template.render('name' => 'Brian')
148
- assert_equal({'greeting'=>'Goodbye'}, template.assigns)
149
- end
150
-
151
- def test_assigns_not_polluted_from_template
152
- template = Template.parse(%|{{ test }}{% assign test = 'bar' %}{{ test }}|)
153
- template.assigns['test'] = 'baz'
154
- assert_equal 'bazbar', template.render
155
- assert_equal 'bazbar', template.render
156
- assert_equal 'foobar', template.render('test' => 'foo')
157
- assert_equal 'bazbar', template.render
158
- end
159
-
160
- def test_hash_with_default_proc
161
- template = Template.parse(%|Hello {{ test }}|)
162
- assigns = Hash.new { |h,k| raise "Unknown variable '#{k}'" }
163
- assigns['test'] = 'Tobi'
164
- assert_equal 'Hello Tobi', template.render!(assigns, {})
165
-
166
- assigns = Hash.new { |h,k| raise "Unknown variable '#{k}'" }
167
- e = assert_raises(RuntimeError) {
168
- template.render!(assigns, {})
169
- }
170
- assert_equal "Unknown variable 'test'", e.message
171
- end
172
-
173
- end