csspool 4.0.3 → 4.0.4

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.
@@ -20,6 +20,7 @@ token VARIABLE_NAME
20
20
  token CALC_SYM
21
21
  token FONTFACE_SYM
22
22
  token UNICODE_RANGE
23
+ token RATIO
23
24
 
24
25
  rule
25
26
  document
@@ -552,6 +553,7 @@ rule
552
553
  ;
553
554
  term
554
555
  : ident
556
+ | ratio
555
557
  | numeric
556
558
  | string
557
559
  | uri
@@ -650,6 +652,11 @@ rule
650
652
  result = Terms::Number.new numeric(val.first), nil, unit
651
653
  }
652
654
  ;
655
+ ratio
656
+ : RATIO {
657
+ result = Terms::Ratio.new(val[0], val[1])
658
+ }
659
+ ;
653
660
  unary_operator
654
661
  : MINUS { result = :minus }
655
662
  | PLUS { result = :plus }
@@ -208,6 +208,9 @@ class Tokenizer < Parser
208
208
  when (text = @ss.scan(/[\s]*([0-9]*\.[0-9]+|[0-9]+)%[\s]*/i))
209
209
  action { [:PERCENTAGE, st(text)] }
210
210
 
211
+ when (text = @ss.scan(/[\s]*[1-9][0-9]*[\s]*\/[\s]*[1-9][0-9]*[\s]*/i))
212
+ action { [:RATIO, st(text)] }
213
+
211
214
  when (text = @ss.scan(/[\s]*([0-9]*\.[0-9]+|[0-9]+)[\s]*/i))
212
215
  action { [:NUMBER, st(text)] }
213
216
 
@@ -278,6 +281,9 @@ class Tokenizer < Parser
278
281
  when (text = @ss.scan(/[\s]*([0-9]*\.[0-9]+|[0-9]+)%[\s]*/i))
279
282
  action { [:PERCENTAGE, st(text)] }
280
283
 
284
+ when (text = @ss.scan(/[\s]*[1-9][0-9]*[\s]*\/[\s]*[1-9][0-9]*[\s]*/i))
285
+ action { [:RATIO, st(text)] }
286
+
281
287
  when (text = @ss.scan(/[\s]*([0-9]*\.[0-9]+|[0-9]+)[\s]*/i))
282
288
  action { [:NUMBER, st(text)] }
283
289
 
@@ -7,8 +7,11 @@ macro
7
7
  w [\s]*
8
8
  nonascii [^\0-\177]
9
9
  num ([0-9]*\.[0-9]+|[0-9]+)
10
+ positiveint [1-9][0-9]*
10
11
  length {num}(px|cm|mm|in|pt|pc|mozmm|em|ex|ch|rem|vh|vw|vmin|vmax)
11
12
  percentage {num}%
13
+ # http://dev.w3.org/csswg/mediaqueries-3/#values
14
+ ratio {positiveint}{w}\/{w}{positiveint}
12
15
  unicode \\[0-9A-Fa-f]{1,6}(\r\n|[\s])?
13
16
  nth ([\+\-]?[0-9]*n({w}[\+\-]{w}[0-9]+)?|[\+\-]?[0-9]+|odd|even)
14
17
  vendorprefix \-[A-Za-z]+\-
@@ -44,6 +47,7 @@ rule
44
47
  :LOGICQUERY {w}{num}(ms|s){w} { [:TIME, st(text)] }
45
48
  :LOGICQUERY {w}{num}[k]?hz{w} { [:FREQ, st(text)] }
46
49
  :LOGICQUERY {w}{percentage}{w} { [:PERCENTAGE, st(text)] }
50
+ :LOGICQUERY {w}{ratio}{w} { [:RATIO, st(text)] }
47
51
  :LOGICQUERY {w}{num}{w} { [:NUMBER, st(text)] }
48
52
  :LOGICQUERY {ident} { [:IDENT, st(text)] }
49
53
  :LOGICQUERY {w},{w} { [:COMMA, st(',')] }
@@ -120,6 +124,7 @@ rule
120
124
  {w}{num}[k]?hz{w} { [:FREQ, st(text)] }
