csspool 2.0.0 → 3.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.
Files changed (57) hide show
  1. data/.gemtest +0 -0
  2. data/CHANGELOG.rdoc +6 -0
  3. data/Manifest.txt +10 -14
  4. data/README.rdoc +8 -21
  5. data/Rakefile +36 -2
  6. data/lib/csspool/collection.rb +2 -2
  7. data/lib/csspool/css/charset.rb +8 -2
  8. data/lib/csspool/css/declaration.rb +13 -2
  9. data/lib/csspool/css/document_handler.rb +3 -3
  10. data/lib/csspool/css/import_rule.rb +15 -3
  11. data/lib/csspool/css/media.rb +8 -2
  12. data/lib/csspool/css/parser.rb +1090 -0
  13. data/lib/csspool/css/parser.y +347 -0
  14. data/lib/csspool/css/rule_set.rb +8 -3
  15. data/lib/csspool/css/tokenizer.rb +228 -0
  16. data/lib/csspool/css/tokenizer.rex +96 -0
  17. data/lib/csspool/css.rb +1 -0
  18. data/lib/csspool/node.rb +29 -1
  19. data/lib/csspool/sac/document.rb +3 -3
  20. data/lib/csspool/sac/parser.rb +6 -112
  21. data/lib/csspool/terms/function.rb +1 -1
  22. data/lib/csspool/terms/ident.rb +1 -1
  23. data/lib/csspool/terms/number.rb +1 -1
  24. data/lib/csspool/terms/rgb.rb +1 -4
  25. data/lib/csspool/terms/string.rb +1 -1
  26. data/lib/csspool/visitors/children.rb +50 -0
  27. data/lib/csspool/visitors/comparable.rb +9 -3
  28. data/lib/csspool/visitors/iterator.rb +80 -0
  29. data/lib/csspool/visitors/to_css.rb +61 -45
  30. data/lib/csspool/visitors.rb +2 -0
  31. data/lib/csspool.rb +6 -3
  32. data/test/css/test_parser.rb +412 -0
  33. data/test/css/test_tokenizer.rb +320 -0
  34. data/test/helper.rb +2 -2
  35. data/test/sac/test_parser.rb +3 -8
  36. data/test/sac/test_terms.rb +128 -34
  37. data/test/test_collection.rb +1 -1
  38. data/test/test_parser.rb +1 -1
  39. data/test/visitors/test_children.rb +20 -0
  40. data/test/visitors/test_comparable.rb +31 -1
  41. data/test/visitors/test_each.rb +19 -0
  42. data/test/visitors/test_to_css.rb +125 -1
  43. metadata +90 -68
  44. data/lib/csspool/lib_croco/cr_additional_sel.rb +0 -46
  45. data/lib/csspool/lib_croco/cr_attr_sel.rb +0 -16
  46. data/lib/csspool/lib_croco/cr_doc_handler.rb +0 -24
  47. data/lib/csspool/lib_croco/cr_num.rb +0 -13
  48. data/lib/csspool/lib_croco/cr_parser.rb +0 -11
  49. data/lib/csspool/lib_croco/cr_parsing_location.rb +0 -17
  50. data/lib/csspool/lib_croco/cr_pseudo.rb +0 -14
  51. data/lib/csspool/lib_croco/cr_rgb.rb +0 -18
  52. data/lib/csspool/lib_croco/cr_selector.rb +0 -34
  53. data/lib/csspool/lib_croco/cr_simple_sel.rb +0 -54
  54. data/lib/csspool/lib_croco/cr_term.rb +0 -97
  55. data/lib/csspool/lib_croco/glist.rb +0 -21
  56. data/lib/csspool/lib_croco.rb +0 -78
  57. data/lib/csspool/visitable.rb +0 -18
@@ -0,0 +1,19 @@
1
+ require 'helper'
2
+
3
+ module CSSPool
4
+ module Visitors
5
+ class TestEach < CSSPool::TestCase
6
+ def test_iterate
7
+ doc = CSSPool.CSS <<-eocss
8
+ @charset "UTF-8";
9
+ @import url("foo.css") screen;
10
+ div#a, a.foo, a:hover, a[href][int="10"]{ background: red; }
11
+ eocss
12
+ list = []
13
+ doc.each { |node| list << node }
14
+ assert_equal 20, list.length
15
+ assert list.hash
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  require 'helper'
2
3
 
