css_parser 1.7.0 → 1.11.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module CssParser
2
- VERSION = "1.7.0".freeze
4
+ VERSION = '1.11.0'.freeze
3
5
  end
data/lib/css_parser.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'addressable/uri'
3
4
  require 'uri'
4
5
  require 'net/https'
@@ -13,7 +14,6 @@ require 'css_parser/regexps'
13
14
  require 'css_parser/parser'
14
15
 
15
16
  module CssParser
16
-
17
17
  # Merge multiple CSS RuleSets by cascading according to the CSS 2.1 cascading rules
18
18
  # (http://www.w3.org/TR/REC-CSS2/cascade.html#cascading-order).
19
19
  #
@@ -56,10 +56,10 @@ module CssParser
56
56
  @folded_declaration_cache = {}
57
57
 
58
58
  # in case called like CssParser.merge([rule_set, rule_set])
59
- rule_sets.flatten! if rule_sets[0].kind_of?(Array)
59
+ rule_sets.flatten! if rule_sets[0].is_a?(Array)
60
60
 
61
- unless rule_sets.all? {|rs| rs.kind_of?(CssParser::RuleSet)}
62
- raise ArgumentError, "all parameters must be CssParser::RuleSets."
61
+ unless rule_sets.all? { |rs| rs.is_a?(CssParser::RuleSet) }
62
+ raise ArgumentError, 'all parameters must be CssParser::RuleSets.'
63
63
  end
64
64
 
65
65
  return rule_sets[0] if rule_sets.length == 1
@@ -71,38 +71,27 @@ module CssParser
71
71
  rule_set.expand_shorthand!
72
72
 
73
73
  specificity = rule_set.specificity
74
- unless specificity
75
- if rule_set.selectors.length == 0
76
- specificity = 0
77
- else
78
- specificity = rule_set.selectors.map { |s| calculate_specificity(s) }.compact.max || 0
79
- end
80
- end
74
+ specificity ||= rule_set.selectors.map { |s| calculate_specificity(s) }.compact.max || 0
81
75
 
82
76
  rule_set.each_declaration do |property, value, is_important|
83
77
  # Add the property to the list to be folded per http://www.w3.org/TR/CSS21/cascade.html#cascading-order
84
- if not properties.has_key?(property)
85
- properties[property] = {:value => value, :specificity => specificity, :is_important => is_important}
78
+ if not properties.key?(property)
79
+ properties[property] = {value: value, specificity: specificity, is_important: is_important}
86
80
  elsif is_important
87
81
  if not properties[property][:is_important] or properties[property][:specificity] <= specificity
88
- properties[property] = {:value => value, :specificity => specificity, :is_important => is_important}
82
+ properties[property] = {value: value, specificity: specificity, is_important: is_important}
89
83
  end
90
84
  elsif properties[property][:specificity] < specificity or properties[property][:specificity] == specificity
91
85
  unless properties[property][:is_important]
92
- properties[property] = {:value => value, :specificity => specificity, :is_important => is_important}
86
+ properties[property] = {value: value, specificity: specificity, is_important: is_important}
93
87
  end
94
88
  end
95
- end
89
+ end
96
90
  end
97
91
 
98
- merged = RuleSet.new(nil, nil)
99
-
100
- properties.each do |property, details|
101
- if details[:is_important]
102
- merged[property.strip] = details[:value].strip.gsub(/\;\Z/, '') + '!important'
103
- else
104
- merged[property.strip] = details[:value].strip
105
- end
92
+ merged = properties.each_with_object(RuleSet.new(nil, nil)) do |(property, details), rule_set|
93
+ value = details[:value].strip
94
+ rule_set[property.strip] = details[:is_important] ? "#{value.gsub(/;\Z/, '')}!important" : value
106
95
  end
107
96
 
108
97
  merged.create_shorthand!
@@ -128,7 +117,7 @@ module CssParser
128
117
 
129
118
  "#{a}#{b}#{c}#{d}".to_i
130
119
  rescue
131
- return 0
120
+ 0
132
121
  end
133
122
 
134
123
  # Make <tt>url()</tt> links absolute.
@@ -145,23 +134,24 @@ module CssParser
145
134
  # "http://example.org/style/basic.css").inspect
146
135
  # => "body { background: url('http://example.org/style/yellow.png?abc=123') };"
147
136
  def self.convert_uris(css, base_uri)
148
- base_uri = Addressable::URI.parse(base_uri) unless base_uri.kind_of?(Addressable::URI)
137
+ base_uri = Addressable::URI.parse(base_uri) unless base_uri.is_a?(Addressable::URI)
149
138
 
150
139
  css.gsub(URI_RX) do
151
- uri = $1.to_s
152
- uri.gsub!(/["']+/, '')
140
+ uri = Regexp.last_match(1).to_s.gsub(/["']+/, '')
153
141
  # Don't process URLs that are already absolute
154
- unless uri =~ /^[a-z]+\:\/\//i
142
+ unless uri.match(%r{^[a-z]+://}i)
155
143
  begin
156
- uri = base_uri + uri
157
- rescue; end
144
+ uri = base_uri.join(uri)
145
+ rescue
146
+ nil
147
+ end
158
148
  end
159
- "url('#{uri.to_s}')"
149
+ "url('#{uri}')"
160
150
  end
161
151
  end
162
152
 
163
153
  def self.sanitize_media_query(raw)
164
- mq = raw.to_s.gsub(/[\s]+/, ' ')
154
+ mq = raw.to_s.gsub(/\s+/, ' ')
165
155
  mq.strip!
166
156
  mq = 'all' if mq.empty?
167
157
  mq.to_sym
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.7.0
4
+ version: 1.11.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: 2019-02-11 00:00:00.000000000 Z
11
+ date: 2021-12-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -24,6 +24,118 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: benchmark-ips
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bump
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: maxitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: memory_profiler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.8'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.8'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop-rake
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: webrick
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
27
139
  description: A set of classes for parsing CSS in Ruby.
28
140
  email: code@dunae.ca
29
141
  executables: []
@@ -39,7 +151,10 @@ files:
39
151
  homepage: https://github.com/premailer/css_parser
40
152
  licenses:
41
153
  - MIT
42
- metadata: {}
154
+ metadata:
155
+ changelog_uri: https://github.com/premailer/css_parser/blob/master/CHANGELOG.md
156
+ source_code_uri: https://github.com/premailer/css_parser
157
+ bug_tracker_uri: https://github.com/premailer/css_parser/issues
43
158
  post_install_message:
44
159
  rdoc_options: []
45
160
  require_paths:
@@ -48,15 +163,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
48
163
  requirements:
49
164
  - - ">="
50
165
  - !ruby/object:Gem::Version
51
- version: '0'
166
+ version: '2.4'
52
167
  required_rubygems_version: !ruby/object:Gem::Requirement
53
168
  requirements:
54
169
  - - ">="
55
170
  - !ruby/object:Gem::Version
56
171
  version: '0'
57
172
  requirements: []
58
- rubyforge_project:
59
- rubygems_version: 2.7.6
173
+ rubygems_version: 3.2.16
60
174
  signing_key:
61
175
  specification_version: 4
62
176
  summary: Ruby CSS parser.