spinto-liquid 2.3.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. data/History.md +56 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +44 -0
  4. data/lib/extras/liquid_view.rb +51 -0
  5. data/lib/liquid/block.rb +101 -0
  6. data/lib/liquid/condition.rb +120 -0
  7. data/lib/liquid/context.rb +245 -0
  8. data/lib/liquid/document.rb +17 -0
  9. data/lib/liquid/drop.rb +49 -0
  10. data/lib/liquid/errors.rb +11 -0
  11. data/lib/liquid/extensions.rb +62 -0
  12. data/lib/liquid/file_system.rb +62 -0
  13. data/lib/liquid/htmltags.rb +75 -0
  14. data/lib/liquid/module_ex.rb +62 -0
  15. data/lib/liquid/standardfilters.rb +241 -0
  16. data/lib/liquid/strainer.rb +54 -0
  17. data/lib/liquid/tag.rb +26 -0
  18. data/lib/liquid/tags/assign.rb +33 -0
  19. data/lib/liquid/tags/capture.rb +35 -0
  20. data/lib/liquid/tags/case.rb +79 -0
  21. data/lib/liquid/tags/comment.rb +9 -0
  22. data/lib/liquid/tags/cycle.rb +59 -0
  23. data/lib/liquid/tags/decrement.rb +39 -0
  24. data/lib/liquid/tags/for.rb +190 -0
  25. data/lib/liquid/tags/if.rb +79 -0
  26. data/lib/liquid/tags/ifchanged.rb +20 -0
  27. data/lib/liquid/tags/include.rb +65 -0
  28. data/lib/liquid/tags/increment.rb +35 -0
  29. data/lib/liquid/tags/raw.rb +21 -0
  30. data/lib/liquid/tags/unless.rb +33 -0
  31. data/lib/liquid/template.rb +150 -0
  32. data/lib/liquid/variable.rb +50 -0
  33. data/lib/liquid.rb +66 -0
  34. data/test/liquid/assign_test.rb +21 -0
  35. data/test/liquid/block_test.rb +58 -0
  36. data/test/liquid/capture_test.rb +40 -0
  37. data/test/liquid/condition_test.rb +127 -0
  38. data/test/liquid/context_test.rb +478 -0
  39. data/test/liquid/drop_test.rb +162 -0
  40. data/test/liquid/error_handling_test.rb +81 -0
  41. data/test/liquid/file_system_test.rb +29 -0
  42. data/test/liquid/filter_test.rb +106 -0
  43. data/test/liquid/module_ex_test.rb +87 -0
  44. data/test/liquid/output_test.rb +116 -0
  45. data/test/liquid/parsing_quirks_test.rb +52 -0
  46. data/test/liquid/regexp_test.rb +44 -0
  47. data/test/liquid/security_test.rb +41 -0
  48. data/test/liquid/standard_filter_test.rb +195 -0
  49. data/test/liquid/strainer_test.rb +25 -0
  50. data/test/liquid/tags/for_tag_test.rb +215 -0
  51. data/test/liquid/tags/html_tag_test.rb +39 -0
  52. data/test/liquid/tags/if_else_tag_test.rb +160 -0
  53. data/test/liquid/tags/include_tag_test.rb +139 -0
  54. data/test/liquid/tags/increment_tag_test.rb +24 -0
  55. data/test/liquid/tags/raw_tag_test.rb +15 -0
  56. data/test/liquid/tags/standard_tag_test.rb +295 -0
  57. data/test/liquid/tags/statements_test.rb +134 -0
  58. data/test/liquid/tags/unless_else_tag_test.rb +26 -0
  59. data/test/liquid/template_test.rb +74 -0
  60. data/test/liquid/variable_test.rb +170 -0
  61. data/test/test_helper.rb +29 -0
  62. metadata +136 -0
