hamlet 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,7 +3,7 @@ require 'helper'
3
3
  class TestSlimCodeEvaluation < TestSlim
4
4
  def test_render_with_call_to_set_attributes
5
5
  source = %q{
6
- p id="#{id_helper}" class="hello world" = hello_world
6
+ <p id="#{id_helper}" class="hello world">= hello_world
7
7
  }
8
8
 
9
9
  assert_html '<p class="hello world" id="notice">Hello World from @env</p>', source
@@ -11,7 +11,7 @@ p id="#{id_helper}" class="hello world" = hello_world
11
11
 
12
12
  def test_render_with_call_to_set_custom_attributes
13
13
  source = %q{
14
- p data-id="#{id_helper}" data-class="hello world"
14
+ <p data-id="#{id_helper}" data-class>="hello world"
15
15
  = hello_world
16
16
  }
17
17
 
@@ -20,7 +20,7 @@ p data-id="#{id_helper}" data-class="hello world"
20
20
 
21
21
  def test_render_with_call_to_set_attributes_and_call_to_set_content
22
22
  source = %q{
23
- p id="#{id_helper}" class="hello world" = hello_world
23
+ <p id="#{id_helper}" class="hello world">= hello_world
24
24
  }
25
25
 
26
26
  assert_html '<p class="hello world" id="notice">Hello World from @env</p>', source
@@ -28,7 +28,7 @@ p id="#{id_helper}" class="hello world" = hello_world
28
28
 
29
29
  def test_render_with_parameterized_call_to_set_attributes_and_call_to_set_content
30
30
  source = %q{
31
- p id="#{id_helper}" class="hello world" = hello_world("Hello Ruby!")
31
+ <p id="#{id_helper}" class="hello world">= hello_world("Hello Ruby!")
32
32
  }
33
33
 
34
34
  assert_html '<p class="hello world" id="notice">Hello Ruby!</p>', source
@@ -36,7 +36,7 @@ p id="#{id_helper}" class="hello world" = hello_world("Hello Ruby!")
36
36
 
37
37
  def test_render_with_spaced_parameterized_call_to_set_attributes_and_call_to_set_content
38
38
  source = %q{
39
- p id="#{id_helper}" class="hello world" = hello_world "Hello Ruby!"
39
+ <p id="#{id_helper}" class="hello world">= hello_world "Hello Ruby!"
40
40
  }
41
41
 
42
42
  assert_html '<p class="hello world" id="notice">Hello Ruby!</p>', source
@@ -44,7 +44,7 @@ p id="#{id_helper}" class="hello world" = hello_world "Hello Ruby!"
44
44
 
45
45
  def test_render_with_spaced_parameterized_call_to_set_attributes_and_call_to_set_content_2
46
46
  source = %q{
47
- p id="#{id_helper}" class="hello world" = hello_world "Hello Ruby!", :dummy => "value"
47
+ <p id="#{id_helper}" class="hello world">= hello_world "Hello Ruby!", :dummy => "value"
48
48
  }
49
49
 
50
50
  assert_html '<p class="hello world" id="notice">Hello Ruby!dummy value</p>', source
@@ -52,7 +52,7 @@ p id="#{id_helper}" class="hello world" = hello_world "Hello Ruby!", :dummy => "
52
52
 
53
53
  def test_hash_call_in_attribute
54
54
  source = %q{
55
- p id="#{hash[:a]}" Test it
55
+ <p id="#{hash[:a]}">Test it
56
56
  }
57
57
 
58
58
  assert_html '<p id="The letter a">Test it</p>', source
@@ -60,7 +60,7 @@ p id="#{hash[:a]}" Test it
60
60
 
61
61
  def test_instance_variable_in_attribute_without_quotes
62
62
  source = %q{
63
- p id=@var
63
+ <p id=#{@var}>
64
64
  }
65
65
 
66
66
  assert_html '<p id="instance"></p>', source
@@ -68,7 +68,7 @@ p id=@var
68
68
 
69
69
  def test_method_call_in_attribute_without_quotes
70
70
  source = %q{
71
- form action=action_path(:page, :save) method='post'
71
+ <form action=#{action_path(:page, :save)} method='post'
72
72
  }
73
73
 
74
74
  assert_html '<form action="&#47;action-page-save" method="post"></form>', source
@@ -76,7 +76,7 @@ form action=action_path(:page, :save) method='post'
76
76
 
77
77
  def test_ruby_attribute_with_unbalanced_delimiters
78
78
  source = %q{
79
- div crazy=action_path('[') id="crazy_delimiters"
79
+ <div crazy=#{action_path('[')} id="crazy_delimiters">
80
80
  }