3
4
  module CSSPool
@@ -11,10 +12,23 @@ module CSSPool
11
12
  doc = CSSPool.CSS(doc.to_css)
12
13
  assert_equal 3, doc.rule_sets.first.declarations[0].expressions.length
13
14
 
14
- assert_equal 'font: 14.0px / 30.0px Tahoma;',
15
+ assert_equal 'font: 14px / 30px Tahoma;',
15
16
  doc.rule_sets.first.declarations.first.to_css.strip
16
17
  end
17
18
 
19
+ # FIXME: this is a bug in libcroco
20
+ #def test_ident_followed_by_id
21
+ # doc = CSSPool.CSS 'p#div { font: foo, #666; }'
22
+ # assert_equal 'p#div', doc.rule_sets.first.selectors.first.to_css
23
+
24
+ # p doc.rule_sets.first.selectors
25
+
26
+ # doc = CSSPool.CSS 'p #div { font: foo, #666; }'
27
+
28
+ # p doc.rule_sets.first.selectors
29
+ # assert_equal 'p #div', doc.rule_sets.first.selectors.first.to_css
30
+ #end
31
+
18
32
  def test_hash_operator
19
33
  doc = CSSPool.CSS 'p { font: foo, #666; }'
20
34
  assert_equal 2, doc.rule_sets.first.declarations[0].expressions.length
@@ -136,6 +150,116 @@ module CSSPool
136
150
 
137
151
  assert_equal 1, doc.charsets.length
138
152
  end
153
+
154
+ def test_selector_attribute
155
+ input_output = {
156
+ "\"quotes\"" => "[title=\"\\\"quotes\\\"\"]",
157
+ }
158
+ input_output.each_pair do |input, output|
159
+ node = Selectors::Attribute.new 'title', input, Selectors::Attribute::EQUALS
160
+ assert_equal output, node.to_css
161
+ end
162
+
163
+ input_output = {
164
+ " space" => "[\\ space=\"value\"]",
165
+ "equal=" => "[equal\\==\"value\"]",
166
+ "new\nline" => "[new\\00000aline=\"value\"]"
167
+ }
168
+ input_output.each_pair do |input, output|
169
+ Selectors::Attribute.new input, 'value', Selectors::Attribute::EQUALS
170
+ end
171
+ end
172
+
173
+ def test_selector_psuedo
174
+ input_output = {
175
+ "pseudo" => ":pseudo",
176
+ "\"quotes\"" => ":\\000022quotes\\000022",
177
+ "paren(" => ":paren\\(",
178
+ }
179
+ input_output.each_pair do |input, output|
180
+ node = Selectors::PseudoClass.new input
181
+ assert_equal output, node.to_css
182
+ end
183
+
184
+ input_output = {
185
+ "" => ":psuedo()",
186
+ "ident" => ":psuedo(ident)",
187
+ " " => ":psuedo(\\ )",
188
+ "\"quote\"" => ":psuedo(\\000022quoted\\000022)"
189
+ }
190
+ input_output.each_pair do |input, output|
191
+ Selectors::Attribute.new input, 'value', Selectors::Attribute::EQUALS
192
+ end
193
+ end
194
+
195
+ def test_selector_other
196
+ input_output = {
197
+ "pseudo" => "pseudo",
198
+ "\"quotes\"" => "\\000022quotes\\000022",
199
+ "space " => "space\\ ",
200
+ "new\nline" => "new\\00000aline"
201
+ }
202
+ input_output.each_pair do |input, output|
203
+ node = Selectors::Type.new input
204
+ assert_equal "#{output}", node.to_css
205
+ end
206
+ input_output.each_pair do |input, output|
207
+ node = Selectors::Id.new input
208
+ assert_equal "##{output}", node.to_css
209
+ end
210
+ input_output.each_pair do |input, output|
211
+ node = Selectors::Class.new input
212
+ assert_equal ".#{output}", node.to_css
213
+ end
214
+ end
215
+
216
+ def test_property
217
+ input_output = {
218
+ "property" => " property: value;",
219
+ "colon:" => " colon\\:: value;",
220
+ "space " => " space\\ : value;"
221
+ }
222
+ input_output.each_pair do |input, output|
223
+ node = CSS::Declaration.new input, [Terms::Ident.new("value")], false, nil
224
+ assert_equal output, node.to_css
225
+ end
226
+ end
227
+
228
+ def test_function_term
229
+ input_output = {
230
+ "attr" => "attr(\"string\", ident)",
231
+ "0" => "\\000030(\"string\", ident)",
232
+ "a function" => "a\\ function(\"string\", ident)",
233
+ "a(" => "a\\((\"string\", ident)",
234
+ }
235
+ input_output.each_pair do |input, output|
236
+ node = Terms::Function.new input, [Terms::String.new("string"), Terms::Ident.new("ident", ',')]
237
+ assert_equal output, node.to_css
238
+ end
239
+ end
240
+
241
+ def test_uri_term
242
+ input_output = {
243
+ "http://example.com" => "url(\"http://example.com\")",
244
+ }
245
+ input_output.each_pair do |input, output|
246
+ node = Terms::URI.new input
247
+ assert_equal output, node.to_css
248
+ end
249
+ end
250
+
251
+ def test_string_term
252
+ input_output = {
253
+ "basic" => "\"basic\"",
254
+ "\"quotes\"" => "\"\\\"quotes\\\"\"",
255
+ "…" => "\"…\"",
256
+ "\n\r\f" => "\"\\a \\\r\\\f\""
257
+ }
258
+ input_output.each_pair do |input, output|
259
+ node = Terms::String.new input
260
+ assert_equal output, node.to_css
261
+ end
262
+ end
139
263
  end