@@ -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
@@ -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 ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spinto-liquid
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.3.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Tobias Luetke
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-27 00:00:00.000000000Z
13
+ dependencies: []
14
+ description:
15
+ email:
16
+ - tobi@leetsoft.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files:
20
+ - History.md
21
+ - README.md
22
+ files:
23
+ - lib/extras/liquid_view.rb
24
+ - lib/liquid/block.rb
25
+ - lib/liquid/condition.rb
26
+ - lib/liquid/context.rb
27
+ - lib/liquid/document.rb
28
+ - lib/liquid/drop.rb
29
+ - lib/liquid/errors.rb
30
+ - lib/liquid/extensions.rb
31
+ - lib/liquid/file_system.rb
32
+ - lib/liquid/htmltags.rb
33
+ - lib/liquid/module_ex.rb
34
+ - lib/liquid/standardfilters.rb
35
+ - lib/liquid/strainer.rb
36
+ - lib/liquid/tag.rb
37
+ - lib/liquid/tags/assign.rb
38
+ - lib/liquid/tags/capture.rb
39
+ - lib/liquid/tags/case.rb
40
+ - lib/liquid/tags/comment.rb
41
+ - lib/liquid/tags/cycle.rb
42
+ - lib/liquid/tags/decrement.rb
43
+ - lib/liquid/tags/for.rb
44
+ - lib/liquid/tags/if.rb
45
+ - lib/liquid/tags/ifchanged.rb
46
+ - lib/liquid/tags/include.rb
47
+ - lib/liquid/tags/increment.rb
48
+ - lib/liquid/tags/raw.rb
49
+ - lib/liquid/tags/unless.rb
50
+ - lib/liquid/template.rb
51
+ - lib/liquid/variable.rb
52
+ - lib/liquid.rb
53
+ - MIT-LICENSE
54
+ - README.md
55
+ - test/liquid/assign_test.rb
56
+ - test/liquid/block_test.rb
57
+ - test/liquid/capture_test.rb
58
+ - test/liquid/condition_test.rb
59
+ - test/liquid/context_test.rb
60
+ - test/liquid/drop_test.rb
61
+ - test/liquid/error_handling_test.rb
62
+ - test/liquid/file_system_test.rb
63
+ - test/liquid/filter_test.rb
64
+ - test/liquid/module_ex_test.rb
65
+ - test/liquid/output_test.rb
66
+ - test/liquid/parsing_quirks_test.rb
67
+ - test/liquid/regexp_test.rb
68
+ - test/liquid/security_test.rb
69
+ - test/liquid/standard_filter_test.rb
70
+ - test/liquid/strainer_test.rb
71
+ - test/liquid/tags/for_tag_test.rb
72
+ - test/liquid/tags/html_tag_test.rb
73
+ - test/liquid/tags/if_else_tag_test.rb
74
+ - test/liquid/tags/include_tag_test.rb
75
+ - test/liquid/tags/increment_tag_test.rb
76
+ - test/liquid/tags/raw_tag_test.rb
77
+ - test/liquid/tags/standard_tag_test.rb
78
+ - test/liquid/tags/statements_test.rb
79
+ - test/liquid/tags/unless_else_tag_test.rb
80
+ - test/liquid/template_test.rb
81
+ - test/liquid/variable_test.rb
82
+ - test/test_helper.rb
83
+ - History.md
84
+ homepage: http://www.liquidmarkup.org
85
+ licenses: []
86
+ post_install_message:
87
+ rdoc_options: []
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: 1.3.7
102
+ requirements: []
103
+ rubyforge_project:
104
+ rubygems_version: 1.8.15
105
+ signing_key:
106
+ specification_version: 3
107
+ summary: A secure, non-evaling end user template engine with aesthetic markup.
108
+ test_files:
109
+ - test/liquid/assign_test.rb
110
+ - test/liquid/block_test.rb
111
+ - test/liquid/capture_test.rb
112
+ - test/liquid/condition_test.rb
113
+ - test/liquid/context_test.rb
114
+ - test/liquid/drop_test.rb
115
+ - test/liquid/error_handling_test.rb
116
+ - test/liquid/file_system_test.rb
117
+ - test/liquid/filter_test.rb
118
+ - test/liquid/module_ex_test.rb
119
+ - test/liquid/output_test.rb
120
+ - test/liquid/parsing_quirks_test.rb
121
+ - test/liquid/regexp_test.rb
122
+ - test/liquid/security_test.rb
123
+ - test/liquid/standard_filter_test.rb
124
+ - test/liquid/strainer_test.rb
125
+ - test/liquid/tags/for_tag_test.rb
126
+ - test/liquid/tags/html_tag_test.rb
127
+ - test/liquid/tags/if_else_tag_test.rb
128
+ - test/liquid/tags/include_tag_test.rb
129
+ - test/liquid/tags/increment_tag_test.rb
130
+ - test/liquid/tags/raw_tag_test.rb
131
+ - test/liquid/tags/standard_tag_test.rb
132
+ - test/liquid/tags/statements_test.rb
133
+ - test/liquid/tags/unless_else_tag_test.rb
134
+ - test/liquid/template_test.rb
135
+ - test/liquid/variable_test.rb
136
+ - test/test_helper.rb