81
81
 
82
82
  assert_html '<div crazy="&#47;action-[" id="crazy_delimiters"></div>', source
@@ -84,7 +84,7 @@ div crazy=action_path('[') id="crazy_delimiters"
84
84
 
85
85
  def test_method_call_in_delimited_attribute_without_quotes
86
86
  source = %q{
87
- form(action=action_path(:page, :save) method='post')
87
+ <form action=#{action_path(:page, :save)} method='post'>
88
88
  }
89
89
 
90
90
  assert_html '<form action="&#47;action-page-save" method="post"></form>', source
@@ -92,7 +92,7 @@ form(action=action_path(:page, :save) method='post')
92
92
 
93
93
  def test_method_call_in_delimited_attribute_without_quotes2
94
94
  source = %q{
95
- form(method='post' action=action_path(:page, :save))
95
+ <form method='post' action=#{action_path(:page, :save)}>
96
96
  }
97
97
 
98
98
  assert_html '<form action="&#47;action-page-save" method="post"></form>', source
@@ -100,7 +100,7 @@ form(method='post' action=action_path(:page, :save))
100
100
 
101
101
  def test_bypassing_escape_in_attribute
102
102
  source = %q{
103
- form action==action_path(:page, :save) method='post'
103
+ <form action==#{action_path(:page, :save)} method='post'>
104
104
  }
105
105
 
106
106
  assert_html '<form action="/action-page-save" method="post"></form>', source
@@ -108,7 +108,7 @@ form action==action_path(:page, :save) method='post'
108
108
 
109
109
  def test_hash_call_in_attribute_without_quotes
110
110
  source = %q{
111
- p id=hash[:a] Test it
111
+ <p id=#{hash[:a]}>Test it
112
112
  }
113
113
 
114
114
  assert_html '<p id="The letter a">Test it</p>', source
@@ -116,7 +116,7 @@ p id=hash[:a] Test it
116
116
 
117
117
  def test_hash_call_in_delimited_attribute
118
118
  source = %q{
119
- p(id=hash[:a]) Test it
119
+ <p id=#{hash[:a]}> Test it
120
120
  }
121
121
 
122
122
  assert_html '<p id="The letter a">Test it</p>', source
@@ -124,7 +124,7 @@ p(id=hash[:a]) Test it
124
124
 
125
125
  def test_hash_call_in_attribute_with_ruby_evaluation
126
126
  source = %q{
127
- p id={hash[:a] + hash[:a]} Test it
127
+ <p id=#{hash[:a] + hash[:a]}>Test it
128
128
  }
129
129
 
130
130
  assert_html '<p id="The letter aThe letter a">Test it</p>', source
@@ -132,7 +132,7 @@ p id={hash[:a] + hash[:a]} Test it
132
132
 
133
133
  def test_hash_call_in_delimited_attribute_with_ruby_evaluation
134
134
  source = %q{
135
- p(id=(hash[:a] + hash[:a])) Test it
135
+ <p id=#{hash[:a] + hash[:a]}> Test it
136
136
  }
137
137
 
138
138
  assert_html '<p id="The letter aThe letter a">Test it</p>', source
@@ -140,7 +140,7 @@ p(id=(hash[:a] + hash[:a])) Test it
140
140
 
141
141
  def test_hash_call_in_delimited_attribute_with_ruby_evaluation_2
142
142
  source = %q{
143
- p[id=(hash[:a] + hash[:a])] Test it
143
+ <p id=#{hash[:a] + hash[:a]}> Test it
144
144
  }
145
145
 
146
146
  assert_html '<p id="The letter aThe letter a">Test it</p>', source
@@ -148,7 +148,7 @@ p[id=(hash[:a] + hash[:a])] Test it
148
148
 
149
149
  def test_hash_call_in_delimited_attribute_with_ruby_evaluation_3
150
150
  source = %q{
151
- p(id=[hash[:a] + hash[:a]]) Test it
151
+ <p id=#{hash[:a] + hash[:a]}>Test it
152
152
  }
153
153
 
154
154
  assert_html '<p id="The letter aThe letter a">Test it</p>', source
@@ -156,7 +156,7 @@ p(id=[hash[:a] + hash[:a]]) Test it
156
156
 
157
157
  def test_hash_call_in_delimited_attribute_with_ruby_evaluation_4
158
158
  source = %q{
159
- p(id=[hash[:a] + hash[:a]] class=[hash[:a]]) Test it
159
+ <p id=#{hash[:a] + hash[:a]} class=#{hash[:a]}>Test it
160
160
  }
161
161
 
162
162
  assert_html '<p class="The letter a" id="The letter aThe letter a">Test it</p>', source