140
264
  end
141
265
  end
metadata CHANGED
@@ -1,51 +1,75 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: csspool
3
- version: !ruby/object:Gem::Version
4
- version: 2.0.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 3.0.0
5
+ prerelease:
5
6
  platform: ruby
6
- authors:
7
+ authors:
7
8
  - Aaron Patterson
8
9
  - John Barnette
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
-
13
- date: 2009-07-07 00:00:00 -07:00
14
- default_executable:
15
- dependencies:
16
- - !ruby/object:Gem::Dependency
17
- name: ffi
18
- type: :runtime
19
- version_requirement:
20
- version_requirements: !ruby/object:Gem::Requirement
21
- requirements:
22
- - - ">="
23
- - !ruby/object:Gem::Version
24
- version: "0"
25
- version:
26
- - !ruby/object:Gem::Dependency
13
+ date: 2012-02-14 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: racc
17
+ requirement: &70169574084020 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: *70169574084020
26
+ - !ruby/object:Gem::Dependency
27
+ name: rexical
28
+ requirement: &70169574081520 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: *70169574081520
37
+ - !ruby/object:Gem::Dependency
38
+ name: rdoc
39
+ requirement: &70169574065400 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ version: '3.10'
45
+ type: :development
46
+ prerelease: false
47
+ version_requirements: *70169574065400
48
+ - !ruby/object:Gem::Dependency
27
49
  name: hoe
50
+ requirement: &70169574053500 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ version: '2.12'
28
56
  type: :development
29
- version_requirement:
30
- version_requirements: !ruby/object:Gem::Requirement
31
- requirements:
32
- - - ">="
33
- - !ruby/object:Gem::Version
34
- version: 2.3.2
35
- version:
36
- description: |-
37
- CSSPool is a CSS parser. CSSPool provides a SAC interface for parsing CSS as
38
- well as a document oriented interface for parsing CSS.
39
- email:
57
+ prerelease: false
58
+ version_requirements: *70169574053500
59
+ description: ! 'CSSPool is a CSS parser. CSSPool provides a SAC interface for parsing
60
+ CSS as
61
+
62
+ well as a document oriented interface for parsing CSS.'
63
+ email:
40
64
  - aaronp@rubyforge.org
41
- - jabarnette@rubyforge.org
65
+ - jbarnette@rubyforge.org
42
66
  executables: []
43
-
44
67
  extensions: []
45
-
46
- extra_rdoc_files:
68
+ extra_rdoc_files:
47
69
  - Manifest.txt
48
- files:
70
+ - CHANGELOG.rdoc
71
+ - README.rdoc
72
+ files:
49
73
  - .autotest
50
74
  - CHANGELOG.rdoc
51
75
  - Manifest.txt
