csspool 0.2.6 → 2.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 (138) hide show
  1. data/.autotest +16 -0
  2. data/{CHANGELOG.txt → CHANGELOG.rdoc} +10 -0
  3. data/Manifest.txt +60 -72
  4. data/README.rdoc +78 -0
  5. data/Rakefile +9 -52
  6. data/lib/csspool/collection.rb +50 -0
  7. data/lib/csspool/css/charset.rb +7 -0
  8. data/lib/csspool/css/declaration.rb +8 -0
  9. data/lib/csspool/css/document.rb +34 -0
  10. data/lib/csspool/css/document_handler.rb +51 -0
  11. data/lib/csspool/css/import_rule.rb +15 -0
  12. data/lib/csspool/css/media.rb +7 -0
  13. data/lib/csspool/css/rule_set.rb +12 -0
  14. data/lib/csspool/css.rb +7 -0
  15. data/lib/csspool/lib_croco/cr_additional_sel.rb +46 -0
  16. data/lib/csspool/lib_croco/cr_attr_sel.rb +16 -0
  17. data/lib/csspool/lib_croco/cr_doc_handler.rb +24 -0
  18. data/lib/csspool/lib_croco/cr_num.rb +13 -0
  19. data/lib/csspool/lib_croco/cr_parser.rb +11 -0
  20. data/lib/csspool/lib_croco/cr_parsing_location.rb +17 -0
  21. data/lib/csspool/lib_croco/cr_pseudo.rb +14 -0
  22. data/lib/csspool/lib_croco/cr_rgb.rb +18 -0
  23. data/lib/csspool/lib_croco/cr_selector.rb +34 -0
  24. data/lib/csspool/lib_croco/cr_simple_sel.rb +54 -0
  25. data/lib/csspool/lib_croco/cr_term.rb +97 -0
  26. data/lib/csspool/lib_croco/glist.rb +21 -0
  27. data/lib/csspool/lib_croco.rb +78 -0
  28. data/lib/csspool/node.rb +5 -0
  29. data/lib/csspool/sac/document.rb +35 -0
  30. data/lib/csspool/sac/parser.rb +122 -0
  31. data/lib/csspool/sac.rb +2 -0
  32. data/lib/csspool/selector.rb +32 -0
  33. data/lib/csspool/selectors/additional.rb +6 -0
  34. data/lib/csspool/selectors/attribute.rb +21 -0
  35. data/lib/csspool/selectors/class.rb +11 -0
  36. data/lib/csspool/selectors/id.rb +11 -0
  37. data/lib/csspool/selectors/pseudo_class.rb +13 -0
  38. data/lib/csspool/selectors/simple.rb +22 -0
  39. data/lib/csspool/selectors/type.rb +6 -0
  40. data/lib/csspool/selectors/universal.rb +6 -0
  41. data/lib/csspool/selectors.rb +8 -0
  42. data/lib/csspool/terms/function.rb +17 -0
  43. data/lib/csspool/terms/hash.rb +6 -0
  44. data/lib/csspool/terms/ident.rb +15 -0
  45. data/lib/csspool/terms/number.rb +14 -0
  46. data/lib/csspool/terms/rgb.rb +23 -0
  47. data/lib/csspool/terms/string.rb +6 -0
  48. data/lib/csspool/terms/uri.rb +6 -0
  49. data/lib/csspool/terms.rb +7 -0
  50. data/lib/csspool/visitable.rb +18 -0
  51. data/lib/csspool/visitors/comparable.rb +78 -0
  52. data/lib/csspool/visitors/to_css.rb +201 -0
  53. data/lib/csspool/visitors/visitor.rb +17 -0
  54. data/lib/csspool/visitors.rb +3 -0
  55. data/lib/csspool.rb +18 -1
  56. data/test/css/test_document.rb +13 -0
  57. data/test/css/test_import_rule.rb +42 -0
  58. data/test/helper.rb +62 -6
  59. data/test/sac/test_parser.rb +115 -0
  60. data/test/sac/test_properties.rb +43 -0
  61. data/test/sac/test_terms.rb +134 -0
  62. data/test/test_collection.rb +81 -0
  63. data/test/test_parser.rb +75 -241
  64. data/test/test_selector.rb +45 -34
  65. data/test/visitors/test_comparable.rb +72 -0
  66. data/test/visitors/test_to_css.rb +141 -0
  67. metadata +98 -85
  68. data/README.txt +0 -79
  69. data/lib/css/sac/conditions/attribute_condition.rb +0 -56
  70. data/lib/css/sac/conditions/begin_hyphen_condition.rb +0 -22
  71. data/lib/css/sac/conditions/class_condition.rb +0 -22
  72. data/lib/css/sac/conditions/combinator_condition.rb +0 -40
  73. data/lib/css/sac/conditions/condition.rb +0 -35
  74. data/lib/css/sac/conditions/id_condition.rb +0 -27
  75. data/lib/css/sac/conditions/one_of_condition.rb +0 -22
  76. data/lib/css/sac/conditions/pseudo_class_condition.rb +0 -24
  77. data/lib/css/sac/conditions.rb +0 -5
  78. data/lib/css/sac/document_handler.rb +0 -67
  79. data/lib/css/sac/error_handler.rb +0 -14
  80. data/lib/css/sac/generated_parser.rb +0 -999
  81. data/lib/css/sac/generated_property_parser.rb +0 -9214
  82. data/lib/css/sac/lexeme.rb +0 -29
  83. data/lib/css/sac/lexical_unit.rb +0 -203
  84. data/lib/css/sac/parse_exception.rb +0 -6
  85. data/lib/css/sac/parser.rb +0 -115
  86. data/lib/css/sac/property_parser.rb +0 -47
  87. data/lib/css/sac/selectors/child_selector.rb +0 -40
  88. data/lib/css/sac/selectors/conditional_selector.rb +0 -49
  89. data/lib/css/sac/selectors/descendant_selector.rb +0 -40
  90. data/lib/css/sac/selectors/element_selector.rb +0 -39
  91. data/lib/css/sac/selectors/selector.rb +0 -31
  92. data/lib/css/sac/selectors/sibling_selector.rb +0 -39
  93. data/lib/css/sac/selectors/simple_selector.rb +0 -25
  94. data/lib/css/sac/selectors.rb +0 -5
  95. data/lib/css/sac/token.rb +0 -27
  96. data/lib/css/sac/tokenizer.rb +0 -187
  97. data/lib/css/sac/visitable.rb +0 -106
  98. data/lib/css/sac.rb +0 -14
  99. data/lib/css/stylesheet/rule.rb +0 -20
  100. data/lib/css/stylesheet/stylesheet.rb +0 -96
  101. data/lib/css/stylesheet.rb +0 -3
  102. data/lib/parser.y +0 -308
  103. data/lib/property_parser.y +0 -2346
  104. data/lib/property_parser.y.erb +0 -1321
  105. data/test/condition_test_case.rb +0 -6
  106. data/test/selector_test_case.rb +0 -20
  107. data/test/test_all.rb +0 -4
  108. data/test/test_attribute_condition.rb +0 -39
  109. data/test/test_begin_hyphen_condition.rb +0 -15
  110. data/test/test_child_selector.rb +0 -60
  111. data/test/test_class_condition.rb +0 -15
  112. data/test/test_combinator_condition.rb +0 -38
  113. data/test/test_condition.rb +0 -31
  114. data/test/test_conditional_selector.rb +0 -44
  115. data/test/test_descendant_selector.rb +0 -64
  116. data/test/test_element_selector.rb +0 -31
  117. data/test/test_error_recovery.rb +0 -28
  118. data/test/test_id_condition.rb +0 -16
  119. data/test/test_lexeme.rb +0 -39
  120. data/test/test_lexical_color.rb +0 -49
  121. data/test/test_lexical_function.rb +0 -31
  122. data/test/test_lexical_ident.rb +0 -30
  123. data/test/test_lexical_number.rb +0 -68
  124. data/test/test_lexical_string.rb +0 -23
  125. data/test/test_lexical_unit.rb +0 -106
  126. data/test/test_lexical_uri.rb +0 -28
  127. data/test/test_one_of_condition.rb +0 -15
  128. data/test/test_parse_error.rb +0 -199
  129. data/test/test_property_parser.rb +0 -593
  130. data/test/test_selector_as_string.rb +0 -94
  131. data/test/test_selector_parser.rb +0 -178
  132. data/test/test_sibling_selector.rb +0 -42
  133. data/test/test_simple_selector.rb +0 -9
  134. data/test/test_specificity.rb +0 -76
  135. data/test/test_stylesheet.rb +0 -95
  136. data/test/test_token.rb +0 -24
  137. data/test/test_tokenizer.rb +0 -127
  138. data/test/test_xpath.rb +0 -105
