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/include_tag_test.rb
DELETED
@@ -1,129 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/helper'
|
2
|
-
|
3
|
-
class TestFileSystem
|
4
|
-
def read_template_file(template_path)
|
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)
|
38
|
-
'from OtherFileSystem'
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
class IncludeTagTest < Test::Unit::TestCase
|
43
|
-
include Liquor
|
44
|
-
|
45
|
-
def setup
|
46
|
-
Liquor::Template.file_system = TestFileSystem.new
|
47
|
-
end
|
48
|
-
|
49
|
-
def test_include_tag_looks_for_file_system_in_registers_first
|
50
|
-
assert_equal 'from OtherFileSystem',
|
51
|
-
Template.parse("{% include 'pick_a_source' %}").render({}, :registers => {:file_system => OtherFileSystem.new})
|
52
|
-
end
|
53
|
-
|
54
|
-
|
55
|
-
def test_include_tag_with
|
56
|
-
assert_equal "Product: Draft 151cm ",
|
57
|
-
Template.parse("{% include 'product' with products[0] %}").render( "products" => [ {'title' => 'Draft 151cm'}, {'title' => 'Element 155cm'} ] )
|
58
|
-
end
|
59
|
-
|
60
|
-
def test_include_tag_with_default_name
|
61
|
-
assert_equal "Product: Draft 151cm ",
|
62
|
-
Template.parse("{% include 'product' %}").render( "product" => {'title' => 'Draft 151cm'} )
|
63
|
-
end
|
64
|
-
|
65
|
-
def test_include_tag_for
|
66
|
-
|
67
|
-
assert_equal "Product: Draft 151cm Product: Element 155cm ",
|
68
|
-
Template.parse("{% include 'product' for products %}").render( "products" => [ {'title' => 'Draft 151cm'}, {'title' => 'Element 155cm'} ] )
|
69
|
-
end
|
70
|
-
|
71
|
-
def test_include_tag_with_local_variables
|
72
|
-
assert_equal "Locale: test123 ",
|
73
|
-
Template.parse("{% include 'locale_variables' echo1: 'test123' %}").render
|
74
|
-
end
|
75
|
-
|
76
|
-
def test_include_tag_with_multiple_local_variables
|
77
|
-
assert_equal "Locale: test123 test321",
|
78
|
-
Template.parse("{% include 'locale_variables' echo1: 'test123', echo2: 'test321' %}").render
|
79
|
-
end
|
80
|
-
|
81
|
-
def test_include_tag_with_multiple_local_variables_from_context
|
82
|
-
assert_equal "Locale: test123 test321",
|
83
|
-
Template.parse("{% include 'locale_variables' echo1: echo1, echo2: more_echos.echo2 %}").render('echo1' => 'test123', 'more_echos' => { "echo2" => 'test321'})
|
84
|
-
end
|
85
|
-
|
86
|
-
def test_nested_include_tag
|
87
|
-
assert_equal "body body_detail",
|
88
|
-
Template.parse("{% include 'body' %}").render
|
89
|
-
|
90
|
-
assert_equal "header body body_detail footer",
|
91
|
-
Template.parse("{% include 'nested_template' %}").render
|
92
|
-
end
|
93
|
-
|
94
|
-
def test_nested_include_with_variable
|
95
|
-
|
96
|
-
assert_equal "Product: Draft 151cm details ",
|
97
|
-
Template.parse("{% include 'nested_product_template' with product %}").render("product" => {"title" => 'Draft 151cm'})
|
98
|
-
|
99
|
-
assert_equal "Product: Draft 151cm details Product: Element 155cm details ",
|
100
|
-
Template.parse("{% include 'nested_product_template' for products %}").render("products" => [{"title" => 'Draft 151cm'}, {"title" => 'Element 155cm'}])
|
101
|
-
|
102
|
-
end
|
103
|
-
|
104
|
-
def test_recursively_included_template_does_not_produce_endless_loop
|
105
|
-
|
106
|
-
infinite_file_system = Class.new do
|
107
|
-
def read_template_file(template_path)
|
108
|
-
"-{% include 'loop' %}"
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
Liquor::Template.file_system = infinite_file_system.new
|
113
|
-
|
114
|
-
assert_raise(Liquor::StackLevelError) do
|
115
|
-
Template.parse("{% include 'loop' %}").render!
|
116
|
-
end
|
117
|
-
|
118
|
-
end
|
119
|
-
|
120
|
-
def test_dynamically_choosen_template
|
121
|
-
|
122
|
-
assert_equal "Test123", Template.parse("{% include template %}").render("template" => 'Test123')
|
123
|
-
assert_equal "Test321", Template.parse("{% include template %}").render("template" => 'Test321')
|
124
|
-
|
125
|
-
assert_equal "Product: Draft 151cm ", Template.parse("{% include template for product %}").render("template" => 'product', 'product' => { 'title' => 'Draft 151cm'})
|
126
|
-
|
127
|
-
end
|
128
|
-
|
129
|
-
end
|
data/test/module_ex_test.rb
DELETED
@@ -1,89 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
require File.dirname(__FILE__) + '/helper'
|
3
|
-
|
4
|
-
class TestClassA
|
5
|
-
liquor_methods :allowedA, :chainedB
|
6
|
-
def allowedA
|
7
|
-
'allowedA'
|
8
|
-
end
|
9
|
-
def restrictedA
|
10
|
-
'restrictedA'
|
11
|
-
end
|
12
|
-
def chainedB
|
13
|
-
TestClassB.new
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
class TestClassB
|
18
|
-
liquor_methods :allowedB, :chainedC
|
19
|
-
def allowedB
|
20
|
-
'allowedB'
|
21
|
-
end
|
22
|
-
def chainedC
|
23
|
-
TestClassC.new
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
class TestClassC
|
28
|
-
liquor_methods :allowedC
|
29
|
-
def allowedC
|
30
|
-
'allowedC'
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
class TestClassC::LiquorDropClass
|
35
|
-
def another_allowedC
|
36
|
-
'another_allowedC'
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
class ModuleExTest < Test::Unit::TestCase
|
41
|
-
include Liquor
|
42
|
-
|
43
|
-
def setup
|
44
|
-
@a = TestClassA.new
|
45
|
-
@b = TestClassB.new
|
46
|
-
@c = TestClassC.new
|
47
|
-
end
|
48
|
-
|
49
|
-
def test_should_create_LiquorDropClass
|
50
|
-
assert TestClassA::LiquorDropClass
|
51
|
-
assert TestClassB::LiquorDropClass
|
52
|
-
assert TestClassC::LiquorDropClass
|
53
|
-
end
|
54
|
-
|
55
|
-
def test_should_respond_to_liquor
|
56
|
-
assert @a.respond_to?(:to_liquor)
|
57
|
-
assert @b.respond_to?(:to_liquor)
|
58
|
-
assert @c.respond_to?(:to_liquor)
|
59
|
-
end
|
60
|
-
|
61
|
-
def test_should_return_LiquorDropClass_object
|
62
|
-
assert @a.to_liquor.is_a?(TestClassA::LiquorDropClass)
|
63
|
-
assert @b.to_liquor.is_a?(TestClassB::LiquorDropClass)
|
64
|
-
assert @c.to_liquor.is_a?(TestClassC::LiquorDropClass)
|
65
|
-
end
|
66
|
-
|
67
|
-
def test_should_respond_to_liquor_methods
|
68
|
-
assert @a.to_liquor.respond_to?(:allowedA)
|
69
|
-
assert @a.to_liquor.respond_to?(:chainedB)
|
70
|
-
assert @b.to_liquor.respond_to?(:allowedB)
|
71
|
-
assert @b.to_liquor.respond_to?(:chainedC)
|
72
|
-
assert @c.to_liquor.respond_to?(:allowedC)
|
73
|
-
assert @c.to_liquor.respond_to?(:another_allowedC)
|
74
|
-
end
|
75
|
-
|
76
|
-
def test_should_not_respond_to_restricted_methods
|
77
|
-
assert ! @a.to_liquor.respond_to?(:restricted)
|
78
|
-
end
|
79
|
-
|
80
|
-
def test_should_use_regular_objects_as_drops
|
81
|
-
assert_equal 'allowedA', Liquor::Template.parse("{{ a.allowedA }}").render('a'=>@a)
|
82
|
-
assert_equal 'allowedB', Liquor::Template.parse("{{ a.chainedB.allowedB }}").render('a'=>@a)
|
83
|
-
assert_equal 'allowedC', Liquor::Template.parse("{{ a.chainedB.chainedC.allowedC }}").render('a'=>@a)
|
84
|
-
assert_equal 'another_allowedC', Liquor::Template.parse("{{ a.chainedB.chainedC.another_allowedC }}").render('a'=>@a)
|
85
|
-
assert_equal '', Liquor::Template.parse("{{ a.restricted }}").render('a'=>@a)
|
86
|
-
assert_equal '', Liquor::Template.parse("{{ a.unknown }}").render('a'=>@a)
|
87
|
-
end
|
88
|
-
|
89
|
-
end
|
data/test/output_test.rb
DELETED
@@ -1,121 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
require File.dirname(__FILE__) + '/helper'
|
3
|
-
|
4
|
-
module FunnyFilter
|
5
|
-
|
6
|
-
def make_funny(input)
|
7
|
-
'LOL'
|
8
|
-
end
|
9
|
-
|
10
|
-
def cite_funny(input)
|
11
|
-
"LOL: #{input}"
|
12
|
-
end
|
13
|
-
|
14
|
-
def add_smiley(input, smiley = ":-)")
|
15
|
-
"#{input} #{smiley}"
|
16
|
-
end
|
17
|
-
|
18
|
-
def add_tag(input, tag = "p", id = "foo")
|
19
|
-
%|<#{tag} id="#{id}">#{input}</#{tag}>|
|
20
|
-
end
|
21
|
-
|
22
|
-
def paragraph(input)
|
23
|
-
"<p>#{input}</p>"
|
24
|
-
end
|
25
|
-
|
26
|
-
def link_to(name, url)
|
27
|
-
%|<a href="#{url}">#{name}</a>|
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
|
32
|
-
class OutputTest < Test::Unit::TestCase
|
33
|
-
include Liquor
|
34
|
-
|
35
|
-
def setup
|
36
|
-
@assigns = {
|
37
|
-
'best_cars' => 'bmw',
|
38
|
-
'car' => {'bmw' => 'good', 'gm' => 'bad'}
|
39
|
-
}
|
40
|
-
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_variable
|
44
|
-
text = %| {{best_cars}} |
|
45
|
-
|
46
|
-
expected = %| bmw |
|
47
|
-
assert_equal expected, Template.parse(text).render(@assigns)
|
48
|
-
end
|
49
|
-
|
50
|
-
def test_variable_traversing
|
51
|
-
text = %| {{car.bmw}} {{car.gm}} {{car.bmw}} |
|
52
|
-
|
53
|
-
expected = %| good bad good |
|
54
|
-
assert_equal expected, Template.parse(text).render(@assigns)
|
55
|
-
end
|
56
|
-
|
57
|
-
def test_variable_piping
|
58
|
-
text = %( {{ car.gm | make_funny }} )
|
59
|
-
expected = %| LOL |
|
60
|
-
|
61
|
-
assert_equal expected, Template.parse(text).render(@assigns, :filters => [FunnyFilter])
|
62
|
-
end
|
63
|
-
|
64
|
-
def test_variable_piping_with_input
|
65
|
-
text = %( {{ car.gm | cite_funny }} )
|
66
|
-
expected = %| LOL: bad |
|
67
|
-
|
68
|
-
assert_equal expected, Template.parse(text).render(@assigns, :filters => [FunnyFilter])
|
69
|
-
end
|
70
|
-
|
71
|
-
def test_variable_piping_with_args
|
72
|
-
text = %! {{ car.gm | add_smiley : ':-(' }} !
|
73
|
-
expected = %| bad :-( |
|
74
|
-
|
75
|
-
assert_equal expected, Template.parse(text).render(@assigns, :filters => [FunnyFilter])
|
76
|
-
end
|
77
|
-
|
78
|
-
def test_variable_piping_with_no_args
|
79
|
-
text = %! {{ car.gm | add_smiley }} !
|
80
|
-
expected = %| bad :-) |
|
81
|
-
|
82
|
-
assert_equal expected, Template.parse(text).render(@assigns, :filters => [FunnyFilter])
|
83
|
-
end
|
84
|
-
|
85
|
-
def test_multiple_variable_piping_with_args
|
86
|
-
text = %! {{ car.gm | add_smiley : ':-(' | add_smiley : ':-('}} !
|
87
|
-
expected = %| bad :-( :-( |
|
88
|
-
|
89
|
-
assert_equal expected, Template.parse(text).render(@assigns, :filters => [FunnyFilter])
|
90
|
-
end
|
91
|
-
|
92
|
-
def test_variable_piping_with_args
|
93
|
-
text = %! {{ car.gm | add_tag : 'span', 'bar'}} !
|
94
|
-
expected = %| <span id="bar">bad</span> |
|
95
|
-
|
96
|
-
assert_equal expected, Template.parse(text).render(@assigns, :filters => [FunnyFilter])
|
97
|
-
end
|
98
|
-
|
99
|
-
def test_variable_piping_with_variable_args
|
100
|
-
text = %! {{ car.gm | add_tag : 'span', car.bmw}} !
|
101
|
-
expected = %| <span id="good">bad</span> |
|
102
|
-
|
103
|
-
assert_equal expected, Template.parse(text).render(@assigns, :filters => [FunnyFilter])
|
104
|
-
end
|
105
|
-
|
106
|
-
def test_multiple_pipings
|
107
|
-
text = %( {{ best_cars | cite_funny | paragraph }} )
|
108
|
-
expected = %| <p>LOL: bmw</p> |
|
109
|
-
|
110
|
-
assert_equal expected, Template.parse(text).render(@assigns, :filters => [FunnyFilter])
|
111
|
-
end
|
112
|
-
|
113
|
-
def test_link_to
|
114
|
-
text = %( {{ 'Typo' | link_to: 'http://typo.leetsoft.com' }} )
|
115
|
-
expected = %| <a href="http://typo.leetsoft.com">Typo</a> |
|
116
|
-
|
117
|
-
assert_equal expected, Template.parse(text).render(@assigns, :filters => [FunnyFilter])
|
118
|
-
end
|
119
|
-
|
120
|
-
|
121
|
-
end
|
data/test/parsing_quirks_test.rb
DELETED
@@ -1,54 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
require File.dirname(__FILE__) + '/helper'
|
3
|
-
|
4
|
-
class ParsingQuirksTest < Test::Unit::TestCase
|
5
|
-
include Liquor
|
6
|
-
|
7
|
-
def test_error_with_css
|
8
|
-
text = %| div { font-weight: bold; } |
|
9
|
-
template = Template.parse(text)
|
10
|
-
|
11
|
-
assert_equal text, template.render
|
12
|
-
assert_equal [String], template.root.nodelist.collect {|i| i.class}
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_raise_on_single_close_bracet
|
16
|
-
assert_raise(SyntaxError) do
|
17
|
-
Template.parse("text {{method} oh nos!")
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_raise_on_label_and_no_close_bracets
|
22
|
-
assert_raise(SyntaxError) do
|
23
|
-
Template.parse("TEST {{ ")
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_raise_on_label_and_no_close_bracets_percent
|
28
|
-
assert_raise(SyntaxError) do
|
29
|
-
Template.parse("TEST {% ")
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_error_on_empty_filter
|
34
|
-
assert_nothing_raised do
|
35
|
-
Template.parse("{{test |a|b|}}")
|
36
|
-
Template.parse("{{test}}")
|
37
|
-
Template.parse("{{|test|}}")
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_meaningless_parens
|
42
|
-
assigns = {'b' => 'bar', 'c' => 'baz'}
|
43
|
-
markup = "a == 'foo' or (b == 'bar' and c == 'baz') or false"
|
44
|
-
assert_template_result(' YES ',"{% if #{markup} %} YES {% endif %}", assigns)
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_unexpected_characters_silently_eat_logic
|
48
|
-
markup = "true && false"
|
49
|
-
assert_template_result(' YES ',"{% if #{markup} %} YES {% endif %}")
|
50
|
-
markup = "false || true"
|
51
|
-
assert_template_result('',"{% if #{markup} %} YES {% endif %}")
|
52
|
-
end
|
53
|
-
|
54
|
-
end
|
data/test/regexp_test.rb
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/helper'
|
2
|
-
|
3
|
-
class RegexpTest < Test::Unit::TestCase
|
4
|
-
include Liquor
|
5
|
-
|
6
|
-
def test_empty
|
7
|
-
assert_equal [], ''.scan(QuotedFragment)
|
8
|
-
end
|
9
|
-
|
10
|
-
def test_quote
|
11
|
-
assert_equal ['"arg 1"'], '"arg 1"'.scan(QuotedFragment)
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_words
|
15
|
-
assert_equal ['arg1', 'arg2'], 'arg1 arg2'.scan(QuotedFragment)
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_tags
|
19
|
-
assert_equal ['<tr>', '</tr>'], '<tr> </tr>'.scan(QuotedFragment)
|
20
|
-
assert_equal ['<tr></tr>'], '<tr></tr>'.scan(QuotedFragment)
|
21
|
-
assert_equal ['<style', 'class="hello">', '</style>'], %|<style class="hello">' </style>|.scan(QuotedFragment)
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_quoted_words
|
25
|
-
assert_equal ['arg1', 'arg2', '"arg 3"'], 'arg1 arg2 "arg 3"'.scan(QuotedFragment)
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_quoted_words
|
29
|
-
assert_equal ['arg1', 'arg2', "'arg 3'"], 'arg1 arg2 \'arg 3\''.scan(QuotedFragment)
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_quoted_words_in_the_middle
|
33
|
-
assert_equal ['arg1', 'arg2', '"arg 3"', 'arg4'], 'arg1 arg2 "arg 3" arg4 '.scan(QuotedFragment)
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_variable_parser
|
37
|
-
assert_equal ['var'], 'var'.scan(VariableParser)
|
38
|
-
assert_equal ['var', 'method'], 'var.method'.scan(VariableParser)
|
39
|
-
assert_equal ['var', '[method]'], 'var[method]'.scan(VariableParser)
|
40
|
-
assert_equal ['var', '[method]', '[0]'], 'var[method][0]'.scan(VariableParser)
|
41
|
-
assert_equal ['var', '["method"]', '[0]'], 'var["method"][0]'.scan(VariableParser)
|
42
|
-
assert_equal ['var', '[method]', '[0]', 'method'], 'var[method][0].method'.scan(VariableParser)
|
43
|
-
end
|
44
|
-
|
45
|
-
end
|
data/test/security_test.rb
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/helper'
|
2
|
-
|
3
|
-
module SecurityFilter
|
4
|
-
def add_one(input)
|
5
|
-
"#{input} + 1"
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
|
-
class SecurityTest < Test::Unit::TestCase
|
10
|
-
include Liquor
|
11
|
-
|
12
|
-
def test_no_instance_eval
|
13
|
-
text = %( {{ '1+1' | instance_eval }} )
|
14
|
-
expected = %| 1+1 |
|
15
|
-
|
16
|
-
assert_equal expected, Template.parse(text).render(@assigns)
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_no_existing_instance_eval
|
20
|
-
text = %( {{ '1+1' | __instance_eval__ }} )
|
21
|
-
expected = %| 1+1 |
|
22
|
-
|
23
|
-
assert_equal expected, Template.parse(text).render(@assigns)
|
24
|
-
end
|
25
|
-
|
26
|
-
|
27
|
-
def test_no_instance_eval_after_mixing_in_new_filter
|
28
|
-
text = %( {{ '1+1' | instance_eval }} )
|
29
|
-
expected = %| 1+1 |
|
30
|
-
|
31
|
-
assert_equal expected, Template.parse(text).render(@assigns)
|
32
|
-
end
|
33
|
-
|
34
|
-
|
35
|
-
def test_no_instance_eval_later_in_chain
|
36
|
-
text = %( {{ '1+1' | add_one | instance_eval }} )
|
37
|
-
expected = %| 1+1 + 1 |
|
38
|
-
|
39
|
-
assert_equal expected, Template.parse(text).render(@assigns, :filters => SecurityFilter)
|
40
|
-
end
|
41
|
-
end
|