@@ -60,20 +84,11 @@ files:
60
84
  - lib/csspool/css/document_handler.rb
61
85
  - lib/csspool/css/import_rule.rb
62
86
  - lib/csspool/css/media.rb
87
+ - lib/csspool/css/parser.rb
88
+ - lib/csspool/css/parser.y
63
89
  - lib/csspool/css/rule_set.rb
64
- - lib/csspool/lib_croco.rb
65
- - lib/csspool/lib_croco/cr_additional_sel.rb
66
- - lib/csspool/lib_croco/cr_attr_sel.rb
67
- - lib/csspool/lib_croco/cr_doc_handler.rb
68
- - lib/csspool/lib_croco/cr_num.rb
69
- - lib/csspool/lib_croco/cr_parser.rb
70
- - lib/csspool/lib_croco/cr_parsing_location.rb
71
- - lib/csspool/lib_croco/cr_pseudo.rb
72
- - lib/csspool/lib_croco/cr_rgb.rb
73
- - lib/csspool/lib_croco/cr_selector.rb
74
- - lib/csspool/lib_croco/cr_simple_sel.rb
75
- - lib/csspool/lib_croco/cr_term.rb
76
- - lib/csspool/lib_croco/glist.rb
90
+ - lib/csspool/css/tokenizer.rb
91
+ - lib/csspool/css/tokenizer.rex
77
92
  - lib/csspool/node.rb
78
93
  - lib/csspool/sac.rb
79
94
  - lib/csspool/sac/document.rb
@@ -96,13 +111,16 @@ files:
96
111
  - lib/csspool/terms/rgb.rb
97
112
  - lib/csspool/terms/string.rb
98
113
  - lib/csspool/terms/uri.rb
99
- - lib/csspool/visitable.rb
100
114
  - lib/csspool/visitors.rb
115
+ - lib/csspool/visitors/children.rb
101
116
  - lib/csspool/visitors/comparable.rb
117
+ - lib/csspool/visitors/iterator.rb
102
118
  - lib/csspool/visitors/to_css.rb
103
119
  - lib/csspool/visitors/visitor.rb
104
120
  - test/css/test_document.rb
105
121
  - test/css/test_import_rule.rb
122
+ - test/css/test_parser.rb
123
+ - test/css/test_tokenizer.rb
106
124
  - test/helper.rb
107
125
  - test/sac/test_parser.rb
108
126
  - test/sac/test_properties.rb
@@ -110,45 +128,49 @@ files:
110
128
  - test/test_collection.rb
111
129
  - test/test_parser.rb
112
130
  - test/test_selector.rb
131
+ - test/visitors/test_children.rb
113
132
  - test/visitors/test_comparable.rb
133
+ - test/visitors/test_each.rb
114
134
  - test/visitors/test_to_css.rb
115
- has_rdoc: true
135
+ - .gemtest
116
136
  homepage: http://csspool.rubyforge.org
117
137
  licenses: []
118
-
119
138
  post_install_message:
120
- rdoc_options:
139
+ rdoc_options:
121
140
  - --main
122
141
  - README.rdoc
123
- require_paths:
142
+ require_paths:
124
143
  - lib
125
- required_ruby_version: !ruby/object:Gem::Requirement
126
- requirements:
127
- - - ">="
128
- - !ruby/object:Gem::Version
129
- version: "0"
130
- version:
131
- required_rubygems_version: !ruby/object:Gem::Requirement
132
- requirements:
133
- - - ">="
134
- - !ruby/object:Gem::Version
135
- version: "0"
136
- version:
144
+ required_ruby_version: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ! '>='
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ required_rubygems_version: !ruby/object:Gem::Requirement
151
+ none: false
152
+ requirements:
153
+ - - ! '>='
154
+ - !ruby/object:Gem::Version
155
+ version: '0'
137
156
  requirements: []
138
-
139
157
  rubyforge_project: csspool
140
- rubygems_version: 1.3.4
158
+ rubygems_version: 1.8.11
141
159
  signing_key:
142
160
  specification_version: 3
143
161
  summary: CSSPool is a CSS parser
144
- test_files:
162
+ test_files:
145
163
  - test/css/test_document.rb
146
164
  - test/css/test_import_rule.rb
165
+ - test/css/test_parser.rb
166
+ - test/css/test_tokenizer.rb
147
167
  - test/sac/test_parser.rb