@@ -1,106 +0,0 @@
1
- require File.dirname(__FILE__) + "/helper"
2
-
3
- class LexicalUnitTest < Test::Unit::TestCase
4
- include CSS::SAC
5
-
6
- def setup
7
- @sac = CSS::SAC::Parser.new()
8
- end
9
-
10
- def test_invalid_property
11
- flexmock(@sac.document_handler).
12
- should_receive(:property).never
13
-
14
- @sac.parse('h1 { background-color: lakdjsfhlakdhjsf; }')
15
- flexmock_verify
16
- end
17
-
18
- def test_equals2
19
- first = LexicalUnit.new
20
- second = LexicalUnit.new
21
- assert_equal(first, second)
22
- second.lexical_unit_type = 'asdfadsf'
23
- assert_not_equal(first, second)
24
- end
25
-
26
- def test_color
27
- flexmock(@sac.document_handler).
28
- should_receive(:property).with('background-color', on { |list|
29
- list.length == 1 && list.first.dimension_unit_text.nil? &&
30
- list.first.lexical_unit_type == :SAC_RGBCOLOR &&
31
- list.first.string_value == "#345" &&
32
- list.first.parameters.length == 3 &&
33
- list.first.parameters.map { |x| x.integer_value } == [51,68,85] &&
34
- list.first.integer_value.nil?
35
- }, false).once
36
-
37
- @sac.parse('h1 { background-color: #345; }')
38
- flexmock_verify
39
- end
40
-
41
- def test_color_6
42
- flexmock(@sac.document_handler).
43
- should_receive(:property).with('background-color', on { |list|
44
- list.length == 1 && list.first.dimension_unit_text.nil? &&
45
- list.first.lexical_unit_type == :SAC_RGBCOLOR &&
46
- list.first.string_value == "#330405" &&
47
- list.first.parameters.length == 3 &&
48
- list.first.parameters.map { |x| x.integer_value } == [51,4,5] &&
49
- list.first.integer_value.nil?
50
- }, false).once
51
-
52
- @sac.parse('h1 { background-color: #330405; }')
53
- flexmock_verify
54
- end
55
-
56
- def test_uri
57
- flexmock(@sac.document_handler).
58
- should_receive(:property).with('content', on { |list|
59
- list.length == 1 && list.first.dimension_unit_text.nil? &&
60
- list.first.lexical_unit_type == :SAC_URI &&
61
- list.first.string_value == "\"aaron\"" &&
62
- list.first.integer_value.nil?
63
- }, false).once
64
-
65
- @sac.parse('h1 { content: url("aaron"); }')
66
- flexmock_verify
67
- end
68
-
69
- def test_string
70
- flexmock(@sac.document_handler).
71
- should_receive(:property).with('content', on { |list|
72
- list.length == 1 && list.first.dimension_unit_text.nil? &&
73
- list.first.lexical_unit_type == :SAC_STRING_VALUE &&
74
- list.first.string_value == "\"aaron\"" &&
75
- list.first.integer_value.nil?
76
- }, false).once
77
-
78
- @sac.parse('h1 { content: "aaron"; }')
79
- flexmock_verify
80
- end
81
-
82
- def test_ident
83
- flexmock(@sac.document_handler).
84
- should_receive(:property).with('color', on { |list|
85
- list.length == 1 && list.first.dimension_unit_text.nil? &&
86
- list.first.lexical_unit_type == :SAC_IDENT &&
87
- list.first.string_value == "black" &&
88
- list.first.integer_value.nil?
89
- }, false).once
90
-
91
- @sac.parse('h1 { color: black; }')
92
- flexmock_verify
93
- end
94
-
95
- def test_mm
96
- flexmock(@sac.document_handler).
97
- should_receive(:property).with('height', on { |list|
98
- list.length == 1 && list.first.dimension_unit_text == 'mm' &&
99
- list.first.lexical_unit_type == :SAC_MILLIMETER &&
100
- list.first.integer_value == 1
101
- }, false).once
102
-
103
- @sac.parse('h1 { height: 1mm; }')
104
- flexmock_verify
105
- end
106
- end
@@ -1,28 +0,0 @@
1
- require File.dirname(__FILE__) + "/helper"
2
-
3
- class LexicalURITest < Test::Unit::TestCase
4
- include CSS::SAC
5
-
6
- def test_to_s
7
- first = LexicalURI.new('url(http://tenderlovemaking.com/)')
8
- assert_equal('url(http://tenderlovemaking.com/)', first.to_s)
9
- end
10
-
11
- def test_hash
12
- first = LexicalURI.new('url(http://tenderlovemaking.com/)')
13
- second = LexicalURI.new('url(http://tenderlovemaking.com/)')
14
- assert_equal first.hash, second.hash
15
-
16
- third = LexicalURI.new('url(http://www.tenderlovemaking.com/)')
17
- assert_not_equal first.hash, third.hash
18
- end
19
-
20
- def test_equals2
21
- first = LexicalURI.new('url(http://tenderlovemaking.com/)')
22
- second = LexicalURI.new('url(http://tenderlovemaking.com/)')
23
- assert_equal first, second
24
-
25
- third = LexicalURI.new('url(http://www.tenderlovemaking.com/)')
26
- assert_not_equal first, third
27
- end
28
- end
@@ -1,15 +0,0 @@
1
- require File.dirname(__FILE__) + "/helper"
2
-
3
- class OneOfConditionTest < ConditionTestCase
4
- def test_equals_tilde
5
- attribute = OneOfCondition.new('class', 'foo')
6
- node = Node.new('p')
7
- node.attributes = { 'class' => 'aaron foo' }
8
-
9
- assert attribute =~ node
10
-
11
- node.attributes = { 'class' => 'bar' }
12
- assert(!(attribute =~ node))
13
- assert(!(attribute =~ 1))
14
- end
15
- end
@@ -1,199 +0,0 @@
1
- require File.dirname(__FILE__) + "/helper"
2
-
3
- class ParseErrorTest < Test::Unit::TestCase
4
- def setup
5
- @sac = CSS::SAC::Parser.new()
6
- end
7
-
8
- def test_unknown_properties
9
- flexmock(@sac.document_handler).
10
- should_receive(:start_document).ordered.once
11
- flexmock(@sac.document_handler).
12
- should_receive(:property).ordered.with('color', on { |list|
13
- list.length == 1 && list.first.dimension_unit_text.nil? &&
14
- list.first.lexical_unit_type == :SAC_IDENT &&
15
- list.first.string_value == "red" &&
16
- list.first.integer_value.nil?
17
- }, false).once
18
- flexmock(@sac.error_handler).
19
- should_receive(:error).ordered.once
20
- flexmock(@sac.document_handler).
21
- should_receive(:property).ordered.with('color', on { |list|
22
- list.length == 1 && list.first.dimension_unit_text.nil? &&
23
- list.first.lexical_unit_type == :SAC_IDENT &&
24
- list.first.string_value == "black" &&
25
- list.first.integer_value.nil?
26
- }, false).once
27
- flexmock(@sac.document_handler).
28
- should_receive(:end_document).ordered.once
29
- @sac.parse('h1 { color: red; rotation: 70minutes; } h2 { color: black }')
30
- flexmock_verify
31
- end
32
-
33
- def test_error_media
34
- flexmock(@sac.document_handler).
35
- should_receive(:start_media).ordered.
36
- with(['all']).once
37
- flexmock(@sac.error_handler).
38
- should_receive(:error).ordered.once
39
- flexmock(@sac.document_handler).
40
- should_receive(:end_media).ordered
41
- @sac.parse('@media all and (min-width:0px) { }')
42
- flexmock_verify
43
- end
44
-
45
- def test_bad_selector
46
- flexmock(@sac.document_handler).
47
- should_receive(:start_selector).ordered.once
48
- flexmock(@sac.document_handler).
49
- should_receive(:property).ordered.with('height', any, false).once
50
- flexmock(@sac.document_handler).
51
- should_receive(:end_selector).ordered.once
52
-
53
- @sac.parse('head~body div#user-section { height: 0; }')
54
- flexmock_verify
55
- end
56
-
57
- def test_malformed_decl_missing_value
58
- flexmock(@sac.document_handler).
59
- should_receive(:property).ordered.with('color', on { |list|
60
- list.length == 1 && list.first.dimension_unit_text.nil? &&
61
- list.first.lexical_unit_type == :SAC_IDENT &&
62
- list.first.string_value == "green" &&
63
- list.first.integer_value.nil?
64
- }, false).once
65
- @sac.parse('p { color:green; color }')
66
- flexmock_verify
67
- end
68
-
69
- def test_function_recover
70
- flexmock(@sac.document_handler).
71
- should_receive(:property).ordered.with('color', on { |list|
72
- list.length == 1 && list.first.dimension_unit_text.nil? &&
73
- list.first.lexical_unit_type == :SAC_IDENT &&
74
- list.first.string_value == "red" &&
75
- list.first.integer_value.nil?
76
- }, false).once
77
- @sac.parse('#modal_cover { filter: alpha(opacity=75); color: red; }')
78
- flexmock_verify
79
- end
80
-
81
- def test_malformed_decl_missing_value_recovery
82
- flexmock(@sac.document_handler).
83
- should_receive(:property).ordered.with('color', on { |list|
84
- list.length == 1 && list.first.dimension_unit_text.nil? &&
85
- list.first.lexical_unit_type == :SAC_IDENT &&
86
- list.first.string_value == "red" &&
87
- list.first.integer_value.nil?
88
- }, false).once
89
- flexmock(@sac.document_handler).
90
- should_receive(:property).ordered.with('color', on { |list|
91
- list.length == 1 && list.first.dimension_unit_text.nil? &&
92
- list.first.lexical_unit_type == :SAC_IDENT &&
93
- list.first.string_value == "green" &&
94
- list.first.integer_value.nil?
95
- }, false).once
96
- @sac.parse('p { color:red; color; color:green }')
97
- flexmock_verify
98
- end
99
-
100
- def test_malformed_decl_missing_value_with_colon
101
- flexmock(@sac.document_handler).
102
- should_receive(:property).ordered.with('color', on { |list|
103
- list.length == 1 && list.first.dimension_unit_text.nil? &&
104
- list.first.lexical_unit_type == :SAC_IDENT &&
105
- list.first.string_value == "green" &&
106
- list.first.integer_value.nil?
107
- }, false).once
108
- @sac.parse('p { color:green; color: }')
109
- flexmock_verify
110
- end
111
-
112
- def test_malformed_decl_missing_value_recovery_with_colon
113
- flexmock(@sac.document_handler).
114
- should_receive(:property).ordered.with('color', on { |list|
115
- list.length == 1 && list.first.dimension_unit_text.nil? &&
116
- list.first.lexical_unit_type == :SAC_IDENT &&
117
- list.first.string_value == "red" &&
118
- list.first.integer_value.nil?
119
- }, false).once
120
- flexmock(@sac.document_handler).
121
- should_receive(:property).ordered.with('color', on { |list|
122
- list.length == 1 && list.first.dimension_unit_text.nil? &&
123
- list.first.lexical_unit_type == :SAC_IDENT &&
124
- list.first.string_value == "green" &&
125
- list.first.integer_value.nil?
126
- }, false).once
127
- @sac.parse('p { color:red; color:; color:green }')
128
- flexmock_verify
129
- end
130
-
131
- def test_malformed_decl_missing_value_unexpected_tokens
132
- flexmock(@sac.document_handler).
133
- should_receive(:property).ordered.with('color', on { |list|
134
- list.length == 1 && list.first.dimension_unit_text.nil? &&
135
- list.first.lexical_unit_type == :SAC_IDENT &&
136
- list.first.string_value == "green" &&
137
- list.first.integer_value.nil?
138
- }, false).once
139
- @sac.parse('p { color:green; color{;color:maroon} }')
140
- flexmock_verify
141
- end
142
-
143
- def test_malformed_decl_missing_value_unexpected_tokens_recover
144
- flexmock(@sac.document_handler).
145
- should_receive(:property).ordered.with('color', on { |list|
146
- list.length == 1 && list.first.dimension_unit_text.nil? &&
147
- list.first.lexical_unit_type == :SAC_IDENT &&
148
- list.first.string_value == "red" &&
149
- list.first.integer_value.nil?
150
- }, false).once
151
- flexmock(@sac.document_handler).
152
- should_receive(:property).ordered.with('color', on { |list|
153
- list.length == 1 && list.first.dimension_unit_text.nil? &&
154
- list.first.lexical_unit_type == :SAC_IDENT &&
155
- list.first.string_value == "green" &&
156
- list.first.integer_value.nil?
157
- }, false).once
158
- @sac.parse('p { color:red; color{;color:maroon}; color:green }')
159
- flexmock_verify
160
- end
161
-
162
- def test_invalid_at_keyword
163
- flexmock(@sac.document_handler).
164
- should_receive(:property).ordered.with('color', on { |list|
165
- list.length == 1 && list.first.dimension_unit_text.nil? &&
166
- list.first.lexical_unit_type == :SAC_IDENT &&
167
- list.first.string_value == "blue" &&
168
- list.first.integer_value.nil?
169
- }, false).once
170
- @sac.parse(
171
- '@three-dee {
172
- @background-lighting {
173
- azimuth: 30deg;
174
- elevation: 190deg;
175
- }
176
- h1 { color: red }
177
- }
178
- h1 { color: blue }')
179
- end
180
-
181
- def test_extra_semi
182
- flexmock(@sac.document_handler).
183
- should_receive(:property).ordered.with('color', on { |list|
184
- list.length == 1 && list.first.dimension_unit_text.nil? &&
185
- list.first.lexical_unit_type == :SAC_IDENT &&
186
- list.first.string_value == "red" &&
187
- list.first.integer_value.nil?
188
- }, false).once
189
- flexmock(@sac.document_handler).
190
- should_receive(:property).ordered.with('color', on { |list|
191
- list.length == 1 && list.first.dimension_unit_text.nil? &&
192
- list.first.lexical_unit_type == :SAC_IDENT &&
193
- list.first.string_value == "green" &&
194
- list.first.integer_value.nil?
195
- }, false).once
196
- @sac.parse('p { color:red; ; color:green }')
197
- flexmock_verify
198
- end
199
- end