haml-edge 2.3.87 → 2.3.88
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/EDGE_GEM_VERSION +1 -1
- data/VERSION +1 -1
- data/lib/sass/script/lexer.rb +26 -9
- data/test/sass/script_test.rb +15 -3
- metadata +1 -1
data/EDGE_GEM_VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.3.
|
1
|
+
2.3.88
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.3.
|
1
|
+
2.3.88
|
data/lib/sass/script/lexer.rb
CHANGED
@@ -54,13 +54,32 @@ module Sass
|
|
54
54
|
:whitespace => /\s*/,
|
55
55
|
:variable => /!([\w-]+)/,
|
56
56
|
:ident => /(\\.|[^\s\\+*\/%(),=!])+/,
|
57
|
-
:string_end => /((?:\\.|\#(?!\{)|[^"\\#])*)(?:"|(?=#\{))/,
|
58
57
|
:number => /(-)?(?:(\d*\.\d+)|(\d+))([a-zA-Z%]+)?/,
|
59
58
|
:color => /\##{"([0-9a-fA-F]{1,2})" * 3}|(#{Color::HTML4_COLORS.keys.join("|")})(?!\()/,
|
60
59
|
:bool => /(true|false)\b/,
|
61
60
|
:op => %r{(#{Regexp.union(*OP_NAMES.map{|s| Regexp.new(Regexp.escape(s) + (s =~ /\w$/ ? '(?:\b|$)' : ''))})})}
|
62
61
|
}
|
63
62
|
|
63
|
+
class << self
|
64
|
+
private
|
65
|
+
def string_re(open, close)
|
66
|
+
/#{open}((?:\\.|\#(?!\{)|[^#{close}\\#])*)(#{close}|(?=#\{))/
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
# A hash of regular expressions that are used for tokenizing strings.
|
71
|
+
#
|
72
|
+
# The key is a [Symbol, Boolean] pair.
|
73
|
+
# The symbol represents which style of quotation to use,
|
74
|
+
# while the boolean represents whether or not the string
|
75
|
+
# is following an interpolated segment.
|
76
|
+
STRING_REGULAR_EXPRESSIONS = {
|
77
|
+
[:double, false] => string_re('"', '"'),
|
78
|
+
[:single, false] => string_re("'", "'"),
|
79
|
+
[:double, true] => string_re('', '"'),
|
80
|
+
[:single, true] => string_re('', "'"),
|
81
|
+
}
|
82
|
+
|
64
83
|
# @param str [String, StringScanner] The source text to lex
|
65
84
|
# @param line [Fixnum] The line on which the SassScript appears.
|
66
85
|
# Used for error reporting
|
@@ -71,6 +90,7 @@ module Sass
|
|
71
90
|
@line = line
|
72
91
|
@offset = offset
|
73
92
|
@filename = filename
|
93
|
+
@interpolation_stack = []
|
74
94
|
@prev = nil
|
75
95
|
end
|
76
96
|
|
@@ -114,8 +134,8 @@ module Sass
|
|
114
134
|
end
|
115
135
|
|
116
136
|
def token
|
117
|
-
return string(
|
118
|
-
variable || string || number || color || bool || op || ident
|
137
|
+
return string(@interpolation_stack.pop, true) if after_interpolation?
|
138
|
+
variable || string(:double, false) || string(:single, false) || number || color || bool || op || ident
|
119
139
|
end
|
120
140
|
|
121
141
|
def variable
|
@@ -128,15 +148,12 @@ module Sass
|
|
128
148
|
[:ident, s.gsub(/\\(.)/, '\1')]
|
129
149
|
end
|
130
150
|
|
131
|
-
def string(
|
132
|
-
return unless @scanner.scan(
|
151
|
+
def string(re, open)
|
152
|
+
return unless @scanner.scan(STRING_REGULAR_EXPRESSIONS[[re, open]])
|
153
|
+
@interpolation_stack << re if @scanner[2].empty? # Started an interpolated section
|
133
154
|
[:string, Script::String.new(@scanner[1].gsub(/\\([^0-9a-f])/, '\1').gsub(/\\([0-9a-f]{1,4})/, "\\\\\\1"))]
|
134
155
|
end
|
135
156
|
|
136
|
-
def begin_interpolation
|
137
|
-
@scanner.scan
|
138
|
-
end
|
139
|
-
|
140
157
|
def number
|
141
158
|
return unless @scanner.scan(REGULAR_EXPRESSIONS[:number])
|
142
159
|
value = @scanner[2] ? @scanner[2].to_f : @scanner[3].to_i
|
data/test/sass/script_test.rb
CHANGED
@@ -16,9 +16,21 @@ class SassScriptTest < Test::Unit::TestCase
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def test_string_escapes
|
19
|
+
assert_equal "'", resolve("\"'\"")
|
19
20
|
assert_equal '"', resolve("\"\\\"\"")
|
20
21
|
assert_equal "\\", resolve("\"\\\\\"")
|
21
22
|
assert_equal "\\02fa", resolve("\"\\02fa\"")
|
23
|
+
|
24
|
+
assert_equal "'", resolve("'\\''")
|
25
|
+
assert_equal '"', resolve("'\"'")
|
26
|
+
assert_equal "\\", resolve("'\\\\'")
|
27
|
+
assert_equal "\\02fa", resolve("'\\02fa'")
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_string_interpolation
|
31
|
+
assert_equal "foo2bar", resolve('\'foo#{1 + 1}bar\'')
|
32
|
+
assert_equal "foo2bar", resolve('"foo#{1 + 1}bar"')
|
33
|
+
assert_equal "foo1bar5baz4bang", resolve('\'foo#{1 + "bar#{2 + 3}baz" + 4}bang\'')
|
22
34
|
end
|
23
35
|
|
24
36
|
def test_color_names
|
@@ -188,16 +200,16 @@ WARN
|
|
188
200
|
def test_string_ops
|
189
201
|
assert_equal "foo bar", resolve('"foo" "bar"')
|
190
202
|
assert_equal "true 1", resolve('true 1')
|
191
|
-
assert_equal "foo, bar", resolve('
|
203
|
+
assert_equal "foo, bar", resolve("'foo' , 'bar'")
|
192
204
|
assert_equal "true, 1", resolve('true , 1')
|
193
205
|
assert_equal "foobar", resolve('"foo" + "bar"')
|
194
206
|
assert_equal "true1", resolve('true + 1')
|
195
|
-
assert_equal "foo-bar", resolve('
|
207
|
+
assert_equal "foo-bar", resolve("'foo' - 'bar'")
|
196
208
|
assert_equal "true-1", resolve('true - 1')
|
197
209
|
assert_equal "foo/bar", resolve('"foo" / "bar"')
|
198
210
|
assert_equal "true/1", resolve('true / 1')
|
199
211
|
|
200
|
-
assert_equal "-bar", resolve(
|
212
|
+
assert_equal "-bar", resolve("- 'bar'")
|
201
213
|
assert_equal "-true", resolve('- true')
|
202
214
|
assert_equal "/bar", resolve('/ "bar"')
|
203
215
|
assert_equal "/true", resolve('/ true')
|