@@ -164,7 +164,7 @@ p(id=[hash[:a] + hash[:a]] class=[hash[:a]]) Test it
164
164
 
165
165
  def test_hash_call_in_delimited_attribute_with_ruby_evaluation_5
166
166
  source = %q{
167
- p(id=hash[:a] class=[hash[:a]]) Test it
167
+ <p id=#{hash[:a]} class=#{hash[:a]}>Test it
168
168
  }
169
169
 
170
170
  assert_html '<p class="The letter a" id="The letter a">Test it</p>', source
@@ -172,7 +172,7 @@ p(id=hash[:a] class=[hash[:a]]) Test it
172
172
 
173
173
  def test_computation_in_attribute
174
174
  source = %q{
175
- p id=(1 + 1)*5 Test it
175
+ <p id=#{(1 + 1)*5}>Test it
176
176
  }
177
177
 
178
178
  assert_html '<p id="10">Test it</p>', source
@@ -180,7 +180,7 @@ p id=(1 + 1)*5 Test it
180
180
 
181
181
  def test_number_type_interpolation
182
182
  source = %q{
183
- p = output_number
183
+ <p>= output_number
184
184
  }
185
185
 
186
186
  assert_html '<p>1337</p>', source
@@ -188,7 +188,7 @@ p = output_number
188
188
 
189
189
  def test_ternary_operation_in_attribute
190
190
  source = %q{
191
- p id="#{(false ? 'notshown' : 'shown')}" = output_number
191
+ <p id="#{(false ? 'notshown' : 'shown')}">= output_number
192
192
  }
193
193
 
194
194
  assert_html '<p id="shown">1337</p>', source
@@ -196,35 +196,35 @@ p id="#{(false ? 'notshown' : 'shown')}" = output_number
196
196
 
197
197
  def test_class_attribute_merging
198
198
  source = %{
199
- .alpha class="beta" Test it
199
+ <.alpha class="beta">Test it
200
200
  }
201
201
  assert_html '<div class="alpha beta">Test it</div>', source
202
202
  end
203
203
 
204
204
  def test_class_attribute_merging_with_nil
205
205
  source = %{
206
- .alpha class="beta" class=nil class="gamma" Test it
206
+ <.alpha class="beta" class=nil class="gamma">Test it
207
207
  }
208
208
  assert_html '<div class="alpha beta gamma">Test it</div>', source
209
209
  end
210
210
 
211
211
  def test_id_attribute_merging
212
212
  source = %{
213
- #alpha id="beta" Test it
213
+ <#alpha id="beta">Test it
214
214
  }
215
215
  assert_html '<div id="alpha_beta">Test it</div>', source, :attr_delimiter => {'class' => ' ', 'id' => '_' }
216
216
  end
217
217
 
218
218
  def test_id_attribute_merging2
219
219
  source = %{
220
- #alpha id="beta" Test it
220
+ <#alpha id="beta">Test it
221
221
  }
222
222
  assert_html '<div id="alpha-beta">Test it</div>', source, :attr_delimiter => {'class' => ' ', 'id' => '-' }
223
223
  end
224
224
 
225
225
  def test_boolean_attribute_false
226
226
  source = %{
227
- option selected=false Text
227
+ <option selected=false>Text
228
228
  }
229
229
 
230
230
  assert_html '<option>Text</option>', source
@@ -232,7 +232,7 @@ option selected=false Text
232
232
 
233
233
  def test_boolean_attribute_true
234
234
  source = %{
235
- option selected=true Text
235
+ <option selected=true>Text
236
236
  }
237
237
 
238
238
  assert_html '<option selected="selected">Text</option>', source
@@ -240,7 +240,7 @@ option selected=true Text
240
240
 
241
241
  def test_boolean_attribute_dynamic
242
242
  source = %{
243
- option selected=method_which_returns_true Text
243
+ <option selected=#{method_which_returns_true}>Text
244
244
  }
245
245
 
246
246
  assert_html '<option selected="selected">Text</option>', source
@@ -248,7 +248,7 @@ option selected=method_which_returns_true Text
248
248
 
249
249
  def test_boolean_attribute_nil
250
250
  source = %{
251
- option selected=nil Text
251
+ <option selected=#{nil}>Text
252
252
  }
253
253
 
254
254
  assert_html '<option>Text</option>', source
@@ -256,7 +256,7 @@ option selected=nil Text
256
256
 
257
257
  def test_boolean_attribute_string2
258
258
  source = %{
259
- option selected="selected" Text
259
+ <option selected="selected">Text
260
260
  }
261
261
 
