liquid 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. data/CHANGELOG +38 -0
  2. data/MIT-LICENSE +20 -0
  3. data/Manifest.txt +60 -0
  4. data/README +38 -0
  5. data/Rakefile +24 -0
  6. data/example/server/example_servlet.rb +37 -0
  7. data/example/server/liquid_servlet.rb +28 -0
  8. data/example/server/server.rb +12 -0
  9. data/example/server/templates/index.liquid +6 -0
  10. data/example/server/templates/products.liquid +45 -0
  11. data/init.rb +6 -0
  12. data/lib/extras/liquid_view.rb +27 -0
  13. data/lib/liquid.rb +66 -0
  14. data/lib/liquid/block.rb +101 -0
  15. data/lib/liquid/condition.rb +91 -0
  16. data/lib/liquid/context.rb +216 -0
  17. data/lib/liquid/document.rb +17 -0
  18. data/lib/liquid/drop.rb +48 -0
  19. data/lib/liquid/errors.rb +7 -0
  20. data/lib/liquid/extensions.rb +56 -0
  21. data/lib/liquid/file_system.rb +62 -0
  22. data/lib/liquid/htmltags.rb +64 -0
  23. data/lib/liquid/standardfilters.rb +125 -0
  24. data/lib/liquid/strainer.rb +43 -0
  25. data/lib/liquid/tag.rb +25 -0
  26. data/lib/liquid/tags/assign.rb +22 -0
  27. data/lib/liquid/tags/capture.rb +22 -0
  28. data/lib/liquid/tags/case.rb +68 -0
  29. data/lib/liquid/tags/comment.rb +9 -0
  30. data/lib/liquid/tags/cycle.rb +46 -0
  31. data/lib/liquid/tags/for.rb +81 -0
  32. data/lib/liquid/tags/if.rb +51 -0
  33. data/lib/liquid/tags/ifchanged.rb +20 -0
  34. data/lib/liquid/tags/include.rb +56 -0
  35. data/lib/liquid/tags/unless.rb +29 -0
  36. data/lib/liquid/template.rb +150 -0
  37. data/lib/liquid/variable.rb +39 -0
  38. data/test/block_test.rb +50 -0
  39. data/test/context_test.rb +340 -0
  40. data/test/drop_test.rb +139 -0
  41. data/test/error_handling_test.rb +65 -0
  42. data/test/extra/breakpoint.rb +547 -0
  43. data/test/extra/caller.rb +80 -0
  44. data/test/file_system_test.rb +30 -0
  45. data/test/filter_test.rb +98 -0
  46. data/test/helper.rb +20 -0
  47. data/test/html_tag_test.rb +24 -0
  48. data/test/if_else_test.rb +95 -0
  49. data/test/include_tag_test.rb +91 -0
  50. data/test/output_test.rb +121 -0
  51. data/test/parsing_quirks_test.rb +14 -0
  52. data/test/regexp_test.rb +39 -0
  53. data/test/security_test.rb +41 -0
  54. data/test/standard_filter_test.rb +101 -0
  55. data/test/standard_tag_test.rb +336 -0
  56. data/test/statements_test.rb +137 -0
  57. data/test/strainer_test.rb +16 -0
  58. data/test/template_test.rb +26 -0
  59. data/test/unless_else_test.rb +19 -0
  60. data/test/variable_test.rb +135 -0
  61. metadata +114 -0