121
125
 
122
126
  {w}{percentage}{w} { [:PERCENTAGE, st(text)] }
127
+ {w}{ratio}{w} { [:RATIO, st(text)] }
123
128
  {w}{num}{w} { [:NUMBER, st(text)] }
124
129
  {w}\/\/{w} { [:DOUBLESLASH, st(text)] }
125
130
  {w}\/{w} { [:SLASH, st('/')] }
data/lib/csspool/terms.rb CHANGED
@@ -6,4 +6,5 @@ require 'csspool/terms/uri'
6
6
  require 'csspool/terms/rgb'
7
7
  require 'csspool/terms/hash'
8
8
  require 'csspool/terms/math'
9
+ require 'csspool/terms/ratio'
9
10
  require 'csspool/terms/resolution'
@@ -87,6 +87,20 @@ module CSSPool
87
87
  eocss
88
88
  end
89
89
 
90
+ def test_ratio
91
+ CSSPool.CSS <<-eocss
92
+ @media all and (min-aspect-ratio: 4/3) {
93
+ }
94
+ eocss
95
+ end
96
+
97
+ def test_ratio_with_spaces
98
+ CSSPool.CSS <<-eocss
99
+ @media all and (min-aspect-ratio: 4 / 3) {
100
+ }
101
+ eocss
102
+ end
103
+
90
104
  end
91
105
  end
92
106
  end
data/test/helper.rb CHANGED
@@ -1,8 +1,8 @@
1
- require "test/unit"
1
+ require "minitest/unit"
2
2
  require "csspool"
3
3
 
4
4
  module CSSPool
5
- class TestCase < Test::Unit::TestCase
5
+ class TestCase < Minitest::Test
6
6
  unless RUBY_VERSION >= '1.9'
7
7
  undef :default_test
8
8
  end
@@ -26,7 +26,7 @@ module CSSPool
26
26
 
27
27
  def test_not_equal
28
28
  doc1 = CSSPool.CSS 'div { border: foo(1, 2); }'
29
- assert_not_equal nil, doc1
29
+ assert nil != doc1
30
30
  end
31
31
 
32
32
  def test_hash_range
metadata CHANGED
@@ -1,15 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: csspool
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.3
4
+ version: 4.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Patterson
8
8
  - John Barnette
9
+ - Jason Barnabe
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2014-12-23 00:00:00.000000000 Z
13
+ date: 2015-05-30 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: rdoc
@@ -17,14 +18,14 @@ dependencies:
17
18
  requirements:
18
19
  - - "~>"
19
20
  - !ruby/object:Gem::Version
20
- version: '3.10'
21
+ version: '4.0'
21
22
  type: :development
22
23
  prerelease: false
23
24
  version_requirements: !ruby/object:Gem::Requirement
24
25
  requirements:
25
26
  - - "~>"
26
27
  - !ruby/object:Gem::Version
27
- version: '3.10'
28
+ version: '4.0'
28
29
  - !ruby/object:Gem::Dependency
29
30
  name: racc
30
31
  requirement: !ruby/object:Gem::Requirement
@@ -95,32 +96,45 @@ dependencies:
95
96
  - - ">="
96
97
  - !ruby/object:Gem::Version
97
98
  version: '0'
99
+ - !ruby/object:Gem::Dependency
100
+ name: minitest
101
+ requirement: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ type: :development
107
+ prerelease: false
108
+ version_requirements: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
98
113
  - !ruby/object:Gem::Dependency
99
114
  name: hoe
100
115
  requirement: !ruby/object:Gem::Requirement
101
116
  requirements:
102
117
  - - "~>"
103
118
  - !ruby/object:Gem::Version
104
- version: '3.4'
119
+ version: '3.13'
105
120
  type: :development
106
121
  prerelease: false
107
122
  version_requirements: !ruby/object:Gem::Requirement
108
123
  requirements:
109
124
  - - "~>"
110
125
  - !ruby/object:Gem::Version
