liquor 0.1.1 → 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -9
- data/Gemfile +7 -0
- data/Guardfile +11 -0
- data/MIT-LICENSE +6 -2
- data/README.md +4 -122
- data/Rakefile +20 -23
- data/doc/language-spec.html +768 -0
- data/doc/language-spec.md +698 -0
- data/lib/liquor.rb +39 -68
- data/lib/liquor/ast_tools.rb +28 -0
- data/lib/liquor/compiler.rb +110 -0
- data/lib/liquor/context.rb +76 -254
- data/lib/liquor/diagnostics.rb +151 -0
- data/lib/liquor/drop/drop.rb +168 -0
- data/lib/liquor/drop/drop_delegation.rb +24 -0
- data/lib/liquor/drop/drop_scope.rb +118 -0
- data/lib/liquor/drop/dropable.rb +17 -0
- data/lib/liquor/emitter.rb +313 -0
- data/lib/liquor/extensions/kaminari.rb +14 -0
- data/lib/liquor/extensions/pagination.rb +235 -0
- data/lib/liquor/extensions/rails.rb +97 -0
- data/lib/liquor/extensions/thinking_sphinx.rb +14 -0
- data/lib/liquor/extensions/tire.rb +30 -0
- data/lib/liquor/external.rb +79 -0
- data/lib/liquor/function.rb +94 -0
- data/lib/liquor/grammar/lexer.rb +1223 -0
- data/lib/liquor/grammar/lexer.rl +297 -0
- data/lib/liquor/grammar/parser.racc +288 -0
- data/lib/liquor/grammar/parser.rb +885 -0
- data/lib/liquor/library.rb +41 -0
- data/lib/liquor/manager.rb +146 -0
- data/lib/liquor/runtime.rb +167 -0
- data/lib/liquor/stdlib/builtin_functions.rb +315 -0
- data/lib/liquor/stdlib/builtin_tags.rb +228 -0
- data/lib/liquor/stdlib/html_truncater.rb +162 -0
- data/lib/liquor/stdlib/partial_tags.rb +76 -0
- data/lib/liquor/tag.rb +83 -14
- data/lib/liquor/version.rb +1 -1
- data/liquor.gemspec +29 -6
- data/spec/builtins_spec.rb +264 -0
- data/spec/compiler_spec.rb +136 -0
- data/spec/context_spec.rb +49 -0
- data/spec/drop_delegation_spec.rb +21 -0
- data/spec/drop_spec.rb +222 -0
- data/spec/errors_spec.rb +40 -0
- data/spec/external_spec.rb +207 -0
- data/spec/function_spec.rb +80 -0
- data/spec/lexer_spec.rb +173 -0
- data/spec/library_spec.rb +18 -0
- data/spec/manager_spec.rb +84 -0
- data/spec/parser_spec.rb +381 -0
- data/spec/partials_spec.rb +74 -0
- data/spec/runtime_spec.rb +97 -0
- data/spec/spec_helper.rb +94 -0
- data/spec/tag_spec.rb +7 -0
- metadata +216 -173
- data/AUTHORS +0 -2
- data/CHANGELOG +0 -48
- data/Gemfile.lock +0 -91
- data/History.txt +0 -44
- data/LICENSE +0 -23
- data/example/server/example_servlet.rb +0 -37
- data/example/server/liquid_servlet.rb +0 -28
- data/example/server/liquor_servlet.rb +0 -28
- data/example/server/server.rb +0 -12
- data/example/server/templates/index.liquid +0 -6
- data/example/server/templates/index.liquor +0 -6
- data/example/server/templates/products.liquid +0 -45
- data/example/server/templates/products.liquor +0 -45
- data/init.rb +0 -8
- data/lib/extras/liquid_view.rb +0 -51
- data/lib/extras/liquor_view.rb +0 -51
- data/lib/liquor/block.rb +0 -101
- data/lib/liquor/condition.rb +0 -120
- data/lib/liquor/document.rb +0 -17
- data/lib/liquor/drop.rb +0 -256
- data/lib/liquor/errors.rb +0 -11
- data/lib/liquor/extensions.rb +0 -72
- data/lib/liquor/file_system.rb +0 -62
- data/lib/liquor/htmltags.rb +0 -74
- data/lib/liquor/module_ex.rb +0 -60
- data/lib/liquor/standardfilters.rb +0 -315
- data/lib/liquor/strainer.rb +0 -58
- data/lib/liquor/tags/assign.rb +0 -33
- data/lib/liquor/tags/capture.rb +0 -35
- data/lib/liquor/tags/case.rb +0 -83
- data/lib/liquor/tags/comment.rb +0 -9
- data/lib/liquor/tags/content_for.rb +0 -54
- data/lib/liquor/tags/cycle.rb +0 -59
- data/lib/liquor/tags/for.rb +0 -136
- data/lib/liquor/tags/if.rb +0 -80
- data/lib/liquor/tags/ifchanged.rb +0 -20
- data/lib/liquor/tags/include.rb +0 -56
- data/lib/liquor/tags/unless.rb +0 -33
- data/lib/liquor/tags/yield.rb +0 -49
- data/lib/liquor/template.rb +0 -181
- data/lib/liquor/variable.rb +0 -52
- data/performance/shopify.rb +0 -92
- data/performance/shopify/comment_form.rb +0 -33
- data/performance/shopify/database.rb +0 -45
- data/performance/shopify/json_filter.rb +0 -7
- data/performance/shopify/liquid.rb +0 -18
- data/performance/shopify/liquor.rb +0 -18
- data/performance/shopify/money_filter.rb +0 -18
- data/performance/shopify/paginate.rb +0 -93
- data/performance/shopify/shop_filter.rb +0 -98
- data/performance/shopify/tag_filter.rb +0 -25
- data/performance/shopify/vision.database.yml +0 -945
- data/performance/shopify/weight_filter.rb +0 -11
- data/performance/tests/dropify/article.liquid +0 -74
- data/performance/tests/dropify/blog.liquid +0 -33
- data/performance/tests/dropify/cart.liquid +0 -66
- data/performance/tests/dropify/collection.liquid +0 -22
- data/performance/tests/dropify/index.liquid +0 -47
- data/performance/tests/dropify/page.liquid +0 -8
- data/performance/tests/dropify/product.liquid +0 -68
- data/performance/tests/dropify/theme.liquid +0 -105
- data/performance/tests/ripen/article.liquid +0 -74
- data/performance/tests/ripen/blog.liquid +0 -13
- data/performance/tests/ripen/cart.liquid +0 -54
- data/performance/tests/ripen/collection.liquid +0 -29
- data/performance/tests/ripen/index.liquid +0 -32
- data/performance/tests/ripen/page.liquid +0 -4
- data/performance/tests/ripen/product.liquid +0 -75
- data/performance/tests/ripen/theme.liquid +0 -85
- data/performance/tests/tribble/404.liquid +0 -56
- data/performance/tests/tribble/article.liquid +0 -98
- data/performance/tests/tribble/blog.liquid +0 -41
- data/performance/tests/tribble/cart.liquid +0 -134
- data/performance/tests/tribble/collection.liquid +0 -70
- data/performance/tests/tribble/index.liquid +0 -94
- data/performance/tests/tribble/page.liquid +0 -56
- data/performance/tests/tribble/product.liquid +0 -116
- data/performance/tests/tribble/search.liquid +0 -51
- data/performance/tests/tribble/theme.liquid +0 -90
- data/performance/tests/vogue/article.liquid +0 -66
- data/performance/tests/vogue/blog.liquid +0 -32
- data/performance/tests/vogue/cart.liquid +0 -58
- data/performance/tests/vogue/collection.liquid +0 -19
- data/performance/tests/vogue/index.liquid +0 -22
- data/performance/tests/vogue/page.liquid +0 -3
- data/performance/tests/vogue/product.liquid +0 -62
- data/performance/tests/vogue/theme.liquid +0 -122
- data/test/assign_test.rb +0 -11
- data/test/block_test.rb +0 -58
- data/test/capture_test.rb +0 -41
- data/test/condition_test.rb +0 -115
- data/test/content_for_test.rb +0 -15
- data/test/context_test.rb +0 -479
- data/test/drop_test.rb +0 -162
- data/test/error_handling_test.rb +0 -89
- data/test/extra/breakpoint.rb +0 -547
- data/test/extra/caller.rb +0 -80
- data/test/file_system_test.rb +0 -30
- data/test/filter_test.rb +0 -147
- data/test/helper.rb +0 -24
- data/test/html_tag_test.rb +0 -31
- data/test/if_else_test.rb +0 -139
- data/test/include_tag_test.rb +0 -129
- data/test/module_ex_test.rb +0 -89
- data/test/output_test.rb +0 -121
- data/test/parsing_quirks_test.rb +0 -54
- data/test/regexp_test.rb +0 -45
- data/test/security_test.rb +0 -41
- data/test/standard_filter_test.rb +0 -170
- data/test/standard_tag_test.rb +0 -405
- data/test/statements_test.rb +0 -137
- data/test/strainer_test.rb +0 -27
- data/test/template_test.rb +0 -82
- data/test/test_helper.rb +0 -28
- data/test/unless_else_test.rb +0 -27
- data/test/variable_test.rb +0 -173
- data/test/yield_test.rb +0 -24
data/test/extra/caller.rb
DELETED
@@ -1,80 +0,0 @@
|
|
1
|
-
class Continuation # :nodoc:
|
2
|
-
def self.create(*args, &block) # :nodoc:
|
3
|
-
cc = nil; result = callcc {|c| cc = c; block.call(cc) if block and args.empty?}
|
4
|
-
result ||= args
|
5
|
-
return *[cc, *result]
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
|
-
class Binding; end # for RDoc
|
10
|
-
# This method returns the binding of the method that called your
|
11
|
-
# method. It will raise an Exception when you're not inside a method.
|
12
|
-
#
|
13
|
-
# It's used like this:
|
14
|
-
# def inc_counter(amount = 1)
|
15
|
-
# Binding.of_caller do |binding|
|
16
|
-
# # Create a lambda that will increase the variable 'counter'
|
17
|
-
# # in the caller of this method when called.
|
18
|
-
# inc = eval("lambda { |arg| counter += arg }", binding)
|
19
|
-
# # We can refer to amount from inside this block safely.
|
20
|
-
# inc.call(amount)
|
21
|
-
# end
|
22
|
-
# # No other statements can go here. Put them inside the block.
|
23
|
-
# end
|
24
|
-
# counter = 0
|
25
|
-
# 2.times { inc_counter }
|
26
|
-
# counter # => 2
|
27
|
-
#
|
28
|
-
# Binding.of_caller must be the last statement in the method.
|
29
|
-
# This means that you will have to put everything you want to
|
30
|
-
# do after the call to Binding.of_caller into the block of it.
|
31
|
-
# This should be no problem however, because Ruby has closures.
|
32
|
-
# If you don't do this an Exception will be raised. Because of
|
33
|
-
# the way that Binding.of_caller is implemented it has to be
|
34
|
-
# done this way.
|
35
|
-
def Binding.of_caller(&block)
|
36
|
-
old_critical = Thread.critical
|
37
|
-
Thread.critical = true
|
38
|
-
count = 0
|
39
|
-
cc, result, error, extra_data = Continuation.create(nil, nil)
|
40
|
-
error.call if error
|
41
|
-
|
42
|
-
tracer = lambda do |*args|
|
43
|
-
type, context, extra_data = args[0], args[4], args
|
44
|
-
if type == "return"
|
45
|
-
count += 1
|
46
|
-
# First this method and then calling one will return --
|
47
|
-
# the trace event of the second event gets the context
|
48
|
-
# of the method which called the method that called this
|
49
|
-
# method.
|
50
|
-
if count == 2
|
51
|
-
# It would be nice if we could restore the trace_func
|
52
|
-
# that was set before we swapped in our own one, but
|
53
|
-
# this is impossible without overloading set_trace_func
|
54
|
-
# in current Ruby.
|
55
|
-
set_trace_func(nil)
|
56
|
-
cc.call(eval("binding", context), nil, extra_data)
|
57
|
-
end
|
58
|
-
elsif type == "line" then
|
59
|
-
nil
|
60
|
-
elsif type == "c-return" and extra_data[3] == :set_trace_func then
|
61
|
-
nil
|
62
|
-
else
|
63
|
-
set_trace_func(nil)
|
64
|
-
error_msg = "Binding.of_caller used in non-method context or " +
|
65
|
-
"trailing statements of method using it aren't in the block."
|
66
|
-
cc.call(nil, lambda { raise(ArgumentError, error_msg) }, nil)
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
unless result
|
71
|
-
set_trace_func(tracer)
|
72
|
-
return nil
|
73
|
-
else
|
74
|
-
Thread.critical = old_critical
|
75
|
-
case block.arity
|
76
|
-
when 1 then yield(result)
|
77
|
-
else yield(result, extra_data)
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
data/test/file_system_test.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
require File.dirname(__FILE__) + '/helper'
|
3
|
-
|
4
|
-
class FileSystemTest < Test::Unit::TestCase
|
5
|
-
include Liquor
|
6
|
-
|
7
|
-
def test_default
|
8
|
-
assert_raise(FileSystemError) do
|
9
|
-
BlankFileSystem.new.read_template_file("dummy")
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_local
|
14
|
-
file_system = Liquor::LocalFileSystem.new("/some/path")
|
15
|
-
assert_equal "/some/path/_mypartial.liquor" , file_system.full_path("mypartial")
|
16
|
-
assert_equal "/some/path/dir/_mypartial.liquor", file_system.full_path("dir/mypartial")
|
17
|
-
|
18
|
-
assert_raise(FileSystemError) do
|
19
|
-
file_system.full_path("../dir/mypartial")
|
20
|
-
end
|
21
|
-
|
22
|
-
assert_raise(FileSystemError) do
|
23
|
-
file_system.full_path("/dir/../../dir/mypartial")
|
24
|
-
end
|
25
|
-
|
26
|
-
assert_raise(FileSystemError) do
|
27
|
-
file_system.full_path("/etc/passwd")
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
data/test/filter_test.rb
DELETED
@@ -1,147 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
require File.dirname(__FILE__) + '/helper'
|
3
|
-
|
4
|
-
module MoneyFilter
|
5
|
-
def money(input)
|
6
|
-
sprintf(' %d$ ', input)
|
7
|
-
end
|
8
|
-
|
9
|
-
def money_with_underscore(input)
|
10
|
-
sprintf(' %d$ ', input)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
module CanadianMoneyFilter
|
15
|
-
def money(input)
|
16
|
-
sprintf(' %d$ CAD ', input)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
module FiltersWithArguments
|
21
|
-
def adjust(input, offset=10)
|
22
|
-
sprintf('[%d]', input+offset)
|
23
|
-
end
|
24
|
-
|
25
|
-
def addsub(input, plus, minus=20)
|
26
|
-
sprintf('[%d]', input+plus-minus)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
class FiltersTest < Test::Unit::TestCase
|
31
|
-
include Liquor
|
32
|
-
|
33
|
-
def setup
|
34
|
-
@context = Context.new
|
35
|
-
end
|
36
|
-
|
37
|
-
#def test_nonexistent_filter
|
38
|
-
# @context['var'] = 1000
|
39
|
-
# assert_match /Error - filter 'money'/, Variable.new("var | money").render(@context)
|
40
|
-
#end
|
41
|
-
|
42
|
-
def test_nonexistent_filter
|
43
|
-
@context['var'] = 1000
|
44
|
-
# assert_raises(FilterNotFound) { Variable.new("var | xyzzy").render(@context) }
|
45
|
-
assert_equal 1000, Variable.new("var | xyzzy").render(@context)
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_local_filter
|
49
|
-
@context['var'] = 1000
|
50
|
-
@context.add_filters(MoneyFilter)
|
51
|
-
assert_equal ' 1000$ ', Variable.new("var | money").render(@context)
|
52
|
-
end
|
53
|
-
|
54
|
-
def test_underscore_in_filter_name
|
55
|
-
@context['var'] = 1000
|
56
|
-
@context.add_filters(MoneyFilter)
|
57
|
-
assert_equal ' 1000$ ', Variable.new("var | money_with_underscore").render(@context)
|
58
|
-
end
|
59
|
-
|
60
|
-
def test_filter_with_numeric_argument
|
61
|
-
@context['var'] = 1000
|
62
|
-
@context.add_filters(FiltersWithArguments)
|
63
|
-
assert_equal '[1005]', Variable.new("var | adjust: 5").render(@context)
|
64
|
-
end
|
65
|
-
|
66
|
-
def test_filter_with_negative_argument
|
67
|
-
@context['var'] = 1000
|
68
|
-
@context.add_filters(FiltersWithArguments)
|
69
|
-
assert_equal '[995]', Variable.new("var | adjust: -5").render(@context)
|
70
|
-
end
|
71
|
-
|
72
|
-
def test_filter_with_default_argument
|
73
|
-
@context['var'] = 1000
|
74
|
-
@context.add_filters(FiltersWithArguments)
|
75
|
-
assert_equal '[1010]', Variable.new("var | adjust").render(@context)
|
76
|
-
end
|
77
|
-
|
78
|
-
def test_filter_with_two_arguments
|
79
|
-
@context['var'] = 1000
|
80
|
-
@context.add_filters(FiltersWithArguments)
|
81
|
-
assert_equal '[1150]', Variable.new("var | addsub: 200, 50").render(@context)
|
82
|
-
end
|
83
|
-
|
84
|
-
# ATM the trailing value is silently ignored. Should raise an exception?
|
85
|
-
#def test_filter_with_two_arguments_no_comma
|
86
|
-
# @context['var'] = 1000
|
87
|
-
# @context.add_filters(FiltersWithArguments)
|
88
|
-
# assert_equal '[1150]', Variable.new("var | addsub: 200 50").render(@context)
|
89
|
-
#end
|
90
|
-
|
91
|
-
def test_second_filter_overwrites_first
|
92
|
-
@context['var'] = 1000
|
93
|
-
@context.add_filters(MoneyFilter)
|
94
|
-
@context.add_filters(CanadianMoneyFilter)
|
95
|
-
assert_equal ' 1000$ CAD ', Variable.new("var | money").render(@context)
|
96
|
-
end
|
97
|
-
|
98
|
-
def test_size
|
99
|
-
@context['var'] = 'abcd'
|
100
|
-
@context.add_filters(MoneyFilter)
|
101
|
-
assert_equal 4, Variable.new("var | size").render(@context)
|
102
|
-
end
|
103
|
-
|
104
|
-
def test_join
|
105
|
-
@context['var'] = [1,2,3,4]
|
106
|
-
assert_equal "1 2 3 4", Variable.new("var | join").render(@context)
|
107
|
-
end
|
108
|
-
|
109
|
-
def test_sort
|
110
|
-
@context['value'] = 3
|
111
|
-
@context['numbers'] = [2,1,4,3]
|
112
|
-
@context['words'] = ['expected', 'as', 'alphabetic']
|
113
|
-
@context['arrays'] = [['flattened'], ['are']]
|
114
|
-
assert_equal [1,2,3,4], Variable.new("numbers | sort").render(@context)
|
115
|
-
assert_equal ['alphabetic', 'as', 'expected'],
|
116
|
-
Variable.new("words | sort").render(@context)
|
117
|
-
assert_equal [3], Variable.new("value | sort").render(@context)
|
118
|
-
assert_equal ['are', 'flattened'], Variable.new("arrays | sort").render(@context)
|
119
|
-
end
|
120
|
-
|
121
|
-
def test_strip_html
|
122
|
-
@context['var'] = "<b>bla blub</a>"
|
123
|
-
assert_equal "bla blub", Variable.new("var | strip_html").render(@context)
|
124
|
-
end
|
125
|
-
|
126
|
-
def test_capitalize
|
127
|
-
@context['var'] = "blub"
|
128
|
-
assert_equal "Blub", Variable.new("var | capitalize").render(@context)
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
class FiltersInTemplate < Test::Unit::TestCase
|
133
|
-
include Liquor
|
134
|
-
|
135
|
-
def test_local_global
|
136
|
-
Template.register_filter(MoneyFilter)
|
137
|
-
|
138
|
-
assert_equal " 1000$ ", Template.parse("{{1000 | money}}").render(nil, nil)
|
139
|
-
assert_equal " 1000$ CAD ", Template.parse("{{1000 | money}}").render(nil, :filters => CanadianMoneyFilter)
|
140
|
-
assert_equal " 1000$ CAD ", Template.parse("{{1000 | money}}").render(nil, :filters => [CanadianMoneyFilter])
|
141
|
-
end
|
142
|
-
|
143
|
-
def test_local_filter_with_deprecated_syntax
|
144
|
-
assert_equal " 1000$ CAD ", Template.parse("{{1000 | money}}").render(nil, CanadianMoneyFilter)
|
145
|
-
assert_equal " 1000$ CAD ", Template.parse("{{1000 | money}}").render(nil, [CanadianMoneyFilter])
|
146
|
-
end
|
147
|
-
end
|
data/test/helper.rb
DELETED
@@ -1,24 +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
|
-
|
9
|
-
require 'rubygems'
|
10
|
-
require 'active_support'
|
11
|
-
require 'active_record'
|
12
|
-
require File.dirname(__FILE__) + '/../lib/liquor'
|
13
|
-
|
14
|
-
|
15
|
-
module Test
|
16
|
-
module Unit
|
17
|
-
module Assertions
|
18
|
-
include Liquor
|
19
|
-
def assert_template_result(expected, template, assigns={}, message=nil)
|
20
|
-
assert_equal expected, Template.parse(template).render(assigns)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
data/test/html_tag_test.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/helper'
|
2
|
-
|
3
|
-
class HtmlTagTest < Test::Unit::TestCase
|
4
|
-
include Liquor
|
5
|
-
|
6
|
-
def test_html_table
|
7
|
-
|
8
|
-
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",
|
9
|
-
'{% tablerow n in numbers cols:3%} {{n}} {% endtablerow %}',
|
10
|
-
'numbers' => [1,2,3,4,5,6])
|
11
|
-
|
12
|
-
assert_template_result("<tr class=\"row1\">\n</tr>\n",
|
13
|
-
'{% tablerow n in numbers cols:3%} {{n}} {% endtablerow %}',
|
14
|
-
'numbers' => [])
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_html_table_with_different_cols
|
18
|
-
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",
|
19
|
-
'{% tablerow n in numbers cols:5%} {{n}} {% endtablerow %}',
|
20
|
-
'numbers' => [1,2,3,4,5,6])
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_html_col_counter
|
25
|
-
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",
|
26
|
-
'{% tablerow n in numbers cols:2%}{{tablerowloop.col}}{% endtablerow %}',
|
27
|
-
'numbers' => [1,2,3,4,5,6])
|
28
|
-
|
29
|
-
end
|
30
|
-
|
31
|
-
end
|
data/test/if_else_test.rb
DELETED
@@ -1,139 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/helper'
|
2
|
-
|
3
|
-
class IfElseTest < Test::Unit::TestCase
|
4
|
-
include Liquor
|
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_if_and
|
48
|
-
assert_template_result(' YES ','{% if true and true %} YES {% endif %}')
|
49
|
-
assert_template_result('','{% if false and true %} YES {% endif %}')
|
50
|
-
assert_template_result('','{% if false and true %} YES {% endif %}')
|
51
|
-
end
|
52
|
-
|
53
|
-
|
54
|
-
def test_hash_miss_generates_false
|
55
|
-
assert_template_result('','{% if foo.bar %} NO {% endif %}', 'foo' => {})
|
56
|
-
end
|
57
|
-
|
58
|
-
def test_if_from_variable
|
59
|
-
assert_template_result('','{% if var %} NO {% endif %}', 'var' => false)
|
60
|
-
assert_template_result('','{% if var %} NO {% endif %}', 'var' => nil)
|
61
|
-
assert_template_result('','{% if foo.bar %} NO {% endif %}', 'foo' => {'bar' => false})
|
62
|
-
assert_template_result('','{% if foo.bar %} NO {% endif %}', 'foo' => {})
|
63
|
-
assert_template_result('','{% if foo.bar %} NO {% endif %}', 'foo' => nil)
|
64
|
-
assert_template_result('','{% if foo.bar %} NO {% endif %}', 'foo' => true)
|
65
|
-
|
66
|
-
assert_template_result(' YES ','{% if var %} YES {% endif %}', 'var' => "text")
|
67
|
-
assert_template_result(' YES ','{% if var %} YES {% endif %}', 'var' => true)
|
68
|
-
assert_template_result(' YES ','{% if var %} YES {% endif %}', 'var' => 1)
|
69
|
-
assert_template_result(' YES ','{% if var %} YES {% endif %}', 'var' => {})
|
70
|
-
assert_template_result(' YES ','{% if var %} YES {% endif %}', 'var' => [])
|
71
|
-
assert_template_result(' YES ','{% if "foo" %} YES {% endif %}')
|
72
|
-
assert_template_result(' YES ','{% if foo.bar %} YES {% endif %}', 'foo' => {'bar' => true})
|
73
|
-
assert_template_result(' YES ','{% if foo.bar %} YES {% endif %}', 'foo' => {'bar' => "text"})
|
74
|
-
assert_template_result(' YES ','{% if foo.bar %} YES {% endif %}', 'foo' => {'bar' => 1 })
|
75
|
-
assert_template_result(' YES ','{% if foo.bar %} YES {% endif %}', 'foo' => {'bar' => {} })
|
76
|
-
assert_template_result(' YES ','{% if foo.bar %} YES {% endif %}', 'foo' => {'bar' => [] })
|
77
|
-
|
78
|
-
assert_template_result(' YES ','{% if var %} NO {% else %} YES {% endif %}', 'var' => false)
|
79
|
-
assert_template_result(' YES ','{% if var %} NO {% else %} YES {% endif %}', 'var' => nil)
|
80
|
-
assert_template_result(' YES ','{% if var %} YES {% else %} NO {% endif %}', 'var' => true)
|
81
|
-
assert_template_result(' YES ','{% if "foo" %} YES {% else %} NO {% endif %}', 'var' => "text")
|
82
|
-
|
83
|
-
assert_template_result(' YES ','{% if foo.bar %} NO {% else %} YES {% endif %}', 'foo' => {'bar' => false})
|
84
|
-
assert_template_result(' YES ','{% if foo.bar %} YES {% else %} NO {% endif %}', 'foo' => {'bar' => true})
|
85
|
-
assert_template_result(' YES ','{% if foo.bar %} YES {% else %} NO {% endif %}', 'foo' => {'bar' => "text"})
|
86
|
-
assert_template_result(' YES ','{% if foo.bar %} NO {% else %} YES {% endif %}', 'foo' => {'notbar' => true})
|
87
|
-
assert_template_result(' YES ','{% if foo.bar %} NO {% else %} YES {% endif %}', 'foo' => {})
|
88
|
-
assert_template_result(' YES ','{% if foo.bar %} NO {% else %} YES {% endif %}', 'notfoo' => {'bar' => true})
|
89
|
-
end
|
90
|
-
|
91
|
-
def test_nested_if
|
92
|
-
assert_template_result('', '{% if false %}{% if false %} NO {% endif %}{% endif %}')
|
93
|
-
assert_template_result('', '{% if false %}{% if true %} NO {% endif %}{% endif %}')
|
94
|
-
assert_template_result('', '{% if true %}{% if false %} NO {% endif %}{% endif %}')
|
95
|
-
assert_template_result(' YES ', '{% if true %}{% if true %} YES {% endif %}{% endif %}')
|
96
|
-
|
97
|
-
assert_template_result(' YES ', '{% if true %}{% if true %} YES {% else %} NO {% endif %}{% else %} NO {% endif %}')
|
98
|
-
assert_template_result(' YES ', '{% if true %}{% if false %} NO {% else %} YES {% endif %}{% else %} NO {% endif %}')
|
99
|
-
assert_template_result(' YES ', '{% if false %}{% if true %} NO {% else %} NONO {% endif %}{% else %} YES {% endif %}')
|
100
|
-
|
101
|
-
end
|
102
|
-
|
103
|
-
def test_comparisons_on_null
|
104
|
-
assert_template_result('','{% if null < 10 %} NO {% endif %}')
|
105
|
-
assert_template_result('','{% if null <= 10 %} NO {% endif %}')
|
106
|
-
assert_template_result('','{% if null >= 10 %} NO {% endif %}')
|
107
|
-
assert_template_result('','{% if null > 10 %} NO {% endif %}')
|
108
|
-
|
109
|
-
assert_template_result('','{% if 10 < null %} NO {% endif %}')
|
110
|
-
assert_template_result('','{% if 10 <= null %} NO {% endif %}')
|
111
|
-
assert_template_result('','{% if 10 >= null %} NO {% endif %}')
|
112
|
-
assert_template_result('','{% if 10 > null %} NO {% endif %}')
|
113
|
-
end
|
114
|
-
|
115
|
-
def test_else_if
|
116
|
-
assert_template_result('0','{% if 0 == 0 %}0{% elsif 1 == 1%}1{% else %}2{% endif %}')
|
117
|
-
assert_template_result('1','{% if 0 != 0 %}0{% elsif 1 == 1%}1{% else %}2{% endif %}')
|
118
|
-
assert_template_result('2','{% if 0 != 0 %}0{% elsif 1 != 1%}1{% else %}2{% endif %}')
|
119
|
-
|
120
|
-
assert_template_result('elsif','{% if false %}if{% elsif true %}elsif{% endif %}')
|
121
|
-
end
|
122
|
-
|
123
|
-
def test_syntax_error_no_variable
|
124
|
-
assert_raise(SyntaxError){ assert_template_result('', '{% if jerry == 1 %}')}
|
125
|
-
end
|
126
|
-
|
127
|
-
def test_syntax_error_no_expression
|
128
|
-
assert_raise(SyntaxError) { assert_template_result('', '{% if %}') }
|
129
|
-
end
|
130
|
-
|
131
|
-
def test_if_with_custom_condition
|
132
|
-
Condition.operators['contains'] = :[]
|
133
|
-
|
134
|
-
assert_template_result('yes', %({% if 'bob' contains 'o' %}yes{% endif %}))
|
135
|
-
assert_template_result('no', %({% if 'bob' contains 'f' %}yes{% else %}no{% endif %}))
|
136
|
-
ensure
|
137
|
-
Condition.operators.delete 'contains'
|
138
|
-
end
|
139
|
-
end
|