css_parser 1.3.7 → 1.4.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
  SHA1:
3
- metadata.gz: 6ffcb3340dbf48f0ab35f5d27c63a16b6a1a948c
4
- data.tar.gz: c33511de9fb08a3e34a59a24b72063eed4f54561
3
+ metadata.gz: 0b24b01cc09a9975b249b7f68331c44a4b2e6d00
4
+ data.tar.gz: 7dc6b7777312134d63abf3ba61154ec152f5ee40
5
5
  SHA512:
6
- metadata.gz: 6972c831ca48c5c1b796ee4b7a3c85f855651d4fb954c26f822360d37f0d573d29d12f29dc2f26fccd2fa3ef57afd167a7928d5d9633f6ed45ddbd574cdfaa1c
7
- data.tar.gz: 5fa36e3e019f67f9b3c594be09ebec77a1318a6f087b469392b71891948ab38c9d03cdffeb3bdc269d8b2bb704f12e17babc0a4f68648bdbd4c617050cef53d7
6
+ metadata.gz: bf202f430205ba83586fbc04ebe084ca12fe552303b70691ae69755ea8d8753cdc94cc1dc87ef4d22bff55b134880f2c23133764539d75b7a4080c67e834fccd
7
+ data.tar.gz: 9384222c4c92f027b0869a2941459ab5ad408b054b7180d4f2aef5e0e784b2a8601057065d1e03794e3710b8744c7f0b5ea280382e386ab3a31b1ac1fcf85785
@@ -47,6 +47,7 @@ module CssParser
47
47
  BOX_MODEL_UNITS_RX = /(auto|inherit|0|([\-]*([0-9]+|[0-9]*\.[0-9]+)(e[mx]+|px|[cm]+m|p[tc+]|in|\%)))([\s;]|\Z)/imx
48
48
  RE_LENGTH_OR_PERCENTAGE = Regexp.new('([\-]*(([0-9]*\.[0-9]+)|[0-9]+)(e[mx]+|px|[cm]+m|p[tc+]|in|\%))', Regexp::IGNORECASE)
49
49
  RE_BACKGROUND_POSITION = Regexp.new("((((#{RE_LENGTH_OR_PERCENTAGE})|left|center|right|top|bottom)[\s]*){1,2})", Regexp::IGNORECASE | Regexp::EXTENDED)
50
+ RE_BACKGROUND_SIZE = Regexp.new("\\s*/\\s*((((#{RE_LENGTH_OR_PERCENTAGE})|auto|cover|contain|initial|inherit)[\\s]*){1,2})", Regexp::IGNORECASE | Regexp::EXTENDED)
50
51
  FONT_UNITS_RX = /(([x]+\-)*small|medium|large[r]*|auto|inherit|([0-9]+|[0-9]*\.[0-9]+)(e[mx]+|px|[cm]+m|p[tc+]|in|\%)*)/i
51
52
  RE_BORDER_STYLE = /([\s]*^)?(none|hidden|dotted|dashed|solid|double|dot-dash|dot-dot-dash|wave|groove|ridge|inset|outset)([\s]*$)?/imx
52
53
  RE_BORDER_UNITS = Regexp.union(BOX_MODEL_UNITS_RX, /(thin|medium|thick)/i)
@@ -4,7 +4,7 @@ module CssParser
4
4
  RE_ELEMENTS_AND_PSEUDO_ELEMENTS = /((^|[\s\+\>]+)[\w]+|\:(first\-line|first\-letter|before|after))/i
5
5
  RE_NON_ID_ATTRIBUTES_AND_PSEUDO_CLASSES = /(\.[\w]+)|(\[[\w]+)|(\:(link|first\-child|lang))/i
6
6
 
7
- BACKGROUND_PROPERTIES = ['background-color', 'background-image', 'background-repeat', 'background-position', 'background-attachment']
7
+ BACKGROUND_PROPERTIES = ['background-color', 'background-image', 'background-repeat', 'background-position', 'background-size', 'background-attachment']
8
8
  LIST_STYLE_PROPERTIES = ['list-style-type', 'list-style-position', 'list-style-image']
9
9
 
10
10
  # Array of selector strings.
@@ -149,11 +149,18 @@ module CssParser
149
149
  split_declaration('background', 'background-attachment', value.slice!(CssParser::RE_SCROLL_FIXED))
150
150
  split_declaration('background', 'background-repeat', value.slice!(CssParser::RE_REPEAT))
151
151
  split_declaration('background', 'background-color', value.slice!(CssParser::RE_COLOUR))
152
+ split_declaration('background', 'background-size', extract_background_size_from(value))
152
153
  split_declaration('background', 'background-position', value.slice(CssParser::RE_BACKGROUND_POSITION))
153
154
 
154
155
  @declarations.delete('background')
155
156
  end
156
157
 
158
+ def extract_background_size_from(value)
159
+ size = value.slice!(CssParser::RE_BACKGROUND_SIZE)
160
+
161
+ size.sub(/^\s*\/\s*/, '') if size
162
+ end
163
+
157
164
  # Split shorthand border declarations (e.g. <tt>border: 1px red;</tt>)
158
165
  # Additional splitting happens in expand_dimensions_shorthand!
159
166
  def expand_border_shorthand! # :nodoc:
@@ -327,6 +334,18 @@ module CssParser
327
334
  #
328
335
  # Leaves properties declared !important alone.
329
336
  def create_background_shorthand! # :nodoc:
337
+ # When we have a background-size property we must separate it and distinguish it from
338
+ # background-position by preceeding it with a backslash. In this case we also need to
339
+ # have a background-position property, so we set it if it's missing.
340
+ # http://www.w3schools.com/cssref/css3_pr_background.asp
341
+ if @declarations.has_key?('background-size') and not @declarations['background-size'][:is_important]
342
+ unless @declarations.has_key?('background-position')
343
+ @declarations['background-position'] = {value => 'initial'}
344
+ end
345
+
346
+ @declarations['background-size'][:value] = "/ #{@declarations['background-size'][:value]}"
347
+ end
348
+
330
349
  create_shorthand_properties! BACKGROUND_PROPERTIES, 'background'
331
350
  end
332
351
 
@@ -1,3 +1,3 @@
1
1
  module CssParser
2
- VERSION = "1.3.7".freeze
2
+ VERSION = "1.4.0".freeze
3
3
  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.3.7
4
+ version: 1.4.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: 2015-09-22 00:00:00.000000000 Z
11
+ date: 2016-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -55,7 +55,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
55
55
  version: '0'
56
56
  requirements: []
57
57
  rubyforge_project:
58
- rubygems_version: 2.2.2
58
+ rubygems_version: 2.4.5.1
59
59
  signing_key:
60
60
  specification_version: 4
61
61
  summary: Ruby CSS parser.