111
- version: '3.4'
112
- description: |-
113
- CSSPool is a CSS parser. CSSPool provides a SAC interface for parsing CSS as
114
- well as a document oriented interface for parsing CSS.
126
+ version: '3.13'
127
+ description: ''
115
128
  email:
116
129
  - aaronp@rubyforge.org
117
130
  - jbarnette@rubyforge.org
131
+ - jason.barnabe@gmail.com
118
132
  executables: []
119
133
  extensions: []
120
134
  extra_rdoc_files:
121
135
  - CHANGELOG.rdoc
122
136
  - Manifest.txt
123
- - README.rdoc
137
+ - README.md
124
138
  files:
125
139
  - ".autotest"
126
140
  - ".gemtest"
@@ -128,7 +142,7 @@ files:
128
142
  - Gemfile
129
143
  - Gemfile.lock
130
144
  - Manifest.txt
131
- - README.rdoc
145
+ - README.md
132
146
  - Rakefile
133
147
  - lib/csspool.rb
134
148
  - lib/csspool/collection.rb
@@ -192,11 +206,9 @@ files:
192
206
  - test/css/test_keyframes_rule.rb
193
207
  - test/css/test_media_rule.rb
194
208
  - test/css/test_namespace_rule.rb
195
- - test/css/test_node_position.rb
196
209
  - test/css/test_parser.rb
197
210
  - test/css/test_supports_rule.rb
198
211
  - test/css/test_tokenizer.rb
199
- - test/css/test_variables.rb
200
212
  - test/files/test.css
201
213
  - test/helper.rb
202
214
  - test/sac/test_parser.rb
@@ -211,14 +223,14 @@ files:
211
223
  - test/visitors/test_comparable.rb
212
224
  - test/visitors/test_each.rb
213
225
  - test/visitors/test_to_css.rb
214
- homepage: http://csspool.rubyforge.org
226
+ homepage: https://github.com/sparklemotion/csspool/
215
227
  licenses:
216
228
  - MIT
217
229
  metadata: {}
218
230
  post_install_message:
219
231
  rdoc_options:
220
232
  - "--main"
221
- - README.rdoc
233
+ - README.md
222
234
  require_paths:
223
235
  - lib
224
236
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -232,33 +244,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
232
244
  - !ruby/object:Gem::Version
233
245
  version: '0'
234
246
  requirements: []
235
- rubyforge_project: csspool
236
- rubygems_version: 2.4.2
247
+ rubyforge_project:
248
+ rubygems_version: 2.4.6
237
249
  signing_key:
238
250
  specification_version: 4
