css_parser 1.1.6 → 1.1.7
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/css_parser.rb +1 -1
- data/lib/css_parser/parser.rb +6 -0
- data/lib/css_parser/rule_set.rb +24 -25
- data/test/test_css_parser_basic.rb +5 -0
- metadata +3 -3
data/lib/css_parser.rb
CHANGED
data/lib/css_parser/parser.rb
CHANGED
@@ -215,6 +215,7 @@ module CssParser
|
|
215
215
|
block.scan(/([\\]?[{}\s"]|(.[^\s"{}\\]*))/).each do |matches|
|
216
216
|
#block.scan(/((.[^{}"\n\r\f\s]*)[\s]|(.[^{}"\n\r\f]*)\{|(.[^{}"\n\r\f]*)\}|(.[^{}"\n\r\f]*)\"|(.*)[\s]+)/).each do |matches|
|
217
217
|
token = matches[0]
|
218
|
+
|
218
219
|
#puts "TOKEN: #{token}" unless token =~ /^[\s]*$/
|
219
220
|
if token =~ /\A"/ # found un-escaped double quote
|
220
221
|
in_string = !in_string
|
@@ -277,6 +278,11 @@ module CssParser
|
|
277
278
|
end
|
278
279
|
end
|
279
280
|
end
|
281
|
+
|
282
|
+
# check for unclosed braces
|
283
|
+
if in_declarations > 0
|
284
|
+
add_rule!(current_selectors, current_declarations, media_types)
|
285
|
+
end
|
280
286
|
end
|
281
287
|
|
282
288
|
# Load a remote CSS file.
|
data/lib/css_parser/rule_set.rb
CHANGED
@@ -125,31 +125,6 @@ module CssParser
|
|
125
125
|
create_font_shorthand!
|
126
126
|
end
|
127
127
|
|
128
|
-
private
|
129
|
-
def parse_declarations!(block) # :nodoc:
|
130
|
-
@declarations = {}
|
131
|
-
|
132
|
-
return unless block
|
133
|
-
|
134
|
-
block.gsub!(/(^[\s]*)|([\s]*$)/, '')
|
135
|
-
|
136
|
-
block.split(/[\;$]+/m).each do |decs|
|
137
|
-
if matches = decs.match(/(.[^:]*)\:(.[^;]*)(;|\Z)/i)
|
138
|
-
property, value, end_of_declaration = matches.captures
|
139
|
-
|
140
|
-
add_declaration!(property, value)
|
141
|
-
end
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
#--
|
146
|
-
# TODO: way too simplistic
|
147
|
-
#++
|
148
|
-
def parse_selectors!(selectors) # :nodoc:
|
149
|
-
@selectors = selectors.split(',')
|
150
|
-
end
|
151
|
-
|
152
|
-
public
|
153
128
|
# Split shorthand dimensional declarations (e.g. <tt>margin: 0px auto;</tt>)
|
154
129
|
# into their constituent parts.
|
155
130
|
def expand_dimensions_shorthand! # :nodoc:
|
@@ -390,5 +365,29 @@ public
|
|
390
365
|
end
|
391
366
|
|
392
367
|
end
|
368
|
+
|
369
|
+
private
|
370
|
+
def parse_declarations!(block) # :nodoc:
|
371
|
+
@declarations = {}
|
372
|
+
|
373
|
+
return unless block
|
374
|
+
|
375
|
+
block.gsub!(/(^[\s]*)|([\s]*$)/, '')
|
376
|
+
|
377
|
+
block.split(/[\;$]+/m).each do |decs|
|
378
|
+
if matches = decs.match(/(.[^:]*)\:(.[^;]*)(;|\Z)/i)
|
379
|
+
property, value, end_of_declaration = matches.captures
|
380
|
+
|
381
|
+
add_declaration!(property, value)
|
382
|
+
end
|
383
|
+
end
|
384
|
+
end
|
385
|
+
|
386
|
+
#--
|
387
|
+
# TODO: way too simplistic
|
388
|
+
#++
|
389
|
+
def parse_selectors!(selectors) # :nodoc:
|
390
|
+
@selectors = selectors.split(',')
|
391
|
+
end
|
393
392
|
end
|
394
393
|
end
|
@@ -27,6 +27,11 @@ class CssParserBasicTests < Test::Unit::TestCase
|
|
27
27
|
assert_equal 'margin: 0px;', @cp.find_by_selector('body').join
|
28
28
|
end
|
29
29
|
|
30
|
+
def test_adding_block_without_closing_brace
|
31
|
+
@cp.add_block!('p { color: red;')
|
32
|
+
assert_equal 'color: red;', @cp.find_by_selector('p').join
|
33
|
+
end
|
34
|
+
|
30
35
|
def test_adding_a_rule
|
31
36
|
@cp.add_rule!('div', 'color: blue;')
|
32
37
|
assert_equal 'color: blue;', @cp.find_by_selector('div').join(' ')
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 1
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 1.1.
|
8
|
+
- 7
|
9
|
+
version: 1.1.7
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Alex Dunae
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-03-
|
17
|
+
date: 2011-03-29 00:00:00 -07:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|