slim 0.7.3 → 0.7.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,107 +0,0 @@
1
- require 'helper'
2
-
3
- class TestParserErrors < TestSlim
4
- def test_correct_filename
5
- source = %q{
6
- ! doctype 5
7
- div Invalid
8
- }
9
-
10
- assert_syntax_error "Unexpected indentation\n test.slim, Line 3\n div Invalid\n ^\n ", source, :file => 'test.slim'
11
- end
12
-
13
- def test_unexpected_indentation
14
- source = %q{
15
- ! doctype 5
16
- div Invalid
17
- }
18
-
19
- assert_syntax_error "Unexpected indentation\n (__TEMPLATE__), Line 3\n div Invalid\n ^\n ", source
20
- end
21
-
22
- def test_unexpected_text_indentation
23
- source = %q{
24
- p
25
- | text block
26
- text
27
- }
28
-
29
- assert_syntax_error "Unexpected text indentation\n (__TEMPLATE__), Line 4\n text\n ^\n ", source
30
- end
31
-
32
- def test_malformed_indentation
33
- source = %q{
34
- p
35
- div Valid
36
- div Invalid
37
- }
38
-
39
- assert_syntax_error "Malformed indentation\n (__TEMPLATE__), Line 4\n div Invalid\n ^\n ", source
40
- end
41
-
42
- def test_unknown_line_indicator
43
- source = %q{
44
- p
45
- div Valid
46
- .valid
47
- #valid
48
- ?invalid
49
- }
50
-
51
- assert_syntax_error "Unknown line indicator\n (__TEMPLATE__), Line 6\n ?invalid\n ^\n ", source
52
- end
53
-
54
- def test_expected_closing_delimiter
55
- source = %q{
56
- p
57
- img(src="img.jpg" title={title}
58
- }
59
-
60
- assert_syntax_error "Expected closing delimiter )\n (__TEMPLATE__), Line 3\n img(src=\"img.jpg\" title={title}\n ^\n ", source
61
- end
62
-
63
- def test_expected_closing_attribute_delimiter
64
- source = %q{
65
- p
66
- img src=[hash[1] + hash[2]
67
- }
68
-
69
- assert_syntax_error "Expected closing attribute delimiter ]\n (__TEMPLATE__), Line 3\n img src=[hash[1] + hash[2]\n ^\n ", source
70
- end
71
-
72
- def test_unexpected_closing
73
- source = %q{
74
- p
75
- img src=(1+1)]
76
- }
77
-
78
- assert_syntax_error "Unexpected closing ]\n (__TEMPLATE__), Line 3\n img src=(1+1)]\n ^\n ", source
79
- end
80
-
81
- def test_invalid_empty_attribute
82
- source = %q{
83
- p
84
- img{src= }
85
- }
86
-
87
- assert_syntax_error "Invalid empty attribute\n (__TEMPLATE__), Line 3\n img{src= }\n ^\n ", source
88
- end
89
-
90
- def test_invalid_empty_attribute2
91
- source = %q{
92
- p
93
- img{src=}
94
- }
95
-
96
- assert_syntax_error "Invalid empty attribute\n (__TEMPLATE__), Line 3\n img{src=}\n ^\n ", source
97
- end
98
-
99
- def test_invalid_empty_attribute3
100
- source = %q{
101
- p
102
- img src=
103
- }
104
-
105
- assert_syntax_error "Invalid empty attribute\n (__TEMPLATE__), Line 3\n img src=\n ^\n ", source
106
- end
107
- end
@@ -1,78 +0,0 @@
1
- require 'helper'
2
-
3
- require 'rubygems'
4
- require 'rails'
5
- require 'action_controller'
6
- require 'action_view'
7
- require 'slim/rails'
8
-
9
- class TestSlimRails < TestSlim
10
- def render(source, &block)
11
- view = ActionView::Base.new
12
- view.controller = ActionController::Base.new
13
- if defined?(ActionController::Response)
14
- # This is needed for >=3.0.0
15
- view.controller.response = ActionController::Response.new
16
- end
17
- view.render :inline => source, :type => :slim
18
- end
19
-
20
- def assert_html(expected, source, &block)
21
- assert_equal expected, render(source, &block)
22
- end
23
-
24
- def test_rails_template
25
- source = %q{
26
- html
27
- head
28
- title Simple Test Title
29
- body
30
- p Hello World, meet Slim.
31
- }
32
-
33
- assert_html '<html><head><title>Simple Test Title</title></head><body><p>Hello World, meet Slim.</p></body></html>', source
34
- end
35
-
36
- def test_content_for_without_output
37
- source = %q{
38
- = content_for :content do
39
- - if false
40
- .content_one
41
- - else
42
- .content_two
43
- }
44
-
45
- assert_html '', source
46
- end
47
-
48
- def test_content_for_with_output
49
- source = %q{
50
- = content_for :content do
51
- - if false
52
- .content_one
53
- - else
54
- .content_two
55
- p This is the captured content
56
- == content_for :content
57
- }
58
-
59
- assert_html '<p>This is the captured content</p><div class="content_two"></div>', source
60
- end
61
-
62
- def test_content_for_with_output2
63
- source = %q{
64
- - if true
65
- = content_for :content do
66
- p a1
67
- p a2
68
- - else
69
- = content_for :content do
70
- p b1
71
- p b2
72
- p This is the captured content
73
- == content_for :content
74
- }
75
-
76
- assert_html '<p>This is the captured content</p><p>a1</p><p>a2</p>', source
77
- end
78
- end
@@ -1,144 +0,0 @@
1
- require 'helper'
2
-
3
- class TestSlimRubyErrors < TestSlim
4
- def test_broken_output_line
5
- source = %q{
6
- p = hello_world + \
7
- hello_world + \
8
- unknown_ruby_method
9
- }
10
-
11
- assert_ruby_error NameError, "test.slim:4", source, :file => 'test.slim'
12
- end
13
-
14
- def test_broken_output_line2
15
- source = %q{
16
- p = hello_world + \
17
- hello_world
18
- p Hello
19
- = unknown_ruby_method
20
- }
21
-
22
- assert_ruby_error NameError,"(__TEMPLATE__):5", source
23
- end
24
-
25
- def test_output_block
26
- source = %q{
27
- p = hello_world "Hello Ruby" do
28
- = unknown_ruby_method
29
- }
30
-
31
- assert_ruby_error NameError,"(__TEMPLATE__):3", source
32
- end
33
-
34
- def test_output_block2
35
- source = %q{
36
- p = hello_world "Hello Ruby" do
37
- = "Hello from block"
38
- p Hello
39
- = unknown_ruby_method
40
- }
41
-
42
- assert_ruby_error NameError, "(__TEMPLATE__):5", source
43
- end
44
-
45
- def test_text_block
46
- source = %q{
47
- p Text line 1
48
- Text line 2
49
- = unknown_ruby_method
50
- }
51
-
52
- assert_ruby_error NameError,"(__TEMPLATE__):4", source
53
- end
54
-
55
- def test_text_block2
56
- source = %q{
57
- |
58
- Text line 1
59
- Text line 2
60
- = unknown_ruby_method
61
- }
62
-
63
- assert_ruby_error NameError,"(__TEMPLATE__):5", source
64
- end
65
-
66
- def test_comment
67
- source = %q{
68
- / Comment line 1
69
- Comment line 2
70
- = unknown_ruby_method
71
- }
72
-
73
- assert_ruby_error NameError,"(__TEMPLATE__):4", source
74
- end
75
-
76
- def test_embedded_ruby
77
- source = %q{
78
- ruby:
79
- a = 1
80
- b = 2
81
- = a + b
82
- = unknown_ruby_method
83
- }
84
-
85
- assert_ruby_error NameError,"(__TEMPLATE__):6", source
86
- end
87
-
88
- def test_embedded_javascript
89
- source = %q{
90
- javascript:
91
- alert();
92
- alert();
93
- = unknown_ruby_method
94
- }
95
-
96
- assert_ruby_error NameError,"(__TEMPLATE__):5", source
97
- end
98
-
99
- def test_invalid_nested_code
100
- source = %q{
101
- p
102
- - test = 123
103
- = "Hello from within a block! "
104
- }
105
- assert_ruby_syntax_error "(__TEMPLATE__):5", source
106
- end
107
-
108
- def test_invalid_nested_output
109
- source = %q{
110
- p
111
- = "Hello Ruby!"
112
- = "Hello from within a block! "
113
- }
114
- assert_ruby_syntax_error "(__TEMPLATE__):5", source
115
- end
116
-
117
- def test_invalid_embedded_engine
118
- source = %q{
119
- p
120
- embed_unknown:
121
- 1+1
122
- }
123
-
124
- assert_runtime_error 'Invalid embedded engine embed_unknown', source
125
- end
126
-
127
- def test_explicit_end
128
- source = %q{
129
- div
130
- - if show_first?
131
- p The first paragraph
132
- - end
133
- }
134
-
135
- assert_runtime_error 'Explicit end statements are forbidden', source
136
- end
137
-
138
- def test_id_attribute_merging2
139
- source = %{
140
- #alpha id="beta" Test it
141
- }
142
- assert_runtime_error 'Multiple id attributes specified, but id concatenation disabled', source
143
- end
144
- end
@@ -1,74 +0,0 @@
1
- require 'helper'
2
-
3
- class TestSlimLogicLess < TestSlim
4
- def test_sections
5
- source = %q{
6
- p
7
- - person
8
- .name = name
9
- }
10
-
11
- hash = {
12
- :person => [
13
- { :name => 'Joe', },
14
- { :name => 'Jack', }
15
- ]
16
- }
17
-
18
- assert_html '<p><div class="name">Joe</div><div class="name">Jack</div></p>', source, :scope => hash, :sections => true
19
- end
20
-
21
- def test_sections_string_access
22
- source = %q{
23
- p
24
- - person
25
- .name = name
26
- }
27
-
28
- hash = {
29
- 'person' => [
30
- { 'name' => 'Joe', },
31
- { 'name' => 'Jack', }
32
- ]
33
- }
34
-
35
- assert_html '<p><div class="name">Joe</div><div class="name">Jack</div></p>', source, :scope => hash, :sections => true, :dictionary_access => :string
36
- end
37
-
38
- def test_flag_section
39
- source = %q{
40
- p
41
- - show_person
42
- - person
43
- .name = name
44
- - show_person
45
- | shown
46
- }
47
-
48
- hash = {
49
- :show_person => true,
50
- :person => [
51
- { :name => 'Joe', },
52
- { :name => 'Jack', }
53
- ]
54
- }
55
-
56
- assert_html '<p><div class="name">Joe</div><div class="name">Jack</div>shown</p>', source, :scope => hash, :sections => true
57
- end
58
-
59
- def test_inverted_section
60
- source = %q{
61
- p
62
- - person
63
- .name = name
64
- -! person
65
- | No person
66
- - !person
67
- | No person 2
68
- }
69
-
70
- hash = {}
71
-
72
- assert_html '<p>No person No person 2</p>', source, :scope => hash, :sections => true
73
- end
74
- end
@@ -1,128 +0,0 @@
1
- require 'helper'
2
-
3
- class ::MockError < NameError
4
- end
5
-
6
- class TestSlimTemplate < MiniTest::Unit::TestCase
7
- class Scope
8
- include Tilt::CompileSite
9
- end
10
-
11
- def test_registered_extension
12
- assert_equal Slim::Template, Tilt['test.slim']
13
- end
14
-
15
- def test_preparing_and_evaluating
16
- template = Slim::Template.new { |t| "p Hello World!\n" }
17
- assert_equal "<p>Hello World!</p>", template.render
18
- end
19
-
20
- def test_passing_locals
21
- template = Slim::Template.new { "p = 'Hey ' + name + '!'\n" }
22
- assert_equal "<p>Hey Joe!</p>", template.render(Object.new, :name => 'Joe')
23
- end
24
-
25
- def test_evaluating_in_an_object_scope
26
- template = Slim::Template.new { "p = 'Hey ' + @name + '!'\n" }
27
- scope = Object.new
28
- scope.instance_variable_set :@name, 'Joe'
29
- assert_equal "<p>Hey Joe!</p>", template.render(scope)
30
- end
31
-
32
- def test_passing_a_block_for_yield
33
- template = Slim::Template.new { "p = 'Hey ' + yield + '!'\n" }
34
- assert_equal "<p>Hey Joe!</p>", template.render { 'Joe' }
35
- end
36
-
37
- def test_backtrace_file_and_line_reporting_without_locals
38
- data = File.read(__FILE__).split("\n__END__\n").last
39
- fail unless data[0] == ?h
40
- template = Slim::Template.new('test.slim', 10) { data }
41
- begin
42
- template.render
43
- fail 'should have raised an exception'
44
- rescue => boom
45
- assert_kind_of NameError, boom
46
- line = boom.backtrace.first
47
- assert_equal 'test.slim', line.split(":").first
48
- end
49
- end
50
-
51
- def test_backtrace_file_and_line_reporting_with_locals
52
- data = File.read(__FILE__).split("\n__END__\n").last
53
- fail unless data[0] == ?h
54
- template = Slim::Template.new('test.slim') { data }
55
- begin
56
- res = template.render(Object.new, :name => 'Joe', :foo => 'bar')
57
- rescue => boom
58
- assert_kind_of MockError, boom
59
- line = boom.backtrace.first
60
- assert_equal 'test.slim', line.split(":").first
61
- end
62
- end
63
-
64
- def test_compiling_template_source_to_a_method
65
- template = Slim::Template.new { |t| "Hello World!" }
66
- template.render(Scope.new)
67
- method_name = template.send(:compiled_method_name, [])
68
- method_name = method_name.to_sym if Symbol === Kernel.methods.first
69
- assert Tilt::CompileSite.instance_methods.include?(method_name),
70
- "CompileSite.instance_methods.include?(#{method_name.inspect})"
71
- assert Scope.new.respond_to?(method_name),
72
- "scope.respond_to?(#{method_name.inspect})"
73
- end
74
-
75
-
76
- def test_passing_locals
77
- template = Slim::Template.new { "p = 'Hey ' + name + '!'\n" }
78
- assert_equal "<p>Hey Joe!</p>", template.render(Scope.new, :name => 'Joe')
79
- end
80
-
81
- def test_evaluating_in_an_object_scope
82
- template = Slim::Template.new { "p = 'Hey ' + @name + '!'\n" }
83
- scope = Scope.new
84
- scope.instance_variable_set :@name, 'Joe'
85
- assert_equal "<p>Hey Joe!</p>", template.render(scope)
86
- end
87
-
88
- def test_passing_a_block_for_yield
89
- template = Slim::Template.new { "p = 'Hey ' + yield + '!'\n" }
90
- assert_equal "<p>Hey Joe!</p>", template.render(Scope.new) { 'Joe' }
91
- end
92
-
93
- def backtrace_file_and_line_reporting_without_locals
94
- data = File.read(__FILE__).split("\n__END__\n").last
95
- fail unless data[0] == ?h
96
- template = Slim::Template.new('test.slim', 10) { data }
97
- begin
98
- template.render(Scope.new)
99
- fail 'should have raised an exception'
100
- rescue => boom
101
- assert_kind_of NameError, boom
102
- line = boom.backtrace.first
103
- assert_equal 'test.slim', line.split(":").first
104
- end
105
- end
106
-
107
- def test_backtrace_file_and_line_reporting_with_locals
108
- data = File.read(__FILE__).split("\n__END__\n").last
109
- fail unless data[0] == ?h
110
- template = Slim::Template.new('test.slim') { data }
111
- begin
112
- res = template.render(Scope.new, :name => 'Joe', :foo => 'bar')
113
- rescue => boom
114
- assert_kind_of MockError, boom
115
- line = boom.backtrace.first
116
- assert_equal 'test.slim', line.split(":").first
117
- end
118
- end
119
- end
120
-
121
- __END__
122
- html
123
- body
124
- h1 = "Hey #{name}"
125
-
126
- = raise MockError
127
-
128
- p we never get here