262
262
  assert_html '<option selected="selected">Text</option>', source
@@ -264,8 +264,8 @@ option selected="selected" Text
264
264
 
265
265
  def test_boolean_attribute_shortcut
266
266
  source = %{
267
- option(class="clazz" selected) Text
268
- option(selected class="clazz") Text
267
+ <option class="clazz" selected>Text
268
+ <option selected class="clazz">Text
269
269
  }
270
270
 
271
271
  assert_html '<option class="clazz" selected="selected">Text</option><option class="clazz" selected="selected">Text</option>', source
@@ -273,7 +273,7 @@ option(selected class="clazz") Text
273
273
 
274
274
  def test_array_attribute
275
275
  source = %{
276
- .alpha class="beta" class=[:gamma, nil, :delta, [true, false]]
276
+ <.alpha class="beta" class=#{[:gamma, nil, :delta, [true, false]]}
277
277
  }
278
278
 
279
279
  assert_html '<div class="alpha beta gamma delta true false"></div>', source
@@ -3,7 +3,7 @@ require 'helper'
3
3
  class TestSlimCodeOutput < TestSlim
4
4
  def test_render_with_call
5
5
  source = %q{
6
- p
6
+ <p
7
7
  = hello_world
8
8
  }
9
9
 
@@ -12,16 +12,17 @@ p
12
12
 
13
13
  def test_render_with_trailing_whitespace
14
14
  source = %q{
15
- p
15
+ <p
16
16
  =' hello_world
17
17
  }
18
18
 
19
19
  assert_html '<p>Hello World from @env </p>', source
20
20
  end
21
21
 
22
+ =begin
22
23
  def test_render_with_trailing_whitespace_after_tag
23
24
  source = %q{
24
- p=' hello_world
25
+ <p>=' hello_world
25
26
  }
26
27
 
27
28
  assert_html '<p>Hello World from @env</p> ', source
@@ -29,7 +30,7 @@ p=' hello_world
29
30
 
30
31
  def test_no_escape_render_with_trailing_whitespace
31
32
  source = %q{
32
- p
33
+ <p
33
34
  ==' hello_world
34
35
  }
35
36
 
@@ -43,10 +44,11 @@ p==' hello_world
43
44
 
44
45
  assert_html '<p>Hello World from @env</p> ', source
45
46
  end
47
+ =end
46
48
 
47
49
  def test_render_with_conditional_call
48
50
  source = %q{
49
- p
51
+ <p
50
52
  = hello_world if true
51
53
  }
52
54
 
@@ -55,7 +57,7 @@ p
55
57
 
56
58
  def test_render_with_parameterized_call
57
59
  source = %q{
58
- p
60
+ <p
59
61
  = hello_world("Hello Ruby!")
60
62
  }
61
63
 
@@ -64,7 +66,7 @@ p
64
66
 
65
67
  def test_render_with_spaced_parameterized_call
66
68
  source = %q{
67
- p
69
+ <p
68
70
  = hello_world "Hello Ruby!"
69
71
  }
70
72
 
@@ -73,7 +75,7 @@ p
73
75
 
74
76
  def test_render_with_spaced_parameterized_call_2
75
77
  source = %q{
76
- p
78
+ <p
77
79
  = hello_world "Hello Ruby!", :dummy => "value"
78
80
  }
79
81
 
@@ -82,8 +84,8 @@ p
82
84
 
83
85
  def test_render_with_call_and_inline_text
84
86
  source = %q{
85
- h1 This is my title
86
- p
87
+ <h1>This is my title
88
+ <p
87
89
  = hello_world
88
90
  }
89
91
 
@@ -92,7 +94,7 @@ p
92
94
 
93
95
  def test_render_with_attribute_starts_with_keyword
94
96
  source = %q{
95
- p = hello_world in_keyword
97
+ <p>= hello_world in_keyword
96
98
  }
97
99
 
98
100
  assert_html '<p>starts with keyword</p>', source
@@ -100,7 +102,7 @@ p = hello_world in_keyword
100
102
 
101
103
  def test_hash_call
102
104
  source = %q{
103
- p = hash[:a]
105
+ <p>= hash[:a]
104
106
  }
105
107
 
106
108
  assert_html '<p>The letter a</p>', source
@@ -108,8 +110,8 @@ p = hash[:a]
108
110
 
109
111
  def test_tag_output_without_space
110
112
  source = %q{
111
- p= hello_world
112
- p=hello_world
113
+ <p>= hello_world
114
+ <p>=hello_world
113
115
  }
114
116
 
115
117
  assert_html '<p>Hello World from @env</p><p>Hello World from @env</p>', source
