slim 0.8.4 → 0.9.0
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/lib/slim/interpolation.rb +8 -7
- data/lib/slim/parser.rb +11 -11
- data/lib/slim/rails.rb +4 -2
- data/lib/slim/version.rb +1 -1
- metadata +4 -4
data/lib/slim/interpolation.rb
CHANGED
@@ -12,15 +12,16 @@ module Slim
|
|
12
12
|
block = [:multi]
|
13
13
|
until string.empty?
|
14
14
|
case string
|
15
|
-
when
|
15
|
+
when /^\\#\{/
|
16
16
|
# Escaped interpolation
|
17
17
|
block << [:static, '#{']
|
18
18
|
string = $'
|
19
|
-
when
|
19
|
+
when /^#\{/
|
20
20
|
# Interpolation
|
21
21
|
string, code = parse_expression($')
|
22
|
-
|
23
|
-
|
22
|
+
escape = code !~ Parser::DELIMITER_REGEX || Parser::DELIMITERS[$&] != code[-1, 1]
|
23
|
+
block << [:slim, :output, escape, escape ? code : code[1..-2], [:multi]]
|
24
|
+
when /^([^#]+|#)/
|
24
25
|
# Static text
|
25
26
|
block << [:static, $&]
|
26
27
|
string = $'
|
@@ -40,12 +41,12 @@ module Slim
|
|
40
41
|
break
|
41
42
|
elsif string =~ Parser::DELIMITER_REGEX
|
42
43
|
# Delimiter found, push it on the stack
|
43
|
-
stack << Parser::DELIMITERS[
|
44
|
+
stack << Parser::DELIMITERS[$&]
|
44
45
|
code << string.slice!(0)
|
45
46
|
elsif string =~ Parser::CLOSE_DELIMITER_REGEX
|
46
47
|
# Closing delimiter found, pop it from the stack if everything is ok
|
47
|
-
raise "Text interpolation: Unexpected closing #{
|
48
|
-
raise "Text interpolation: Expected closing #{stack.last}" if stack.last !=
|
48
|
+
raise "Text interpolation: Unexpected closing #{$&}" if stack.empty?
|
49
|
+
raise "Text interpolation: Expected closing #{stack.last}" if stack.last != $&
|
49
50
|
code << string.slice!(0)
|
50
51
|
stack.pop
|
51
52
|
else
|
data/lib/slim/parser.rb
CHANGED
@@ -236,12 +236,12 @@ module Slim
|
|
236
236
|
'[' => ']',
|
237
237
|
'{' => '}',
|
238
238
|
}.freeze
|
239
|
-
DELIMITER_REGEX = /^
|
240
|
-
CLOSE_DELIMITER_REGEX = /^
|
239
|
+
DELIMITER_REGEX = /^[\(\[\{]/
|
240
|
+
CLOSE_DELIMITER_REGEX = /^[\)\]\}]/
|
241
241
|
|
242
242
|
private
|
243
243
|
|
244
|
-
ATTR_REGEX =
|
244
|
+
ATTR_REGEX = /^\s+(\w[:\w-]*)=/
|
245
245
|
QUOTED_VALUE_REGEX = /^("[^"]+"|'[^']+')/
|
246
246
|
ATTR_SHORTHAND = {
|
247
247
|
'#' => 'id',
|
@@ -258,7 +258,7 @@ module Slim
|
|
258
258
|
orig_line = line
|
259
259
|
|
260
260
|
case line
|
261
|
-
when /^
|
261
|
+
when /^[#\.]/
|
262
262
|
tag = 'div'
|
263
263
|
when /^\w[:\w-]*/
|
264
264
|
tag = $&
|
@@ -281,7 +281,7 @@ module Slim
|
|
281
281
|
# Check to see if there is a delimiter right after the tag name
|
282
282
|
delimiter = ''
|
283
283
|
if line =~ DELIMITER_REGEX
|
284
|
-
delimiter = DELIMITERS[
|
284
|
+
delimiter = DELIMITERS[$&]
|
285
285
|
# Replace the delimiter with a space so we can continue parsing as normal.
|
286
286
|
line[0] = ?\s
|
287
287
|
end
|
@@ -303,8 +303,8 @@ module Slim
|
|
303
303
|
|
304
304
|
# Find ending delimiter
|
305
305
|
if !delimiter.empty?
|
306
|
-
if line
|
307
|
-
line
|
306
|
+
if line =~ /^\s*#{Regexp.escape delimiter}/
|
307
|
+
line = $'
|
308
308
|
else
|
309
309
|
syntax_error! "Expected closing delimiter #{delimiter}", orig_line, lineno, orig_line.size - line.size
|
310
310
|
end
|
@@ -350,12 +350,12 @@ module Slim
|
|
350
350
|
break
|
351
351
|
elsif line =~ DELIMITER_REGEX
|
352
352
|
# Delimiter found, push it on the stack
|
353
|
-
stack << DELIMITERS[
|
353
|
+
stack << DELIMITERS[$&]
|
354
354
|
value << line.slice!(0)
|
355
355
|
elsif line =~ CLOSE_DELIMITER_REGEX
|
356
356
|
# Closing delimiter found, pop it from the stack if everything is ok
|
357
|
-
syntax_error! "Unexpected closing #{
|
358
|
-
syntax_error! "Expected closing #{stack.last}", orig_line, lineno if stack.last !=
|
357
|
+
syntax_error! "Unexpected closing #{$&}", orig_line, lineno if stack.empty?
|
358
|
+
syntax_error! "Expected closing #{stack.last}", orig_line, lineno if stack.last != $&
|
359
359
|
value << line.slice!(0)
|
360
360
|
stack.pop
|
361
361
|
else
|
@@ -368,7 +368,7 @@ module Slim
|
|
368
368
|
|
369
369
|
# Remove attribute wrapper which doesn't belong to the ruby code
|
370
370
|
# e.g id=[hash[:a] + hash[:b]]
|
371
|
-
value = value[1..-2] if value =~ DELIMITER_REGEX && DELIMITERS[
|
371
|
+
value = value[1..-2] if value =~ DELIMITER_REGEX && DELIMITERS[$&] == value[-1, 1]
|
372
372
|
|
373
373
|
return line, value
|
374
374
|
end
|
data/lib/slim/rails.rb
CHANGED
@@ -5,7 +5,9 @@ Slim::Engine.default_options[:disable_capture] = true
|
|
5
5
|
|
6
6
|
module ActionView
|
7
7
|
module TemplateHandlers
|
8
|
-
|
8
|
+
if Rails::VERSION::MAJOR < 3
|
9
|
+
raise "Slim supports only Rails 3.x and greater, your Rails version is #{Rails::VERSION::STRING}"
|
10
|
+
end
|
9
11
|
|
10
12
|
if Rails::VERSION::MAJOR == 3 && Rails::VERSION::MINOR < 1
|
11
13
|
# Slim handler for Rails 3.0
|
@@ -26,5 +28,5 @@ module ActionView
|
|
26
28
|
end
|
27
29
|
end
|
28
30
|
|
29
|
-
Template.
|
31
|
+
Template.register_template_handler :slim, TemplateHandlers::SlimHandler
|
30
32
|
end
|
data/lib/slim/version.rb
CHANGED
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 9
|
8
|
+
- 0
|
9
|
+
version: 0.9.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Andrew Stone
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2011-01-
|
19
|
+
date: 2011-01-30 00:00:00 -05:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|