css_parser 1.15.0 → 1.17.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: 91aaa83da45a315177fda1bff179f8a313c46f441e378c66b8cc95d6d5808c68
4
- data.tar.gz: 25db2114f5bcc9fd310ca5ccdfed5f47a87ec22098cc1b16754c1f824569a7db
3
+ metadata.gz: 47d696725a77d514c0a1ca529dc18e39d41bdd4106a786f21219f14c2ccf43f5
4
+ data.tar.gz: eb6a39b541cfa6bd8c4d66fc4e0adb06310922794b47e582989aba6dd8f5729b
5
5
  SHA512:
6
- metadata.gz: 7be87bf3530120ca4c9277973c7a945af18441ed3d574ff52cff4c0547787197d0b59a724af64b1b186366326db464c0afd0139c8489dee8b171980e77707c21
7
- data.tar.gz: a2e590d95594aeac08604b4b0591979c6c91d81fe785e46c573f84b4e3bfab8aa7b050d12799309223c2ca58fef40f49a79a0db62124c1924a079769f725b596
6
+ metadata.gz: db5d0a6cf245796841621194c360c31f5f349596fa00a755152bd109a50707ff5dc301a47601fb09400fa00479e2319a9321f3657c9eb0d5a11b4db7c5d8b048
7
+ data.tar.gz: 7dd50eff88bc656f81928098d736fb7c657ebe6ced0328523cee6e3e778f5b2e7d285311436be6ffd210f8b122467f99dfad739828d43530db41e60a74694b25
@@ -17,7 +17,6 @@ module CssParser
17
17
  # [<tt>io_exceptions</tt>] Throw an exception if a link can not be found. Boolean, default is <tt>true</tt>.
18
18
  class Parser
19
19
  USER_AGENT = "Ruby CSS Parser/#{CssParser::VERSION} (https://github.com/premailer/css_parser)"
20
-
21
20
  STRIP_CSS_COMMENTS_RX = %r{/\*.*?\*/}m.freeze
22
21
  STRIP_HTML_COMMENTS_RX = /<!--|-->/m.freeze
23
22
 
@@ -36,11 +35,14 @@ module CssParser
36
35
  class << self; attr_reader :folded_declaration_cache; end
37
36
 
38
37
  def initialize(options = {})
39
- @options = {absolute_paths: false,
40
- import: true,
41
- io_exceptions: true,
42
- rule_set_exceptions: true,
43
- capture_offsets: false}.merge(options)
38
+ @options = {
39
+ absolute_paths: false,
40
+ import: true,
41
+ io_exceptions: true,
42
+ rule_set_exceptions: true,
43
+ capture_offsets: false,
44
+ user_agent: USER_AGENT
45
+ }.merge(options)
44
46
 
45
47
  # array of RuleSets
46
48
  @rules = []
@@ -329,7 +331,7 @@ module CssParser
329
331
  rule_start = nil
330
332
  offset = nil
331
333
 
332
- block.scan(/\s+|\\{2,}|\\?[{}\s"]|.[^\s"{}\\]*/) do |token|
334
+ block.scan(/\s+|\\{2,}|\\?[{}\s"]|[()]|.[^\s"{}()\\]*/) do |token|
333
335
  # save the regex offset so that we know where in the file we are
334
336
  offset = Regexp.last_match.offset(0) if options[:capture_offsets]
335
337
 
@@ -391,7 +393,16 @@ module CssParser
391
393
  current_media_query = String.new
392
394
  else
393
395
  token.strip!
394
- current_media_query << token << ' '
396
+ # special-case the ( and ) tokens to remove inner-whitespace
397
+ # (eg we'd prefer '(width: 500px)' to '( width: 500px )' )
398
+ case token
399
+ when '('
400
+ current_media_query << token
401
+ when ')'
402
+ current_media_query.sub!(/ ?$/, token)
403
+ else
404
+ current_media_query << token << ' '
405
+ end
395
406
  end
396
407
  elsif in_charset or token =~ /@charset/i
397
408
  # iterate until we are out of the charset declaration
@@ -588,7 +599,7 @@ module CssParser
588
599
  http = Net::HTTP.new(uri.host, uri.port)
589
600
  end
590
601
 
591
- res = http.get(uri.request_uri, {'User-Agent' => USER_AGENT, 'Accept-Encoding' => 'gzip'})
602
+ res = http.get(uri.request_uri, {'User-Agent' => @options[:user_agent], 'Accept-Encoding' => 'gzip'})
592
603
  src = res.body
593
604
  charset = res.respond_to?(:charset) ? res.encoding : 'utf-8'
594
605
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CssParser
4
- VERSION = '1.15.0'.freeze
4
+ VERSION = '1.17.0'.freeze
5
5
  end
data/lib/css_parser.rb CHANGED
@@ -75,13 +75,13 @@ module CssParser
75
75
 
76
76
  rule_set.each_declaration do |property, value, is_important|
77
77
  # Add the property to the list to be folded per http://www.w3.org/TR/CSS21/cascade.html#cascading-order
78
- if not properties.key?(property)
78
+ if !properties.key?(property)
79
79
  properties[property] = {value: value, specificity: specificity, is_important: is_important}
80
80
  elsif is_important
81
- if not properties[property][:is_important] or properties[property][:specificity] <= specificity
81
+ if !properties[property][:is_important] || properties[property][:specificity] <= specificity
82
82
  properties[property] = {value: value, specificity: specificity, is_important: is_important}
83
83
  end
84
- elsif properties[property][:specificity] < specificity or properties[property][:specificity] == specificity
84
+ elsif properties[property][:specificity] < specificity || properties[property][:specificity] == specificity
85
85
  unless properties[property][:is_important]
86
86
  properties[property] = {value: value, specificity: specificity, is_important: is_important}
87
87
  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.15.0
4
+ version: 1.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Dunae
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-08-29 00:00:00.000000000 Z
11
+ date: 2024-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -155,7 +155,7 @@ metadata:
155
155
  changelog_uri: https://github.com/premailer/css_parser/blob/master/CHANGELOG.md
156
156
  source_code_uri: https://github.com/premailer/css_parser
157
157
  bug_tracker_uri: https://github.com/premailer/css_parser/issues
158
- post_install_message:
158
+ post_install_message:
159
159
  rdoc_options: []
160
160
  require_paths:
161
161
  - lib
@@ -171,7 +171,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
171
171
  version: '0'
172
172
  requirements: []
173
173
  rubygems_version: 3.1.6
174
- signing_key:
174
+ signing_key:
175
175
  specification_version: 4
176
176
  summary: Ruby CSS parser.
177
177
  test_files: []