148
168
  - test/sac/test_properties.rb
149
169
  - test/sac/test_terms.rb
150
170
  - test/test_collection.rb
151
171
  - test/test_parser.rb
152
172
  - test/test_selector.rb
173
+ - test/visitors/test_children.rb
153
174
  - test/visitors/test_comparable.rb
175
+ - test/visitors/test_each.rb
154
176
  - test/visitors/test_to_css.rb
@@ -1,46 +0,0 @@
1
- module CSSPool
2
- module LibCroco
3
- class CRAdditionalSel < FFI::Struct
4
- layout(
5
- :sel_type, :int,
6
- :content, :pointer,
7
- :next, :pointer,
8
- :prev, :pointer,
9
- :line, :int,
10
- :column, :int,
11
- :byte_offset, :int
12
- )
13
-
14
- def to_additional_selector
15
- case self[:sel_type]
16
- when 1 # CLASS_ADD_SELECTOR
17
- CSSPool::Selectors::Class.new(
18
- LibCroco.cr_string_peek_raw_str(self[:content]).read_string
19
- )
20
- when 1 << 1 # PSEUDO_CLASS_ADD_SELECTOR
21
- pseudo = CRPseudo.new(self[:content])
22
- CSSPool::Selectors::PseudoClass.new(
23
- pseudo[:name].null? ? nil :
24
- LibCroco.cr_string_peek_raw_str(pseudo[:name]).read_string,
25
- pseudo[:extra].null? ? nil :
26
- LibCroco.cr_string_peek_raw_str(pseudo[:extra]).read_string
27
- )
28
- when 1 << 3 # ID_ADD_SELECTOR
29
- CSSPool::Selectors::Id.new(
30
- LibCroco.cr_string_peek_raw_str(self[:content]).read_string
31
- )
32
- when 1 << 4 # ATTRIBUTE_ADD_SELECTOR
33
- attr_sel = CRAttrSel.new(self[:content])
34
- raise "FIXME: additional add selectors" unless attr_sel[:next].null?
35
- CSSPool::Selectors::Attribute.new(
36
- attr_sel[:name].null? ? nil :
37
- LibCroco.cr_string_peek_raw_str(attr_sel[:name]).read_string,
38
- attr_sel[:value].null? ? nil :
39
- LibCroco.cr_string_peek_raw_str(attr_sel[:value]).read_string,
40
- attr_sel[:match_way]
41
- )
42
- end
43
- end
44
- end
45
- end
46
- end
@@ -1,16 +0,0 @@
1
- module CSSPool
2
- module LibCroco
3
- class CRAttrSel < FFI::Struct
4
- layout(
5
- :name, :pointer,
6
- :value, :pointer,
7
- :match_way, :int,
8
- :next, :pointer,
9
- :prev, :pointer,
10
- :line, :int,
11
- :column, :int,
12
- :byte_offset, :int
13
- )
14
- end
15
- end
16
- end
@@ -1,24 +0,0 @@
1
- module CSSPool
2
- module LibCroco
3
- class CRDocHandler < FFI::Struct
4
- layout(
5
- :priv, :pointer,
6
- :app_data, :pointer,
7
- :start_document, :start_document,
8
- :end_document, :end_document,
9
- :charset, :charset,
10
- :import_style, :import_style,
11
- :import_style_result, :import_style_result,
12
- :namespace_declaration, :namespace_declaration,
13
- :comment, :comment,
14
- :start_selector, :start_selector,
15
- :end_selector, :end_selector,
16
- :property, :property,
17
- :start_font_face, :start_font_face,
18
- :end_font_face, :end_font_face,
19
- :start_media, :start_media,
20
- :end_media, :end_media
21
- )
22
- end
23
- end
24
- end
@@ -1,13 +0,0 @@
1
- module CSSPool
2
- module LibCroco
3
- class CRNum < FFI::Struct
4
- layout(
5
- :type, :int,
6
- :value, :double,
7
- :line, :int,
8
- :column, :int,
9
- :byte_offset, :int
10
- )
11
- end
12
- end
13
- end
@@ -1,11 +0,0 @@
1
- module CSSPool
2
- module LibCroco
3
- class CRParser < FFI::Struct
4
- layout(:priv, :pointer)
5
-
6
- #def self.release pointer
7
- # CSSPool::LibCroco.cr_parser_destroy pointer
8
- #end
9
- end
10
- end
11
- end
@@ -1,17 +0,0 @@
1
- module CSSPool
2
- module LibCroco
3
- class CRParsingLocation < FFI::Struct
4
- layout(
5
- :line, :uint,
6
- :column, :uint,
7
- :byte_offset, :uint
8
- )
9
-
10
- def to_h
11
- Hash[*[:line, :column, :byte_offset].map { |k|
12
- [k, self[k]]
13
- }.flatten]
14
- end
15
- end
16
- end
17
- end
@@ -1,14 +0,0 @@
1
- module CSSPool
2
- module LibCroco
3
- class CRPseudo < FFI::Struct
4
- layout(
5
- :pseudo_type, :int,
6
- :name, :pointer,
7
- :extra, :pointer,
8
- :line, :int,
9
- :column, :int,
10
- :byte_offset, :int
11
- )
12
- end
13
- end
14
- end
@@ -1,18 +0,0 @@
1
- module CSSPool
2
- module LibCroco
3
- class CRRgb < FFI::Struct
4
- layout(
5
- :name, :string,
6
- :red, :long,
7
- :green, :long,
8
- :blue, :long,
9
- :is_percentage, :int,
10
- :inherit, :int,
11
- :is_transparent,:int,
12
- :line, :int,
13
- :column, :int,
14
- :byte_offset, :int
15
- )
16
- end
17
- end
18
- end
@@ -1,34 +0,0 @@
1
- module CSSPool
2
- module LibCroco
3
- class CRSelector < FFI::Struct
4
- layout(
5
- :simple_sel, :pointer,
6
- :next, :pointer,
7
- :prev, :pointer,
8
- :line, :int,
9
- :column, :int,
10
- :byte_offset, :int,
11
- :ref_count, :long
12
- )
13
-
14
- def to_selector
15
- simple_selectors = []
16
- pointer = self[:simple_sel]
17
-
18
- until pointer.null?
19
- LibCroco.cr_simple_sel_compute_specificity(pointer)
20
- simple_selectors << CRSimpleSel.new(pointer)
21
- pointer = simple_selectors.last[:next]
22
- end
23
-
24
- simple_selectors = simple_selectors.map { |sel| sel.to_simple_selector }
25
-
26
- Selector.new simple_selectors, {
27
- :line => self[:line],
28
- :column => self[:column],
29
- :byte_offset => self[:byte_offset]
30
- }
31
- end
32
- end
33
- end
34
- end
@@ -1,54 +0,0 @@
1
- module CSSPool
2
- module LibCroco
3
- class CRSimpleSel < FFI::Struct
4
- layout(
5
- :type_mask, :int,
6
- :case_sensitive, :int,
7
- :name, :pointer,
8
- :combinator, :int,
9
- :add_sel, :pointer,
10
- :specificity, :ulong,
11
- :next, :pointer,
12
- :prev, :pointer,
13
- :line, :int,
14
- :column, :int,
15
- :byte_offset, :int
16
- )
17
-
18
- def to_simple_selector
19
- klass = CSSPool::Selectors::Simple
20
-
21
- case self[:type_mask]
22
- when 1 # UNIVERSAL_SELECTOR
23
- klass = CSSPool::Selectors::Universal
24
- when 1 << 1 # TYPE_SELECTOR
25
- klass = CSSPool::Selectors::Type
26
- end
27
-
28
- simple_sel = klass.new(
29
- self[:name].null? ? nil :
30
- LibCroco.cr_string_peek_raw_str(self[:name]).read_string,
31
- self[:combinator]
32
- )
33
- simple_sel.parse_location = {
34
- :line => self[:line],
35
- :column => self[:column],
36
- :byte_offset => self[:byte_offset]
37
- }
38
-
39
- additional_selectors = []
40
- pointer = self[:add_sel]
41
- until pointer.null?
42
- additional_selectors << CRAdditionalSel.new(pointer)
43
- pointer = additional_selectors.last[:next]
44
- end
45
-
46
- simple_sel.additional_selectors = additional_selectors.map { |as|
47
- as.to_additional_selector
48
- }
49
-
50
- simple_sel
51
- end
52
- end
53
- end
54
- end