hamlet 0.2 → 0.2.1
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.
- data/hamlet.gemspec +1 -1
- data/lib/hamlet/forked_slim_parser.rb +14 -13
- data/lib/hamlet/parser.rb +65 -11
- data/test/slim/test_html_structure.rb +72 -91
- data/test/slim/test_ruby_errors.rb +5 -5
- data/test/slim/test_sections.rb +12 -12
- data/test/slim/test_slim_template.rb +10 -6
- data/test/slim/test_text_interpolation.rb +4 -4
- data/test/slim/test_wrapper.rb +3 -3
- metadata +21 -21
data/hamlet.gemspec
CHANGED
@@ -189,6 +189,12 @@ module ForkedSlim
|
|
189
189
|
# Slim comment
|
190
190
|
parse_comment_block
|
191
191
|
end
|
192
|
+
when /\A([\|'])( ?)(.*)\Z/
|
193
|
+
# Found a text block.
|
194
|
+
trailing_ws = $1 == "'"
|
195
|
+
@stacks.last << [:slim, :interpolate, $3] unless $3.empty?
|
196
|
+
parse_text_block($3.empty? ? nil : @indents.last + $2.size + 1)
|
197
|
+
@stacks.last << [:static, ' '] if trailing_ws
|
192
198
|
when /\A-/
|
193
199
|
# Found a code block.
|
194
200
|
# We expect the line to be broken or the next line to be indented.
|
@@ -205,7 +211,7 @@ module ForkedSlim
|
|
205
211
|
@stacks.last << [:slim, :output, $1.empty?, parse_broken_line, block]
|
206
212
|
@stacks.last << [:static, ' '] unless $2.empty?
|
207
213
|
@stacks << block
|
208
|
-
when /\A
|
214
|
+
when /\A(\w+):\s*\Z/
|
209
215
|
# Embedded template detected. It is treated as block.
|
210
216
|
block = [:multi]
|
211
217
|
@stacks.last << [:newline] << [:slim, :embedded, $1, block]
|
@@ -215,15 +221,9 @@ module ForkedSlim
|
|
215
221
|
when /\Adoctype\s+/i
|
216
222
|
# Found doctype declaration
|
217
223
|
@stacks.last << [:html, :doctype, $'.strip]
|
218
|
-
when /\A
|
224
|
+
when /\A([#\.]|\w[:\w-]*)/
|
219
225
|
# Found a HTML tag.
|
220
|
-
parse_tag(
|
221
|
-
when /\A(> *)?(.*)?\Z/
|
222
|
-
# Found a text block.
|
223
|
-
trailing_ws = !$1
|
224
|
-
@stacks.last << [:slim, :interpolate, $2] unless $2.empty?
|
225
|
-
parse_text_block($2.empty? ? nil : @indents.last + $1.to_s.size)
|
226
|
-
@stacks.last << [:static, ' '] if trailing_ws
|
226
|
+
parse_tag($&)
|
227
227
|
else
|
228
228
|
syntax_error! 'Unknown line indicator'
|
229
229
|
end
|
@@ -282,7 +282,6 @@ module ForkedSlim
|
|
282
282
|
end
|
283
283
|
|
284
284
|
def parse_tag(tag)
|
285
|
-
@line.slice!(0,1) # get rid of leading '<'
|
286
285
|
if tag == '#' || tag == '.'
|
287
286
|
tag = options[:default_tag]
|
288
287
|
else
|
@@ -293,7 +292,7 @@ module ForkedSlim
|
|
293
292
|
@stacks.last << tag
|
294
293
|
|
295
294
|
case @line
|
296
|
-
when /\A\s
|
295
|
+
when /\A\s*=(=?)('?)/
|
297
296
|
# Handle output code
|
298
297
|
block = [:multi]
|
299
298
|
@line = $'
|
@@ -303,12 +302,12 @@ module ForkedSlim
|
|
303
302
|
@stacks << block
|
304
303
|
when /\A\s*\//
|
305
304
|
# Closed tag. Do nothing
|
306
|
-
when /\A\s
|
305
|
+
when /\A\s*\Z/
|
307
306
|
# Empty content
|
308
307
|
content = [:multi]
|
309
308
|
tag << content
|
310
309
|
@stacks << content
|
311
|
-
when /\A( ?)
|
310
|
+
when /\A( ?)(.*)\Z/
|
312
311
|
# Text content
|
313
312
|
content = [:multi, [:slim, :interpolate, $2]]
|
314
313
|
tag << content
|
@@ -381,6 +380,7 @@ module ForkedSlim
|
|
381
380
|
attributes
|
382
381
|
end
|
383
382
|
|
383
|
+
=begin
|
384
384
|
def parse_ruby_attribute(outer_delimiter)
|
385
385
|
value, count, delimiter, close_delimiter = '', 0, nil, nil
|
386
386
|
|
@@ -411,6 +411,7 @@ module ForkedSlim
|
|
411
411
|
|
412
412
|
value
|
413
413
|
end
|
414
|
+
=end
|
414
415
|
|
415
416
|
def parse_quoted_attribute(quote)
|
416
417
|
value, count = '', 0
|
data/lib/hamlet/parser.rb
CHANGED
@@ -54,25 +54,16 @@ module Hamlet
|
|
54
54
|
when /\A<([#\.]|\w[:\w-]*)/
|
55
55
|
# Found a HTML tag.
|
56
56
|
parse_tag($1)
|
57
|
-
when /\A(
|
57
|
+
when /\A(?:>( *))?(.*)?\Z/
|
58
58
|
# Found a text block.
|
59
|
-
|
60
|
-
@stacks.last << [:slim, :interpolate, $2] unless $2.empty?
|
59
|
+
@stacks.last << [:slim, :interpolate, $1 ? $1 << $2 : $2] unless $2.empty?
|
61
60
|
parse_text_block($2.empty? ? nil : @indents.last + $1.to_s.size)
|
62
|
-
@stacks.last << [:static, ' '] if trailing_ws
|
63
61
|
else
|
64
62
|
syntax_error! 'Unknown line indicator'
|
65
63
|
end
|
66
64
|
@stacks.last << [:newline]
|
67
65
|
end
|
68
66
|
|
69
|
-
def parse_comment_block
|
70
|
-
while !@lines.empty? && (@lines.first =~ /\A\s*\Z/ || get_indent(@lines.first) > @indents.last)
|
71
|
-
next_line
|
72
|
-
@stacks.last << [:newline]
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
67
|
def parse_text_block(text_indent = nil)
|
77
68
|
empty_lines = 0
|
78
69
|
until @lines.empty?
|
@@ -143,5 +134,68 @@ module Hamlet
|
|
143
134
|
parse_text_block(@orig_line.size - @line.size + $1.size)
|
144
135
|
end
|
145
136
|
end
|
137
|
+
|
138
|
+
def parse_attributes
|
139
|
+
attributes = [:html, :attrs]
|
140
|
+
|
141
|
+
# Find any literal class/id attributes
|
142
|
+
while @line =~ CLASS_ID_REGEX
|
143
|
+
# The class/id attribute is :static instead of :slim :text,
|
144
|
+
# because we don't want text interpolation in .class or #id shortcut
|
145
|
+
attributes << [:html, :attr, ATTR_SHORTCUT[$1], [:static, $2]]
|
146
|
+
@line = $'
|
147
|
+
end
|
148
|
+
|
149
|
+
# Check to see if there is a delimiter right after the tag name
|
150
|
+
delimiter = nil
|
151
|
+
if @line =~ DELIMITER_REGEX
|
152
|
+
delimiter = DELIMITERS[$&]
|
153
|
+
@line.slice!(0)
|
154
|
+
end
|
155
|
+
|
156
|
+
orig_line = @orig_line
|
157
|
+
lineno = @lineno
|
158
|
+
while true
|
159
|
+
# Parse attributes
|
160
|
+
attr_regex = delimiter ? /#{ATTR_NAME_REGEX}(=|\s|(?=#{Regexp.escape delimiter}))/ : /#{ATTR_NAME_REGEX}=/
|
161
|
+
while @line =~ attr_regex
|
162
|
+
@line = $'
|
163
|
+
name = $1
|
164
|
+
if delimiter && $2 != '='
|
165
|
+
attributes << [:slim, :attr, name, false, 'true']
|
166
|
+
elsif @line =~ /\A["']/
|
167
|
+
# Value is quoted (static)
|
168
|
+
@line = $'
|
169
|
+
attributes << [:html, :attr, name, [:slim, :interpolate, parse_quoted_attribute($&)]]
|
170
|
+
else
|
171
|
+
@line =~ /[^ >]+/
|
172
|
+
@line = $'
|
173
|
+
attributes << [:html, :attr, name, [:slim, :interpolate, $&]]
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
# No ending delimiter, attribute end
|
178
|
+
break unless delimiter
|
179
|
+
|
180
|
+
# Find ending delimiter
|
181
|
+
if @line =~ /\A\s*#{Regexp.escape delimiter}/
|
182
|
+
@line = $'
|
183
|
+
break
|
184
|
+
end
|
185
|
+
|
186
|
+
# Found something where an attribute should be
|
187
|
+
@line.lstrip!
|
188
|
+
syntax_error!('Expected attribute') unless @line.empty?
|
189
|
+
|
190
|
+
# Attributes span multiple lines
|
191
|
+
@stacks.last << [:newline]
|
192
|
+
next_line || syntax_error!("Expected closing delimiter #{delimiter}",
|
193
|
+
:orig_line => orig_line,
|
194
|
+
:lineno => lineno,
|
195
|
+
:column => orig_line.size)
|
196
|
+
end
|
197
|
+
|
198
|
+
attributes
|
199
|
+
end
|
146
200
|
end
|
147
201
|
end
|
@@ -4,11 +4,11 @@ class TestSlimHtmlStructure < TestSlim
|
|
4
4
|
def test_simple_render
|
5
5
|
# Keep the trailing space behind "body "!
|
6
6
|
source = %q{
|
7
|
-
html
|
8
|
-
head
|
9
|
-
title Simple Test Title
|
10
|
-
body
|
11
|
-
p Hello World, meet Slim.
|
7
|
+
<html
|
8
|
+
<head
|
9
|
+
<title Simple Test Title
|
10
|
+
<body
|
11
|
+
<p Hello World, meet Slim.
|
12
12
|
}
|
13
13
|
|
14
14
|
assert_html '<html><head><title>Simple Test Title</title></head><body><p>Hello World, meet Slim.</p></body></html>', source
|
@@ -17,9 +17,9 @@ html
|
|
17
17
|
def test_html_tag_with_text_and_empty_line
|
18
18
|
# Keep the trailing space behind "body "!
|
19
19
|
source = %q{
|
20
|
-
p Hello
|
20
|
+
<p Hello
|
21
21
|
|
22
|
-
p World
|
22
|
+
<p World
|
23
23
|
}
|
24
24
|
|
25
25
|
assert_html "<p>Hello</p><p>World</p>", source
|
@@ -27,7 +27,7 @@ p World
|
|
27
27
|
|
28
28
|
def test_html_namespaces
|
29
29
|
source = %q{
|
30
|
-
html:body
|
30
|
+
<html:body
|
31
31
|
html:p html:id="test" Text
|
32
32
|
}
|
33
33
|
|
@@ -37,7 +37,7 @@ html:body
|
|
37
37
|
def test_doctype
|
38
38
|
source = %q{
|
39
39
|
doctype 1.1
|
40
|
-
html
|
40
|
+
<html
|
41
41
|
}
|
42
42
|
|
43
43
|
assert_html '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html></html>', source, :format => :xhtml
|
@@ -46,7 +46,7 @@ html
|
|
46
46
|
def test_doctype_new_syntax
|
47
47
|
source = %q{
|
48
48
|
doctype 5
|
49
|
-
html
|
49
|
+
<html
|
50
50
|
}
|
51
51
|
|
52
52
|
assert_html '<!DOCTYPE html><html></html>', source, :format => :xhtml
|
@@ -55,7 +55,7 @@ html
|
|
55
55
|
def test_doctype_new_syntax_html5
|
56
56
|
source = %q{
|
57
57
|
doctype html
|
58
|
-
html
|
58
|
+
<html
|
59
59
|
}
|
60
60
|
|
61
61
|
assert_html '<!DOCTYPE html><html></html>', source, :format => :xhtml
|
@@ -63,8 +63,8 @@ html
|
|
63
63
|
|
64
64
|
def test_render_with_shortcut_attributes
|
65
65
|
source = %q{
|
66
|
-
h1#title This is my title
|
67
|
-
|
66
|
+
<h1#title This is my title
|
67
|
+
<#notice.hello.world
|
68
68
|
= hello_world
|
69
69
|
}
|
70
70
|
|
@@ -73,7 +73,7 @@ h1#title This is my title
|
|
73
73
|
|
74
74
|
def test_render_with_overwritten_default_tag
|
75
75
|
source = %q{
|
76
|
-
#notice.hello.world
|
76
|
+
<section #notice.hello.world
|
77
77
|
= hello_world
|
78
78
|
}
|
79
79
|
|
@@ -82,8 +82,7 @@ h1#title This is my title
|
|
82
82
|
|
83
83
|
def test_render_with_text_block
|
84
84
|
source = %q{
|
85
|
-
p
|
86
|
-
|
|
85
|
+
<p
|
87
86
|
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
|
88
87
|
}
|
89
88
|
|
@@ -92,10 +91,9 @@ p
|
|
92
91
|
|
93
92
|
def test_render_with_text_block_with_subsequent_markup
|
94
93
|
source = %q{
|
95
|
-
p
|
96
|
-
|
|
94
|
+
<p
|
97
95
|
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
|
98
|
-
p Some more markup
|
96
|
+
<p Some more markup
|
99
97
|
}
|
100
98
|
|
101
99
|
assert_html '<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p><p>Some more markup</p>', source
|
@@ -105,7 +103,7 @@ p Some more markup
|
|
105
103
|
source = %q{
|
106
104
|
' this is
|
107
105
|
a link to
|
108
|
-
a href="link" page
|
106
|
+
<a href="link" page
|
109
107
|
}
|
110
108
|
|
111
109
|
assert_html "this is\na link to <a href=\"link\">page</a>", source
|
@@ -113,13 +111,12 @@ a href="link" page
|
|
113
111
|
|
114
112
|
def test_nested_text
|
115
113
|
source = %q{
|
116
|
-
p
|
117
|
-
|
|
114
|
+
<p
|
118
115
|
This is line one.
|
119
116
|
This is line two.
|
120
117
|
This is line three.
|
121
118
|
This is line four.
|
122
|
-
p This is a new paragraph.
|
119
|
+
<p This is a new paragraph.
|
123
120
|
}
|
124
121
|
|
125
122
|
assert_html "<p>This is line one.\n This is line two.\n This is line three.\n This is line four.</p><p>This is a new paragraph.</p>", source
|
@@ -127,11 +124,11 @@ p This is a new paragraph.
|
|
127
124
|
|
128
125
|
def test_nested_text_with_nested_html_one_same_line
|
129
126
|
source = %q{
|
130
|
-
p
|
131
|
-
|
132
|
-
|
127
|
+
<p
|
128
|
+
This is line one.
|
129
|
+
> This is line two.
|
133
130
|
span.bold This is a bold line in the paragraph.
|
134
|
-
|
131
|
+
> This is more content.
|
135
132
|
}
|
136
133
|
|
137
134
|
assert_html "<p>This is line one.\n This is line two.<span class=\"bold\">This is a bold line in the paragraph.</span> This is more content.</p>", source
|
@@ -139,7 +136,7 @@ p
|
|
139
136
|
|
140
137
|
def test_nested_text_with_nested_html_one_same_line2
|
141
138
|
source = %q{
|
142
|
-
p
|
139
|
+
<p
|
143
140
|
|This is line one.
|
144
141
|
This is line two.
|
145
142
|
span.bold This is a bold line in the paragraph.
|
@@ -151,7 +148,7 @@ p
|
|
151
148
|
|
152
149
|
def test_nested_text_with_nested_html
|
153
150
|
source = %q{
|
154
|
-
p
|
151
|
+
<p
|
155
152
|
|
|
156
153
|
This is line one.
|
157
154
|
This is line two.
|
@@ -166,7 +163,7 @@ p
|
|
166
163
|
|
167
164
|
def test_simple_paragraph_with_padding
|
168
165
|
source = %q{
|
169
|
-
p There will be 3 spaces in front of this line.
|
166
|
+
<p There will be 3 spaces in front of this line.
|
170
167
|
}
|
171
168
|
|
172
169
|
assert_html '<p> There will be 3 spaces in front of this line.</p>', source
|
@@ -174,7 +171,7 @@ p There will be 3 spaces in front of this line.
|
|
174
171
|
|
175
172
|
def test_paragraph_with_nested_text
|
176
173
|
source = %q{
|
177
|
-
p This is line one.
|
174
|
+
<p This is line one.
|
178
175
|
This is line two.
|
179
176
|
}
|
180
177
|
|
@@ -183,7 +180,7 @@ p This is line one.
|
|
183
180
|
|
184
181
|
def test_paragraph_with_padded_nested_text
|
185
182
|
source = %q{
|
186
|
-
p This is line one.
|
183
|
+
<p This is line one.
|
187
184
|
This is line two.
|
188
185
|
}
|
189
186
|
|
@@ -192,7 +189,7 @@ p This is line one.
|
|
192
189
|
|
193
190
|
def test_paragraph_with_attributes_and_nested_text
|
194
191
|
source = %q{
|
195
|
-
p#test class="paragraph"
|
192
|
+
<p#test class="paragraph">This is line one.
|
196
193
|
This is line two.
|
197
194
|
}
|
198
195
|
|
@@ -201,9 +198,9 @@ p#test class="paragraph" This is line one.
|
|
201
198
|
|
202
199
|
def test_output_code_with_leading_spaces
|
203
200
|
source = %q{
|
204
|
-
p= hello_world
|
205
|
-
p = hello_world
|
206
|
-
p = hello_world
|
201
|
+
<p= hello_world
|
202
|
+
<p = hello_world
|
203
|
+
<p = hello_world
|
207
204
|
}
|
208
205
|
|
209
206
|
assert_html '<p>Hello World from @env</p><p>Hello World from @env</p><p>Hello World from @env</p>', source
|
@@ -211,7 +208,7 @@ p = hello_world
|
|
211
208
|
|
212
209
|
def test_single_quoted_attributes
|
213
210
|
source = %q{
|
214
|
-
p class='underscored_class_name'
|
211
|
+
<p class='underscored_class_name'>= output_number
|
215
212
|
}
|
216
213
|
|
217
214
|
assert_html '<p class="underscored_class_name">1337</p>', source
|
@@ -219,7 +216,7 @@ p class='underscored_class_name' = output_number
|
|
219
216
|
|
220
217
|
def test_nonstandard_attributes
|
221
218
|
source = %q{
|
222
|
-
p id="dashed-id" class="underscored_class_name"
|
219
|
+
<p id="dashed-id" class="underscored_class_name">= output_number
|
223
220
|
}
|
224
221
|
|
225
222
|
assert_html '<p class="underscored_class_name" id="dashed-id">1337</p>', source
|
@@ -227,7 +224,7 @@ p id="dashed-id" class="underscored_class_name" = output_number
|
|
227
224
|
|
228
225
|
def test_nonstandard_shortcut_attributes
|
229
226
|
source = %q{
|
230
|
-
p#dashed-id.underscored_class_name
|
227
|
+
<p#dashed-id.underscored_class_name>= output_number
|
231
228
|
}
|
232
229
|
|
233
230
|
assert_html '<p class="underscored_class_name" id="dashed-id">1337</p>', source
|
@@ -235,7 +232,7 @@ p#dashed-id.underscored_class_name = output_number
|
|
235
232
|
|
236
233
|
def test_dashed_attributes
|
237
234
|
source = %q{
|
238
|
-
p data-info="Illudium Q-36"
|
235
|
+
<p data-info="Illudium Q-36">= output_number
|
239
236
|
}
|
240
237
|
|
241
238
|
assert_html '<p data-info="Illudium Q-36">1337</p>', source
|
@@ -243,7 +240,7 @@ p data-info="Illudium Q-36" = output_number
|
|
243
240
|
|
244
241
|
def test_dashed_attributes_with_shortcuts
|
245
242
|
source = %q{
|
246
|
-
p#marvin.martian data-info="Illudium Q-36"
|
243
|
+
<p#marvin.martian data-info="Illudium Q-36">= output_number
|
247
244
|
}
|
248
245
|
|
249
246
|
assert_html '<p class="martian" data-info="Illudium Q-36" id="marvin">1337</p>', source
|
@@ -251,15 +248,15 @@ p#marvin.martian data-info="Illudium Q-36" = output_number
|
|
251
248
|
|
252
249
|
def test_parens_around_attributes
|
253
250
|
source = %q{
|
254
|
-
p
|
251
|
+
<p id="marvin" class="martian" data-info="Illudium Q-36"> = output_number
|
255
252
|
}
|
256
253
|
|
257
|
-
assert_html '<p class="martian" data-info="Illudium Q-36" id="marvin">
|
254
|
+
assert_html '<p class="martian" data-info="Illudium Q-36" id="marvin"> = output_number</p>', source
|
258
255
|
end
|
259
256
|
|
260
257
|
def test_square_brackets_around_attributes
|
261
258
|
source = %q{
|
262
|
-
p
|
259
|
+
<p id="marvin" class="martian" data-info="Illudium Q-36"> = output_number
|
263
260
|
}
|
264
261
|
|
265
262
|
assert_html '<p class="martian" data-info="Illudium Q-36" id="marvin">1337</p>', source
|
@@ -267,7 +264,7 @@ p[id="marvin" class="martian" data-info="Illudium Q-36"] = output_number
|
|
267
264
|
|
268
265
|
def test_parens_around_attributes_with_equal_sign_snug_to_right_paren
|
269
266
|
source = %q{
|
270
|
-
p
|
267
|
+
<p id="marvin" class="martian" data-info="Illudium Q-36">= output_number
|
271
268
|
}
|
272
269
|
|
273
270
|
assert_html '<p class="martian" data-info="Illudium Q-36" id="marvin">1337</p>', source
|
@@ -275,7 +272,7 @@ p(id="marvin" class="martian" data-info="Illudium Q-36")= output_number
|
|
275
272
|
|
276
273
|
def test_static_empty_attribute
|
277
274
|
source = %q{
|
278
|
-
p
|
275
|
+
<p id="marvin" class="" data-info="Illudium Q-36">= output_number
|
279
276
|
}
|
280
277
|
|
281
278
|
assert_html '<p class="" data-info="Illudium Q-36" id="marvin">1337</p>', source
|
@@ -283,7 +280,7 @@ p(id="marvin" class="" data-info="Illudium Q-36")= output_number
|
|
283
280
|
|
284
281
|
def test_dynamic_empty_attribute
|
285
282
|
source = %q{
|
286
|
-
p
|
283
|
+
<p id="marvin" class=nil other_empty=#{"".to_s} data-info="Illudium Q-36">= output_number
|
287
284
|
}
|
288
285
|
|
289
286
|
assert_html '<p data-info="Illudium Q-36" id="marvin">1337</p>', source
|
@@ -291,24 +288,24 @@ p(id="marvin" class=nil other_empty=("".to_s) data-info="Illudium Q-36")= output
|
|
291
288
|
|
292
289
|
def test_closed_tag
|
293
290
|
source = %q{
|
294
|
-
closed/
|
291
|
+
<closed/
|
295
292
|
}
|
296
293
|
|
297
294
|
assert_html '<closed />', source, :format => :xhtml
|
298
295
|
end
|
299
296
|
|
300
297
|
def test_attributs_with_parens_and_spaces
|
301
|
-
source = %q{label
|
298
|
+
source = %q{<label for=filter>= hello_world}
|
302
299
|
assert_html '<label for="filter">Hello World from @env</label>', source
|
303
300
|
end
|
304
301
|
|
305
302
|
def test_attributs_with_parens_and_spaces2
|
306
|
-
source = %q{label
|
303
|
+
source = %q{<label for=filter>= hello_world}
|
307
304
|
assert_html '<label for="filter">Hello World from @env</label>', source
|
308
305
|
end
|
309
306
|
|
310
307
|
def test_attributs_with_multiple_spaces
|
311
|
-
source = %q{label
|
308
|
+
source = %q{<label for=filter class="test">= hello_world}
|
312
309
|
assert_html '<label class="test" for="filter">Hello World from @env</label>', source
|
313
310
|
end
|
314
311
|
|
@@ -322,7 +319,7 @@ closed id="test" /
|
|
322
319
|
|
323
320
|
def test_closed_tag_with_attributes_and_parens
|
324
321
|
source = %q{
|
325
|
-
closed
|
322
|
+
<closed id="test">/
|
326
323
|
}
|
327
324
|
|
328
325
|
assert_html '<closed id="test" />', source, :format => :xhtml
|
@@ -330,11 +327,11 @@ closed(id="test")/
|
|
330
327
|
|
331
328
|
def test_render_with_html_comments
|
332
329
|
source = %q{
|
333
|
-
p Hello
|
330
|
+
<p Hello
|
334
331
|
/! This is a comment
|
335
332
|
|
336
333
|
Another comment
|
337
|
-
p World
|
334
|
+
<p World
|
338
335
|
}
|
339
336
|
|
340
337
|
assert_html "<p>Hello</p><!--This is a comment\n\nAnother comment--><p>World</p>", source
|
@@ -358,81 +355,65 @@ p World
|
|
358
355
|
assert_html "<!--[if IE]>hello<![endif]-->", source
|
359
356
|
end
|
360
357
|
|
358
|
+
=begin
|
361
359
|
def test_multiline_attributes_with_method
|
362
|
-
|
363
|
-
p
|
360
|
+
str = %q{
|
361
|
+
<p id="marvin"
|
364
362
|
class="martian"
|
365
363
|
data-info="Illudium Q-36"> = output_number
|
366
364
|
}
|
367
|
-
|
368
|
-
str = source.sub('<',k).sub('>',v)
|
369
|
-
assert_html '<p class="martian" data-info="Illudium Q-36" id="marvin">1337</p>', str
|
370
|
-
end
|
365
|
+
assert_html '<p class="martian" data-info="Illudium Q-36" id="marvin">1337</p>', str
|
371
366
|
end
|
372
367
|
|
373
368
|
def test_multiline_attributes_with_text_on_same_line
|
374
|
-
|
375
|
-
p
|
369
|
+
str = %q{
|
370
|
+
<p id="marvin"
|
376
371
|
class="martian"
|
377
372
|
data-info="Illudium Q-36"> THE space modulator
|
378
373
|
}
|
379
|
-
|
380
|
-
str = source.sub('<',k).sub('>',v)
|
381
|
-
assert_html '<p class="martian" data-info="Illudium Q-36" id="marvin">THE space modulator</p>', str
|
382
|
-
end
|
374
|
+
assert_html '<p class="martian" data-info="Illudium Q-36" id="marvin">THE space modulator</p>', str
|
383
375
|
end
|
384
376
|
|
385
377
|
def test_multiline_attributes_with_nested_text
|
386
|
-
|
387
|
-
p
|
378
|
+
str = %q{
|
379
|
+
<p id="marvin"
|
388
380
|
class="martian"
|
389
381
|
data-info="Illudium Q-36">
|
390
|
-
|
382
|
+
THE space modulator
|
391
383
|
}
|
392
|
-
|
393
|
-
str = source.sub('<',k).sub('>',v)
|
394
|
-
assert_html '<p class="martian" data-info="Illudium Q-36" id="marvin">THE space modulator</p>', str
|
395
|
-
end
|
384
|
+
assert_html '<p class="martian" data-info="Illudium Q-36" id="marvin">THE space modulator</p>', str
|
396
385
|
end
|
397
386
|
|
398
387
|
def test_multiline_attributes_with_dynamic_attr
|
399
388
|
source = %q{
|
400
|
-
p
|
389
|
+
<p id=id_helper
|
401
390
|
class="martian"
|
402
391
|
data-info="Illudium Q-36">
|
403
|
-
|
392
|
+
THE space modulator
|
404
393
|
}
|
405
|
-
|
406
|
-
str = source.sub('<',k).sub('>',v)
|
407
|
-
assert_html '<p class="martian" data-info="Illudium Q-36" id="notice">THE space modulator</p>', str
|
408
|
-
end
|
394
|
+
assert_html '<p class="martian" data-info="Illudium Q-36" id="notice">THE space modulator</p>', str
|
409
395
|
end
|
410
396
|
|
411
397
|
def test_multiline_attributes_with_nested_tag
|
412
398
|
source = %q{
|
413
|
-
p
|
399
|
+
<p id=id_helper
|
414
400
|
class="martian"
|
415
401
|
data-info="Illudium Q-36">
|
416
402
|
span.emphasis THE
|
417
|
-
|
403
|
+
> space modulator
|
418
404
|
}
|
419
|
-
|
420
|
-
str = source.sub('<',k).sub('>',v)
|
421
|
-
assert_html '<p class="martian" data-info="Illudium Q-36" id="notice"><span class="emphasis">THE</span> space modulator</p>', str
|
422
|
-
end
|
405
|
+
assert_html '<p class="martian" data-info="Illudium Q-36" id="notice"><span class="emphasis">THE</span> space modulator</p>', source
|
423
406
|
end
|
424
407
|
|
425
408
|
def test_multiline_attributes_with_nested_text_and_extra_indentation
|
426
409
|
source = %q{
|
427
|
-
li
|
410
|
+
<li id="myid"
|
428
411
|
class="myclass"
|
429
412
|
data-info="myinfo">
|
430
|
-
a href="link" My Link
|
413
|
+
<a href="link" My Link
|
431
414
|
}
|
432
|
-
|
433
|
-
str = source.sub('<',k).sub('>',v)
|
434
|
-
assert_html '<li class="myclass" data-info="myinfo" id="myid"><a href="link">My Link</a></li>', str
|
435
|
-
end
|
415
|
+
assert_html '<li class="myclass" data-info="myinfo" id="myid"><a href="link">My Link</a></li>', str
|
436
416
|
end
|
417
|
+
=end
|
437
418
|
|
438
419
|
end
|
@@ -3,8 +3,8 @@ require 'helper'
|
|
3
3
|
class TestSlimRubyErrors < TestSlim
|
4
4
|
def test_multline_attribute
|
5
5
|
source = %q{
|
6
|
-
<p
|
7
|
-
data2-=1
|
6
|
+
<p data-1=1
|
7
|
+
data2-=1>
|
8
8
|
<p
|
9
9
|
= unknown_ruby_method
|
10
10
|
}
|
@@ -150,7 +150,7 @@ data2-=1)
|
|
150
150
|
|
151
151
|
def test_invalid_nested_output
|
152
152
|
source = %q{
|
153
|
-
p
|
153
|
+
<p
|
154
154
|
= "Hello Ruby!"
|
155
155
|
= "Hello from within a block! "
|
156
156
|
}
|
@@ -160,7 +160,7 @@ p
|
|
160
160
|
def test_invalid_embedded_engine
|
161
161
|
source = %q{
|
162
162
|
<p
|
163
|
-
embed_unknown:
|
163
|
+
<embed_unknown:
|
164
164
|
1+1
|
165
165
|
}
|
166
166
|
|
@@ -180,7 +180,7 @@ p
|
|
180
180
|
|
181
181
|
def test_id_attribute_merging2
|
182
182
|
source = %{
|
183
|
-
|
183
|
+
<#alpha id="beta" Test it
|
184
184
|
}
|
185
185
|
assert_runtime_error 'Multiple id attributes specified', source
|
186
186
|
end
|
data/test/slim/test_sections.rb
CHANGED
@@ -11,9 +11,9 @@ class TestSlimLogicLess < TestSlim
|
|
11
11
|
|
12
12
|
def test_sections
|
13
13
|
source = %q{
|
14
|
-
p
|
14
|
+
<p
|
15
15
|
- person
|
16
|
-
|
16
|
+
<.name = name
|
17
17
|
}
|
18
18
|
|
19
19
|
hash = {
|
@@ -28,9 +28,9 @@ p
|
|
28
28
|
|
29
29
|
def test_sections_string_access
|
30
30
|
source = %q{
|
31
|
-
p
|
31
|
+
<p
|
32
32
|
- person
|
33
|
-
|
33
|
+
<.name = name
|
34
34
|
}
|
35
35
|
|
36
36
|
hash = {
|
@@ -45,12 +45,12 @@ p
|
|
45
45
|
|
46
46
|
def test_flag_section
|
47
47
|
source = %q{
|
48
|
-
p
|
48
|
+
<p
|
49
49
|
- show_person
|
50
50
|
- person
|
51
|
-
|
51
|
+
<.name = name
|
52
52
|
- show_person
|
53
|
-
|
53
|
+
shown
|
54
54
|
}
|
55
55
|
|
56
56
|
hash = {
|
@@ -66,13 +66,13 @@ p
|
|
66
66
|
|
67
67
|
def test_inverted_section
|
68
68
|
source = %q{
|
69
|
-
p
|
69
|
+
<p
|
70
70
|
- person
|
71
|
-
|
71
|
+
<.name = name
|
72
72
|
-! person
|
73
|
-
|
73
|
+
No person
|
74
74
|
- !person
|
75
|
-
|
75
|
+
> No person 2
|
76
76
|
}
|
77
77
|
|
78
78
|
hash = {}
|
@@ -82,7 +82,7 @@ p
|
|
82
82
|
|
83
83
|
def test_output_with_content
|
84
84
|
source = %{
|
85
|
-
p = method_with_block do
|
85
|
+
<p = method_with_block do
|
86
86
|
block
|
87
87
|
}
|
88
88
|
assert_runtime_error 'Output statements with content are forbidden in sections mode', source, :sections => true
|
@@ -83,8 +83,7 @@ class TestSlimTemplate < TestSlim
|
|
83
83
|
end
|
84
84
|
|
85
85
|
def test_backtrace_file_and_line_reporting_without_locals
|
86
|
-
data =
|
87
|
-
fail unless data[0] == ?h
|
86
|
+
data = load_file_data
|
88
87
|
template = Hamlet::Template.new('test.slim', 10) { data }
|
89
88
|
begin
|
90
89
|
template.render(Scope.new)
|
@@ -95,9 +94,14 @@ class TestSlimTemplate < TestSlim
|
|
95
94
|
end
|
96
95
|
end
|
97
96
|
|
98
|
-
def
|
97
|
+
def load_file_data
|
99
98
|
data = File.read(__FILE__).split("\n__END__\n").last
|
100
|
-
fail unless data[0] ==
|
99
|
+
fail unless data[0] == ?<
|
100
|
+
data
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_backtrace_file_and_line_reporting_with_locals
|
104
|
+
data = load_file_data
|
101
105
|
template = Hamlet::Template.new('test.slim') { data }
|
102
106
|
begin
|
103
107
|
res = template.render(Scope.new, :name => 'Joe', :foo => 'bar')
|
@@ -109,8 +113,8 @@ class TestSlimTemplate < TestSlim
|
|
109
113
|
end
|
110
114
|
|
111
115
|
__END__
|
112
|
-
html
|
113
|
-
body
|
116
|
+
<html>
|
117
|
+
<body>
|
114
118
|
<h1>= "Hey #{name}"
|
115
119
|
|
116
120
|
= raise MockError
|
@@ -20,7 +20,7 @@ class TestSlimTextInterpolation < TestSlim
|
|
20
20
|
def test_interpolation_in_text
|
21
21
|
source = %q{
|
22
22
|
<p
|
23
|
-
|
23
|
+
#{hello_world} with "quotes"
|
24
24
|
<p
|
25
25
|
|
26
26
|
>A message from the compiler: #{hello_world}
|
@@ -55,7 +55,7 @@ class TestSlimTextInterpolation < TestSlim
|
|
55
55
|
|
56
56
|
def test_interpolation_with_escaping
|
57
57
|
source = %q{
|
58
|
-
|
58
|
+
#{evil_method}
|
59
59
|
}
|
60
60
|
|
61
61
|
assert_html '<script>do_something_evil();</script>', source
|
@@ -63,7 +63,7 @@ class TestSlimTextInterpolation < TestSlim
|
|
63
63
|
|
64
64
|
def test_interpolation_without_escaping
|
65
65
|
source = %q{
|
66
|
-
|
66
|
+
#{{evil_method}}
|
67
67
|
}
|
68
68
|
|
69
69
|
assert_html '<script>do_something_evil();</script>', source
|
@@ -71,7 +71,7 @@ class TestSlimTextInterpolation < TestSlim
|
|
71
71
|
|
72
72
|
def test_interpolation_with_escaping_and_delimiter
|
73
73
|
source = %q{
|
74
|
-
|
74
|
+
#{(evil_method)}
|
75
75
|
}
|
76
76
|
assert_html '<script>do_something_evil();</script>', source
|
77
77
|
end
|
data/test/slim/test_wrapper.rb
CHANGED
@@ -14,7 +14,7 @@ class TestSlimWrapper < TestSlim
|
|
14
14
|
source = %q{
|
15
15
|
<p
|
16
16
|
- person
|
17
|
-
<.name
|
17
|
+
<.name>= name
|
18
18
|
}
|
19
19
|
assert_html '<p><div class="name">Joe</div><div class="name">Jack</div></p>', source, :sections => true
|
20
20
|
end
|
@@ -31,9 +31,9 @@ class TestSlimWrapper < TestSlim
|
|
31
31
|
|
32
32
|
def test_method
|
33
33
|
source = %q{
|
34
|
-
<a href=output_number
|
34
|
+
<a href=output_number>Link
|
35
35
|
}
|
36
|
-
assert_html '<a href="
|
36
|
+
assert_html '<a href="output_number">Link</a>', source, :sections => true
|
37
37
|
end
|
38
38
|
|
39
39
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hamlet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 0.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2011-10-28 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: slim
|
16
|
-
requirement: &
|
16
|
+
requirement: &3779800 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 1.0.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *3779800
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rake
|
27
|
-
requirement: &
|
27
|
+
requirement: &3778760 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 0.8.7
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *3778760
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: sass
|
38
|
-
requirement: &
|
38
|
+
requirement: &3777880 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 3.1.0
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *3777880
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: minitest
|
49
|
-
requirement: &
|
49
|
+
requirement: &3777100 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *3777100
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: kramdown
|
60
|
-
requirement: &
|
60
|
+
requirement: &3776500 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *3776500
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: yard
|
71
|
-
requirement: &
|
71
|
+
requirement: &3775820 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *3775820
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: creole
|
82
|
-
requirement: &
|
82
|
+
requirement: &3775060 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: '0'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *3775060
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: builder
|
93
|
-
requirement: &
|
93
|
+
requirement: &3774140 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ! '>='
|
@@ -98,10 +98,10 @@ dependencies:
|
|
98
98
|
version: '0'
|
99
99
|
type: :development
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *3774140
|
102
102
|
- !ruby/object:Gem::Dependency
|
103
103
|
name: pry
|
104
|
-
requirement: &
|
104
|
+
requirement: &3773380 !ruby/object:Gem::Requirement
|
105
105
|
none: false
|
106
106
|
requirements:
|
107
107
|
- - ! '>='
|
@@ -109,10 +109,10 @@ dependencies:
|
|
109
109
|
version: '0'
|
110
110
|
type: :development
|
111
111
|
prerelease: false
|
112
|
-
version_requirements: *
|
112
|
+
version_requirements: *3773380
|
113
113
|
- !ruby/object:Gem::Dependency
|
114
114
|
name: rcov
|
115
|
-
requirement: &
|
115
|
+
requirement: &3720320 !ruby/object:Gem::Requirement
|
116
116
|
none: false
|
117
117
|
requirements:
|
118
118
|
- - ! '>='
|
@@ -120,7 +120,7 @@ dependencies:
|
|
120
120
|
version: '0'
|
121
121
|
type: :development
|
122
122
|
prerelease: false
|
123
|
-
version_requirements: *
|
123
|
+
version_requirements: *3720320
|
124
124
|
description: Hamlet is a template language whose goal is reduce HTML syntax to the
|
125
125
|
essential parts.
|
126
126
|
email:
|