slim 0.6.0.beta.2 → 0.6.0.beta.3
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/Gemfile +4 -1
- data/Gemfile.lock +1 -1
- data/lib/slim.rb +2 -2
- data/lib/slim/compiler.rb +15 -17
- data/slim.gemspec +2 -2
- data/test/helper.rb +4 -0
- data/test/slim/test_compiler.rb +30 -5
- data/test/slim/test_engine.rb +10 -0
- metadata +4 -4
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
data/lib/slim.rb
CHANGED
data/lib/slim/compiler.rb
CHANGED
@@ -13,9 +13,8 @@ module Slim
|
|
13
13
|
REGEX_LINE_PARSER = /^(\s*)(!?`?\|?-?=?\/?\w*)((?:\s*(?:\w|-)*="[^=]+")+|(\S*[#.]\S+))?(.*)/
|
14
14
|
|
15
15
|
REGEX_LINE_CONTAINS_OUTPUT_CODE = /^\s*=(.*)/
|
16
|
-
|
17
|
-
|
18
|
-
REGEX_METHOD_HAS_NO_PARENTHESES = /^\w+\s/
|
16
|
+
REGEX_LINE_CONTAINS_METHOD_DETECTED = /^((?:(?!#{CONTROL_WORDS * '\b|'}\b).)*)/
|
17
|
+
REGEX_METHOD_HAS_NO_PARENTHESES = /^\w+\s+\S+/
|
19
18
|
REGEX_CODE_BLOCK_DETECTED = / do ?.*$/
|
20
19
|
REGEX_CODE_CONTROL_WORD_DETECTED = /(?:\s|(\())(#{CONTROL_WORDS * '|'})\b\s?(.*)$/
|
21
20
|
REGEX_CODE_ELSE_CONTROL_WORD_DETECTED = /^#{ELSE_CONTROL_WORDS * '\b|'}\b/
|
@@ -55,9 +54,6 @@ module Slim
|
|
55
54
|
# Remove the first space, but allow people to pad if they want.
|
56
55
|
string.slice!(0) if string =~ /^\s/
|
57
56
|
|
58
|
-
# prepends "div" to the shortcut form of attrs if no marker is given
|
59
|
-
marker = 'div' if shortcut_attrs && marker.empty?
|
60
|
-
|
61
57
|
line_type = case marker
|
62
58
|
when '`', '|' then :text
|
63
59
|
when '-' then :control_code
|
@@ -78,9 +74,8 @@ module Slim
|
|
78
74
|
continue_closing = true
|
79
75
|
ender, ender_indent = enders.pop
|
80
76
|
|
81
|
-
unless ender_indent < indent ||
|
82
|
-
|
83
|
-
@_buffer << ender
|
77
|
+
unless ender_indent < indent || ender_indent == indent && string =~ REGEX_CODE_ELSE_CONTROL_WORD_DETECTED
|
78
|
+
@_buffer << ender
|
84
79
|
else
|
85
80
|
enders << [ender, ender_indent]
|
86
81
|
continue_closing = false
|
@@ -95,6 +90,9 @@ module Slim
|
|
95
90
|
if AUTOCLOSED.include?(marker)
|
96
91
|
@_buffer << "_buf << \"<#{marker}#{attrs}/>\";"
|
97
92
|
else
|
93
|
+
# prepends "div" to the shortcut form of attrs if no marker is given
|
94
|
+
marker = 'div' if shortcut_attrs && marker.empty?
|
95
|
+
|
98
96
|
enders << ["_buf << \"</#{marker}>\";", indent]
|
99
97
|
@_buffer << "_buf << \"<#{marker}#{attrs}>\";"
|
100
98
|
end
|
@@ -136,12 +134,13 @@ module Slim
|
|
136
134
|
private
|
137
135
|
|
138
136
|
def parse_string(string)
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
137
|
+
if string =~ REGEX_LINE_CONTAINS_OUTPUT_CODE
|
138
|
+
$1.strip
|
139
|
+
else
|
140
|
+
parenthesesify_method!(string) if string =~ REGEX_METHOD_HAS_NO_PARENTHESES
|
141
|
+
wraps_with_slim_escape!(string) unless string =~ REGEX_CODE_BLOCK_DETECTED
|
142
|
+
string.strip
|
143
|
+
end
|
145
144
|
end
|
146
145
|
|
147
146
|
# adds a pair of parentheses to the method
|
@@ -157,8 +156,7 @@ module Slim
|
|
157
156
|
# converts 'p#hello.world.mate' to 'p id="hello" class="world mate"'
|
158
157
|
def normalize_attributes!(string)
|
159
158
|
string.sub!(REGEX_FIND_HTML_ATTR_ID, ' id="\1"')
|
160
|
-
string.sub!(REGEX_FIND_HTML_ATTR_CLASSES, ' class="\1"')
|
161
|
-
string.gsub!('.', ' ')
|
159
|
+
string.sub!(REGEX_FIND_HTML_ATTR_CLASSES, ' class="\1"') && string.gsub!('.', ' ')
|
162
160
|
end
|
163
161
|
end
|
164
162
|
end
|
data/slim.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{slim}
|
8
|
-
s.version = "0.6.0.beta.
|
8
|
+
s.version = "0.6.0.beta.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Andrew Stone", "Fred Wu"]
|
12
|
-
s.date = %q{2010-10-
|
12
|
+
s.date = %q{2010-10-16}
|
13
13
|
s.description = %q{Slim is a template language whose goal is reduce the syntax to the essential parts without becoming cryptic.}
|
14
14
|
s.email = ["andy@stonean.com", "ifredwu@gmail.com"]
|
15
15
|
s.extra_rdoc_files = [
|
data/test/helper.rb
CHANGED
data/test/slim/test_compiler.rb
CHANGED
@@ -188,7 +188,7 @@ p
|
|
188
188
|
= hello_world
|
189
189
|
HTML
|
190
190
|
|
191
|
-
expected = %q|_buf = [];_buf << "<p>";_buf << Slim.escape_html(hello_world
|
191
|
+
expected = %q|_buf = [];_buf << "<p>";_buf << Slim.escape_html(hello_world);_buf << "</p>";_buf.join;|
|
192
192
|
|
193
193
|
assert_equal expected, TestEngine.new(string).compiled
|
194
194
|
end
|
@@ -221,7 +221,7 @@ body
|
|
221
221
|
p id="first" = hello_world
|
222
222
|
TEMPLATE
|
223
223
|
|
224
|
-
expected = %q|_buf = [];_buf << "<body>";_buf << "<p id=\"first\">";_buf << Slim.escape_html(hello_world
|
224
|
+
expected = %q|_buf = [];_buf << "<body>";_buf << "<p id=\"first\">";_buf << Slim.escape_html(hello_world);_buf << "</p>";_buf << "</body>";_buf.join;|
|
225
225
|
|
226
226
|
assert_equal expected, TestEngine.new(string).compiled
|
227
227
|
end
|
@@ -312,17 +312,27 @@ TEMPLATE
|
|
312
312
|
p = session[:id]
|
313
313
|
TEMPLATE
|
314
314
|
|
315
|
-
expected = %q|_buf = [];_buf << "<p>";_buf << session[:id];_buf << "</p>";_buf.join;|
|
315
|
+
expected = %q|_buf = [];_buf << "<p>";_buf << Slim.escape_html(session[:id]);_buf << "</p>";_buf.join;|
|
316
316
|
|
317
317
|
assert_equal expected, TestEngine.new(string).compiled
|
318
318
|
end
|
319
319
|
|
320
320
|
def test_escape_escaping
|
321
321
|
string = <<TEMPLATE
|
322
|
+
p == session[:id]
|
323
|
+
TEMPLATE
|
324
|
+
|
325
|
+
expected = %q|_buf = [];_buf << "<p>";_buf << session[:id];_buf << "</p>";_buf.join;|
|
326
|
+
|
327
|
+
assert_equal expected, TestEngine.new(string).compiled
|
328
|
+
end
|
329
|
+
|
330
|
+
def test_escape_escaping2
|
331
|
+
string = <<TEMPLATE
|
322
332
|
p == safe_method_call
|
323
333
|
TEMPLATE
|
324
334
|
|
325
|
-
expected = %q|_buf = [];_buf << "<p>";_buf << safe_method_call
|
335
|
+
expected = %q|_buf = [];_buf << "<p>";_buf << safe_method_call;_buf << "</p>";_buf.join;|
|
326
336
|
|
327
337
|
assert_equal expected, TestEngine.new(string).compiled
|
328
338
|
end
|
@@ -348,7 +358,22 @@ TEMPLATE
|
|
348
358
|
== hello
|
349
359
|
TEMPLATE
|
350
360
|
|
351
|
-
expected = %q|_buf = [];_buf << "<body>";_buf << "<p>";_buf << "hey";_buf << hello
|
361
|
+
expected = %q|_buf = [];_buf << "<body>";_buf << "<p>";_buf << "hey";_buf << hello;_buf << "</p>";_buf << "</body>";_buf.join;|
|
362
|
+
|
363
|
+
assert_equal expected, TestEngine.new(string).compiled
|
364
|
+
end
|
365
|
+
|
366
|
+
def test_code_block
|
367
|
+
string = <<TEMPLATE
|
368
|
+
- unless items.empty?
|
369
|
+
ul
|
370
|
+
- items.each do |item|
|
371
|
+
li = item
|
372
|
+
- else
|
373
|
+
p No items
|
374
|
+
TEMPLATE
|
375
|
+
|
376
|
+
expected = %q|_buf = [];unless items.empty?;_buf << "<ul>";items.each do \|item\|;_buf << "<li>";_buf << Slim.escape_html(item);_buf << "</li>";end;_buf << "</ul>";else;_buf << "<p>";_buf << "No items";_buf << "</p>";end;_buf.join;|
|
352
377
|
|
353
378
|
assert_equal expected, TestEngine.new(string).compiled
|
354
379
|
end
|
data/test/slim/test_engine.rb
CHANGED
@@ -395,4 +395,14 @@ HTML
|
|
395
395
|
|
396
396
|
assert_equal expected, Slim::Engine.new(string).render(@env)
|
397
397
|
end
|
398
|
+
|
399
|
+
def test_number_type_interpolation
|
400
|
+
string = <<HTML
|
401
|
+
p = output_number
|
402
|
+
HTML
|
403
|
+
|
404
|
+
expected = "<p>1337</p>"
|
405
|
+
|
406
|
+
assert_equal expected, Slim::Engine.new(string).render(@env)
|
407
|
+
end
|
398
408
|
end
|
metadata
CHANGED
@@ -7,8 +7,8 @@ version: !ruby/object:Gem::Version
|
|
7
7
|
- 6
|
8
8
|
- 0
|
9
9
|
- beta
|
10
|
-
-
|
11
|
-
version: 0.6.0.beta.
|
10
|
+
- 3
|
11
|
+
version: 0.6.0.beta.3
|
12
12
|
platform: ruby
|
13
13
|
authors:
|
14
14
|
- Andrew Stone
|
@@ -17,7 +17,7 @@ autorequire:
|
|
17
17
|
bindir: bin
|
18
18
|
cert_chain: []
|
19
19
|
|
20
|
-
date: 2010-10-
|
20
|
+
date: 2010-10-16 00:00:00 +11:00
|
21
21
|
default_executable:
|
22
22
|
dependencies:
|
23
23
|
- !ruby/object:Gem::Dependency
|
@@ -124,7 +124,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
124
124
|
requirements:
|
125
125
|
- - ">="
|
126
126
|
- !ruby/object:Gem::Version
|
127
|
-
hash:
|
127
|
+
hash: 2018264533147870573
|
128
128
|
segments:
|
129
129
|
- 0
|
130
130
|
version: "0"
|