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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ecd734b97658689e087ca19039ea51377c23d9e1c4be6099b084006150255fce
4
- data.tar.gz: d5a326fac6e3b57fe75fa3bc664ae8511a0e0dcf34f80dd5736ee8cc9709f5ee
3
+ metadata.gz: 5de40b5ed5a0e298dcf2bbb5461b0643a2044f0ee314f1211695da1e8b0c15a1
4
+ data.tar.gz: 8db5565c440bb65113054f58354d8dcfb4c761b2e3a1b1c4d4d758c9f74aa3f8
5
5
  SHA512:
6
- metadata.gz: ca0d59324036c9071c5f957235f10022d3db4841d4e4782e147f30e2cde1a1cd46873ede55db01b260676fc7289c0e7c4ad7e0e6ac7dbd0b38a1de8aa13333a1
7
- data.tar.gz: da5fb20229ecfac93b0436a0ed6954c109908429628cd635751c58fd9b3d029227da06a60bb80f5f4bd2fac55851ac258e7ff59d09fea59e93157f38d21c0fac
6
+ metadata.gz: 28b3ff2dcd11c1803a74175fdebd8592aab0da5b5df608a92923a9c56bb1dd41fba217b73ccc1a919b4ba6468c9ecb1e5a57f4fd4cce989307f08acf0c7d28ac
7
+ data.tar.gz: 3a0bcb5fb3c71f057ce7bdcf506aeca30829bb22558787d1d73c8a3a539f65cc9bcef9ead07c87f379378ec6885cc31b919582c1961eb8e921f81b04c620e949
@@ -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
@@ -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.strip.split(/\s+/)
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
- t, r, b, l = values
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CssParser
4
- VERSION = '1.9.0'.freeze
4
+ VERSION = '1.10.0'.freeze
5
5
  end
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.9.0
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-02-04 00:00:00.000000000 Z
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.1.3
173
+ rubygems_version: 3.2.16
174
174
  signing_key:
175
175
  specification_version: 4
176
176
  summary: Ruby CSS parser.