css_parser 1.9.0 → 1.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/css_parser/regexps.rb +16 -0
- data/lib/css_parser/rule_set.rb +17 -3
- data/lib/css_parser/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5de40b5ed5a0e298dcf2bbb5461b0643a2044f0ee314f1211695da1e8b0c15a1
|
4
|
+
data.tar.gz: 8db5565c440bb65113054f58354d8dcfb4c761b2e3a1b1c4d4d758c9f74aa3f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 28b3ff2dcd11c1803a74175fdebd8592aab0da5b5df608a92923a9c56bb1dd41fba217b73ccc1a919b4ba6468c9ecb1e5a57f4fd4cce989307f08acf0c7d28ac
|
7
|
+
data.tar.gz: 3a0bcb5fb3c71f057ce7bdcf506aeca30829bb22558787d1d73c8a3a539f65cc9bcef9ead07c87f379378ec6885cc31b919582c1961eb8e921f81b04c620e949
|
data/lib/css_parser/regexps.rb
CHANGED
@@ -58,6 +58,22 @@ module CssParser
|
|
58
58
|
RE_BORDER_STYLE = /(\s*^)?(none|hidden|dotted|dashed|solid|double|dot-dash|dot-dot-dash|wave|groove|ridge|inset|outset)(\s*$)?/imx.freeze
|
59
59
|
RE_BORDER_UNITS = Regexp.union(BOX_MODEL_UNITS_RX, /(thin|medium|thick)/i)
|
60
60
|
|
61
|
+
# Functions like calc, var, clamp, etc.
|
62
|
+
RE_FUNCTIONS = /
|
63
|
+
(
|
64
|
+
[a-z0-9-]+ # function name
|
65
|
+
)
|
66
|
+
(?>
|
67
|
+
\( # opening parenthesis
|
68
|
+
(?:
|
69
|
+
([^()]+)
|
70
|
+
| # recursion via subexpression
|
71
|
+
\g<0>
|
72
|
+
)*
|
73
|
+
\) # closing parenthesis
|
74
|
+
)
|
75
|
+
/imx.freeze
|
76
|
+
|
61
77
|
# Patterns for specificity calculations
|
62
78
|
NON_ID_ATTRIBUTES_AND_PSEUDO_CLASSES_RX_NC = /
|
63
79
|
(?:\.\w+) # classes
|
data/lib/css_parser/rule_set.rb
CHANGED
@@ -24,6 +24,8 @@ module CssParser
|
|
24
24
|
['border-width', %w[border-top-width border-right-width border-bottom-width border-left-width]]
|
25
25
|
].freeze
|
26
26
|
|
27
|
+
WHITESPACE_REPLACEMENT = '___SPACE___'
|
28
|
+
|
27
29
|
class Declarations
|
28
30
|
class Value
|
29
31
|
attr_reader :value
|
@@ -358,7 +360,7 @@ module CssParser
|
|
358
360
|
# TODO: rgba, hsl, hsla
|
359
361
|
value.gsub!(RE_COLOUR) { |c| c.gsub(/(\s*,\s*)/, ',') }
|
360
362
|
|
361
|
-
matches = value
|
363
|
+
matches = split_value_preserving_function_whitespace(value)
|
362
364
|
|
363
365
|
case matches.length
|
364
366
|
when 1
|
@@ -374,8 +376,7 @@ module CssParser
|
|
374
376
|
raise ArgumentError, "Cannot parse #{value}"
|
375
377
|
end
|
376
378
|
|
377
|
-
|
378
|
-
replacement = {top => t, right => r, bottom => b, left => l}
|
379
|
+
replacement = [top, right, bottom, left].zip(values).to_h
|
379
380
|
|
380
381
|
declarations.replace_declaration!(property, replacement, preserve_importance: true)
|
381
382
|
end
|
@@ -634,6 +635,19 @@ module CssParser
|
|
634
635
|
s
|
635
636
|
end
|
636
637
|
end
|
638
|
+
|
639
|
+
def split_value_preserving_function_whitespace(value)
|
640
|
+
split_value = value.gsub(RE_FUNCTIONS) do |c|
|
641
|
+
c.gsub!(/\s+/, WHITESPACE_REPLACEMENT)
|
642
|
+
c
|
643
|
+
end
|
644
|
+
|
645
|
+
matches = split_value.strip.split(/\s+/)
|
646
|
+
|
647
|
+
matches.each do |c|
|
648
|
+
c.gsub!(WHITESPACE_REPLACEMENT, ' ')
|
649
|
+
end
|
650
|
+
end
|
637
651
|
end
|
638
652
|
|
639
653
|
class OffsetAwareRuleSet < RuleSet
|
data/lib/css_parser/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: css_parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Dunae
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-07-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|
@@ -170,7 +170,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
170
170
|
- !ruby/object:Gem::Version
|
171
171
|
version: '0'
|
172
172
|
requirements: []
|
173
|
-
rubygems_version: 3.
|
173
|
+
rubygems_version: 3.2.16
|
174
174
|
signing_key:
|
175
175
|
specification_version: 4
|
176
176
|
summary: Ruby CSS parser.
|