css_parser 1.21.0 → 2.0.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c8880ebd6978e8a8a3108ea93b4d567252aee152b28f237dab31809f1488f42e
4
- data.tar.gz: 4e8379acf246b7fe2573a2ada4fc49c01e9c3b2de43fe80d07f42390f8f16450
3
+ metadata.gz: 85c1ed60af098bd844114375df9517e7859db55440a1b4f7d91362c91f80a916
4
+ data.tar.gz: df39d79d248b8153e5cd0ebc1754a31e8d366a1b7c23a8fb6c316d84bd774df1
5
5
  SHA512:
6
- metadata.gz: 480947bb06a6c40ab955f76ff9eb7ba9ac5caf160d7fe343d16901e9f37210c9ccab22a07a4d3165ec26bec4cd28547f530718978d2d969ed398c8195351a0c0
7
- data.tar.gz: e7a757c9dc096e71d5f617343f0900bacddea42bef4b26ca68f2830728a480ace908807dc4db82b6b0b77a11c1b2c9295ad814bb2aaa80fd069c959cd58afe65
6
+ metadata.gz: ce543588bb1b082bd0cc671dd29705f67f7b56c5ea05d53f24c7e48f13746f648a2d36adcd625837757a7562e466e569060132d81d8d9befae47f201fd7bffd8
7
+ data.tar.gz: 78c1fdc5fd1ec624cfbc209860dfccd7677fb5c564daf9fb7d6a23ed6360215d36495adfbf1bfa23fee023f07fe4e4e27127e501ce3e8b2d6779ee1ed7acec6e
@@ -31,12 +31,6 @@ module CssParser
31
31
  # Array of CSS files that have been loaded.
32
32
  attr_reader :loaded_uris
33
33
 
34
- #--
35
- # Class variable? see http://www.oreillynet.com/ruby/blog/2007/01/nubygems_dont_use_class_variab_1.html
36
- #++
37
- @folded_declaration_cache = {}
38
- class << self; attr_reader :folded_declaration_cache; end
39
-
40
34
  def initialize(options = {})
41
35
  @options = {
42
36
  absolute_paths: false,
@@ -143,7 +137,7 @@ module CssParser
143
137
  media_types = [:all]
144
138
  end
145
139
 
146
- next unless options[:only_media_types].include?(:all) or media_types.empty? or !(media_types & options[:only_media_types]).empty?
140
+ next unless options[:only_media_types].include?(:all) or media_types.empty? or media_types.intersect?(options[:only_media_types])
147
141
 
148
142
  import_path = import_rule[0].to_s.gsub(/['"]*/, '').strip
149
143
 
@@ -448,7 +442,7 @@ module CssParser
448
442
  current_media_query << token << ' '
449
443
  end
450
444
  end
451
- elsif in_charset or token =~ /@charset/i
445
+ elsif in_charset or /@charset/i.match?(token)
452
446
  # iterate until we are out of the charset declaration
453
447
  in_charset = !token.include?(';')
454
448
  elsif !in_string && token.include?('}')
@@ -467,7 +461,7 @@ module CssParser
467
461
  current_selectors << token
468
462
 
469
463
  # mark this as the beginning of the selector unless we have already marked it
470
- rule_start = start_offset if options[:capture_offsets] && rule_start.nil? && token =~ /^[^\s]+$/
464
+ rule_start = start_offset if options[:capture_offsets] && rule_start.nil? && /^[^\s]+$/.match?(token)
471
465
  end
472
466
  end
473
467
 
@@ -568,7 +562,8 @@ module CssParser
568
562
  #
569
563
  # Raises a CircularReferenceError exception if io_exceptions are on,
570
564
  # otherwise returns true/false.
571
- def circular_reference_check(path)
565
+ # TODO: fix rubocop
566
+ def circular_reference_check(path) # rubocop:disable Naming/PredicateMethod
572
567
  path = path.to_s
573
568
  if @loaded_uris.include?(path)
574
569
  raise CircularReferenceError, "can't load #{path} more than once" if @options[:io_exceptions]
@@ -89,17 +89,20 @@ module CssParser
89
89
  # puts declarations['margin']
90
90
  # => #<CssParser::RuleSet::Declarations::Value:0x00000000030c1838 @important=true, @order=2, @value="0px auto">
91
91
  #
92
- # If the property already exists its value will be over-written.
92
+ # If the property already exists its value will be over-written unless it was !important and the new value
93
+ # is not !important.
93
94
  # If the value is empty - property will be deleted
94
95
  def []=(property, value)
95
96
  property = normalize_property(property)
97
+ currently_important = declarations[property]&.important
96
98
 
97
- if value.is_a?(Value)
99
+ if value.is_a?(Value) && (!currently_important || value.important)
98
100
  declarations[property] = value
99
101
  elsif value.to_s.strip.empty?
100
102
  delete property
101
103
  else
102
- declarations[property] = Value.new(value)
104
+ value = Value.new(value)
105
+ declarations[property] = value if !currently_important || value.important
103
106
  end
104
107
  rescue ArgumentError => e
105
108
  raise e.exception, "#{property} #{e.message}"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CssParser
4
- VERSION = '1.21.0'.freeze
4
+ VERSION = '2.0.0'.freeze
5
5
  end
data/lib/css_parser.rb CHANGED
@@ -52,8 +52,6 @@ module CssParser
52
52
  # TODO: declaration_hashes should be able to contain a RuleSet
53
53
  # this should be a Class method
54
54
  def self.merge(*rule_sets)
55
- @folded_declaration_cache = {}
56
-
57
55
  # in case called like CssParser.merge([rule_set, rule_set])
58
56
  rule_sets.flatten! if rule_sets[0].is_a?(Array)
59
57
 
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: css_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.21.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Dunae
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-12-13 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: addressable
@@ -44,7 +43,6 @@ metadata:
44
43
  source_code_uri: https://github.com/premailer/css_parser
45
44
  bug_tracker_uri: https://github.com/premailer/css_parser/issues
46
45
  rubygems_mfa_required: 'true'
47
- post_install_message:
48
46
  rdoc_options: []
49
47
  require_paths:
50
48
  - lib
@@ -52,15 +50,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
52
50
  requirements:
53
51
  - - ">="
54
52
  - !ruby/object:Gem::Version
55
- version: '3.0'
53
+ version: '3.3'
56
54
  required_rubygems_version: !ruby/object:Gem::Requirement
57
55
  requirements:
58
56
  - - ">="
59
57
  - !ruby/object:Gem::Version
60
58
  version: '0'
61
59
  requirements: []
62
- rubygems_version: 3.4.19
63
- signing_key:
60
+ rubygems_version: 4.0.3
64
61
  specification_version: 4
65
62
  summary: Ruby CSS parser.
66
63
  test_files: []