239
- summary: CSSPool is a CSS parser
240
- test_files:
241
- - test/test_selector.rb
242
- - test/test_collection.rb
243
- - test/test_term.rb
244
- - test/test_parser.rb
245
- - test/sac/test_properties.rb
246
- - test/sac/test_parser.rb
247
- - test/sac/test_terms.rb
248
- - test/test_declaration.rb
249
- - test/css/test_import_rule.rb
250
- - test/css/test_document.rb
251
- - test/css/test_parser.rb
252
- - test/css/test_font_face.rb
253
- - test/css/test_variables.rb
254
- - test/css/test_media_rule.rb
255
- - test/css/test_namespace_rule.rb
256
- - test/css/test_keyframes_rule.rb
257
- - test/css/test_document_query.rb
258
- - test/css/test_supports_rule.rb
259
- - test/css/test_tokenizer.rb
260
- - test/css/test_node_position.rb
261
- - test/visitors/test_comparable.rb
262
- - test/visitors/test_each.rb
263
- - test/visitors/test_children.rb
264
- - test/visitors/test_to_css.rb
251
+ summary: ''
252
+ test_files: []
@@ -1,81 +0,0 @@
1
- require 'helper'
2
-
3
- module CSSPool
4
- module CSS
5
- class TestNodePosition < CSSPool::TestCase
6
-
7
- def test_no_whitespace
8
- child_content = '* { color: blue !important }'
9
- css = "@document url(\"http://www.example.com\") {#{child_content}}"
10
- doc = CSSPool.CSS css
11
- assert_equal 1, doc.document_queries.size
12
- dq = doc.document_queries.first
13
- assert !dq.outer_start_pos.nil?
14
- assert !dq.inner_start_pos.nil?
15
- assert !dq.inner_end_pos.nil?
16
- assert !dq.outer_end_pos.nil?
17
- assert_equal css, css[dq.outer_start_pos..dq.outer_end_pos-1]
18
- assert_equal child_content, css[dq.inner_start_pos..dq.inner_end_pos-1]
19
- end
20
-
21
- def test_whitespace
22
- child_content = '
23
- * { color: blue !important }
24
- '
25
- css = "
26
- @document url(\"http://www.example.com\") {#{child_content}}
27
- "
28
- doc = CSSPool.CSS css
29
- assert_equal 1, doc.document_queries.size
30
- dq = doc.document_queries.first
31
- assert !dq.outer_start_pos.nil?
32
- assert !dq.inner_start_pos.nil?
33
- assert !dq.inner_end_pos.nil?
34
- assert !dq.outer_end_pos.nil?
35
- # the whitespace on the "outside" should not be included
36
- assert_equal css.strip, css[dq.outer_start_pos..dq.outer_end_pos-1]
37
- # the whitespace on the "inside" should be retained
38
- assert_equal child_content, css[dq.inner_start_pos..dq.inner_end_pos-1]
39
- end
40
-
41
- def test_comments
42
- child_content = ' /* comment two */
43
- * { color: blue !important }
44
- /* comment three */
45
- '
46
- css = " /* comment one */
47
- @document url(\"http://www.example.com\") {#{child_content}}
48
- /* comment four */
49
- "
50
- doc = CSSPool.CSS css
51
- assert_equal 1, doc.document_queries.size
52
- dq = doc.document_queries.first
53
- assert !dq.outer_start_pos.nil?
54
- assert !dq.inner_start_pos.nil?
55
- assert !dq.inner_end_pos.nil?
56
- assert !dq.outer_end_pos.nil?
57
- # the comments and whitespace to the "outside" should not be retained
58
- assert_equal css.sub('/* comment one */', '').sub('/* comment four */', '').strip, css[dq.outer_start_pos..dq.outer_end_pos-1]
59
- # the comments and whitespace on the "inside" should be retained
60
- assert_equal child_content, css[dq.inner_start_pos..dq.inner_end_pos-1]
61
- end
62
-
63
- # this only works in ruby 2+
64
- def test_multibyte_characters
65
- child_content = '/* â */ * { color: blue !important }'
66
- css = "@document url(\"http://www.example.com\") {#{child_content}}"
67
- doc = CSSPool.CSS css
68
- assert_equal 1, doc.document_queries.size
69
- dq = doc.document_queries.first
70
- assert !dq.outer_start_pos.nil?
71
- assert !dq.inner_start_pos.nil?
72
- assert !dq.inner_end_pos.nil?
73
- assert !dq.outer_end_pos.nil?
74
- assert_equal css, css[dq.outer_start_pos..dq.outer_end_pos-1]
75
- assert_equal child_content, css[dq.inner_start_pos..dq.inner_end_pos-1]
76
- end
77
-
78
- end
79
- end
80
- end
81
-
@@ -1,33 +0,0 @@
1
- require 'helper'
2
-
3
- # CSS variables - http://dev.w3.org/csswg/css-variables/
4
- module CSSPool
5
- module CSS
6
- class TestVariables < CSSPool::TestCase
7
-
8
- # just checking that there's no parse error
9
- def test_basic
10
- doc = CSSPool.CSS <<-eocss
11
- :root {
12
- --main-bg-color: brown;
13
- }
14
- .one {
15
- background-color: var(--main-bg-color);
16
- }
17
- eocss
18
- end
19
-
20
- def test_var_in_calc
21
- doc = CSSPool.CSS <<-eocss
22
- :root {
23
- --right-margin: 10px;
24
- }
25
- .one {
26
- width: calc(100% + var(--right-margin));
27
- }
28
- eocss
29
- end
30
-
31
- end
32
- end
33
- end