@@ -117,8 +119,8 @@ p=hello_world
117
119
 
118
120
  def test_class_output_without_space
119
121
  source = %q{
120
- .test=hello_world
121
- #test==hello_world
122
+ <.test>=hello_world
123
+ <#test>==hello_world
122
124
  }
123
125
 
124
126
  assert_html '<div class="test">Hello World from @env</div><div id="test">Hello World from @env</div>', source
@@ -126,8 +128,8 @@ p=hello_world
126
128
 
127
129
  def test_attribute_output_without_space
128
130
  source = %q{
129
- p id="test"=hello_world
130
- p(id="test")==hello_world
131
+ <p id="test">=hello_world
132
+ <p id="test">==hello_world
131
133
  }
132
134
 
133
135
  assert_html '<p id="test">Hello World from @env</p><p id="test">Hello World from @env</p>', source
@@ -136,7 +138,7 @@ p(id="test")==hello_world
136
138
  def test_render_with_backslash_end
137
139
  # Keep trailing spaces!
138
140
  source = %q{
139
- p = \
141
+ <p>= \
140
142
  "Hello" + \
141
143
  " Ruby!"
142
144
  - variable = 1 + \
@@ -151,7 +153,7 @@ p = \
151
153
 
152
154
  def test_render_with_no_trailing_character
153
155
  source = %q{
154
- p
156
+ <p>
155
157
  = hello_world}
156
158
 
157
159
  assert_html '<p>Hello World from @env</p>', source
@@ -3,11 +3,11 @@ require 'helper'
3
3
  class TestSlimCodeStructure < TestSlim
4
4
  def test_render_with_conditional
5
5
  source = %q{
6
- div
6
+ <div
7
7
  - if show_first?
8
- p The first paragraph
8
+ <p>The first paragraph
9
9
  - else
10
- p The second paragraph
10
+ <p>The second paragraph
11
11
  }
12
12
 
13
13
  assert_html '<div><p>The second paragraph</p></div>', source
@@ -15,11 +15,11 @@ div
15
15
 
16
16
  def test_render_with_consecutive_conditionals
17
17
  source = %q{
18
- div
18
+ <div>
19
19
  - if show_first? true
20
- p The first paragraph
20
+ <p>The first paragraph
21
21
  - if show_first? true
22
- p The second paragraph
22
+ <p>The second paragraph
23
23
  }
24
24
 
25
25
  assert_html '<div><p>The first paragraph</p><p>The second paragraph</p></div>', source
@@ -27,11 +27,11 @@ div
27
27
 
28
28
  def test_render_with_parameterized_conditional
29
29
  source = %q{
30
- div
30
+ <div
31
31
  - if show_first? false
32
- p The first paragraph
32
+ <p>The first paragraph
33
33
  - else
34
- p The second paragraph
34
+ <p>The second paragraph
35
35
  }
36
36
 
37
37
  assert_html '<div><p>The second paragraph</p></div>', source
@@ -39,9 +39,9 @@ div
39
39
 
40
40
  def test_render_with_conditional_and_following_nonconditonal
41
41
  source = %q{
42
- div
42
+ <div
43
43
  - if true
44
- p The first paragraph
44
+ <p>The first paragraph
45
45
  - var = 42
46
46
  = var
47
47
  }
@@ -51,7 +51,7 @@ div
51
51
 
52
52
  def test_render_with_inline_condition
53
53
  source = %q{
54
- p = hello_world if true
54
+ <p>= hello_world if true
55
55
  }
56
56
 
57
57
  assert_html '<p>Hello World from @env</p>', source
@@ -59,13 +59,13 @@ p = hello_world if true
59
59
 
60
60
  def test_render_with_case
61
61
  source = %q{
62
- p
62
+ <p>
63
63
  - case 42
64
64
  - when 41
65
- | 1
65
+ 1
66
66
  - when 42
67
- | 42
68
- | is the answer
67
+ 42
68
+ > is the answer
69
69
  }
70
70
 
71
71
  assert_html '<p>42 is the answer</p>', source
@@ -73,10 +73,10 @@ p
73
73
 
74
74
  def test_render_with_slim_comments
75
75
  source = %q{
76
- p Hello
77
- / This is a comment
78
- Another comment
79
- p World
76
+ <p>Hello
77
+ # This is a comment
78
+ # Another comment
79
+ <p>World
80
80
  }
81
81
 
82
82
  assert_html '<p>Hello</p><p>World</p>', source
@@ -84,7 +84,7 @@ p World
84
84
 
85
85
  def test_render_with_yield
86
86
  source = %q{
87
- div
87
+ <div
88
88
  == yield :menu
89
89
  }
90
90