@@ -0,0 +1,137 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/helper'
3
+
4
+ class StatementsTest < Test::Unit::TestCase
5
+ include Liquid
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
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/helper'
3
+
4
+ class StrainerTest < Test::Unit::TestCase
5
+ include Liquid
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
+ end
@@ -0,0 +1,26 @@
1
+ require File.dirname(__FILE__) + '/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
+ end
@@ -0,0 +1,19 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+
3
+ class UnlessElseTest < 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
+ end
@@ -0,0 +1,135 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/helper'
3
+
4
+ class VariableTest < Test::Unit::TestCase
5
+ include Liquid
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 Liquid
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
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.0
3
+ specification_version: 1
4
+ name: liquid
5
+ version: !ruby/object:Gem::Version
6
+ version: 1.7.0
7
+ date: 2006-10-09 00:00:00 -04:00
8
+ summary: A secure non evaling end user template engine with aesthetic markup.
9
+ require_paths:
10
+ - lib
11
+ - test
12
+ email: tobi@leetsoft.com
13
+ homepage: http://home.leetsoft.com/liquid
14
+ rubyforge_project: liquid
15
+ description:
16
+ autorequire:
17
+ default_executable:
18
+ bindir: bin
19
+ has_rdoc: true
20
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
21
+ requirements:
22
+ - - ">"
23
+ - !ruby/object:Gem::Version
24
+ version: 0.0.0
25
+ version:
26
+ platform: ruby
27
+ signing_key:
28
+ cert_chain:
29
+ post_install_message:
30
+ authors:
31
+ - Tobias Luetke
32
+ files:
33
+ - CHANGELOG
34
+ - MIT-LICENSE
35
+ - Manifest.txt
36
+ - README
37
+ - Rakefile
38
+ - example/server/example_servlet.rb
39
+ - example/server/liquid_servlet.rb
40
+ - example/server/server.rb
41
+ - example/server/templates/index.liquid
42
+ - example/server/templates/products.liquid
43
+ - init.rb
44
+ - lib/extras/liquid_view.rb
45
+ - lib/liquid.rb
46
+ - lib/liquid/block.rb
47
+ - lib/liquid/condition.rb
48
+ - lib/liquid/context.rb
49
+ - lib/liquid/document.rb
50
+ - lib/liquid/drop.rb
51
+ - lib/liquid/errors.rb
52
+ - lib/liquid/extensions.rb
53
+ - lib/liquid/file_system.rb
54
+ - lib/liquid/htmltags.rb
55
+ - lib/liquid/standardfilters.rb
56
+ - lib/liquid/strainer.rb
57
+ - lib/liquid/tag.rb
58
+ - lib/liquid/tags/assign.rb
59
+ - lib/liquid/tags/capture.rb
60
+ - lib/liquid/tags/case.rb
61
+ - lib/liquid/tags/comment.rb
62
+ - lib/liquid/tags/cycle.rb
63
+ - lib/liquid/tags/for.rb
64
+ - lib/liquid/tags/if.rb
65
+ - lib/liquid/tags/ifchanged.rb
66
+ - lib/liquid/tags/include.rb
67
+ - lib/liquid/tags/unless.rb
68
+ - lib/liquid/template.rb
69
+ - lib/liquid/variable.rb
70
+ - test/block_test.rb
71
+ - test/context_test.rb
72
+ - test/drop_test.rb
73
+ - test/error_handling_test.rb
74
+ - test/extra/breakpoint.rb
75
+ - test/extra/caller.rb
76
+ - test/file_system_test.rb
77
+ - test/filter_test.rb
78
+ - test/helper.rb
79
+ - test/html_tag_test.rb
80
+ - test/if_else_test.rb
81
+ - test/include_tag_test.rb
82
+ - test/output_test.rb
83
+ - test/parsing_quirks_test.rb
84
+ - test/regexp_test.rb
85
+ - test/security_test.rb
86
+ - test/standard_filter_test.rb
87
+ - test/standard_tag_test.rb
88
+ - test/statements_test.rb
89
+ - test/strainer_test.rb
90
+ - test/template_test.rb
91
+ - test/unless_else_test.rb
92
+ - test/variable_test.rb
93
+ test_files: []
94
+
95
+ rdoc_options: []
96
+
97
+ extra_rdoc_files: []
98
+
99
+ executables: []
100
+
101
+ extensions: []
102
+
103
+ requirements: []
104
+
105
+ dependencies:
106
+ - !ruby/object:Gem::Dependency
107
+ name: hoe
108
+ version_requirement:
109
+ version_requirements: !ruby/object:Gem::Version::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: 1.1.0
114
+ version: