csspool 0.2.6 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +16 -0
- data/{CHANGELOG.txt → CHANGELOG.rdoc} +10 -0
- data/Manifest.txt +60 -72
- data/README.rdoc +78 -0
- data/Rakefile +9 -52
- data/lib/csspool/collection.rb +50 -0
- data/lib/csspool/css/charset.rb +7 -0
- data/lib/csspool/css/declaration.rb +8 -0
- data/lib/csspool/css/document.rb +34 -0
- data/lib/csspool/css/document_handler.rb +51 -0
- data/lib/csspool/css/import_rule.rb +15 -0
- data/lib/csspool/css/media.rb +7 -0
- data/lib/csspool/css/rule_set.rb +12 -0
- data/lib/csspool/css.rb +7 -0
- data/lib/csspool/lib_croco/cr_additional_sel.rb +46 -0
- data/lib/csspool/lib_croco/cr_attr_sel.rb +16 -0
- data/lib/csspool/lib_croco/cr_doc_handler.rb +24 -0
- data/lib/csspool/lib_croco/cr_num.rb +13 -0
- data/lib/csspool/lib_croco/cr_parser.rb +11 -0
- data/lib/csspool/lib_croco/cr_parsing_location.rb +17 -0
- data/lib/csspool/lib_croco/cr_pseudo.rb +14 -0
- data/lib/csspool/lib_croco/cr_rgb.rb +18 -0
- data/lib/csspool/lib_croco/cr_selector.rb +34 -0
- data/lib/csspool/lib_croco/cr_simple_sel.rb +54 -0
- data/lib/csspool/lib_croco/cr_term.rb +97 -0
- data/lib/csspool/lib_croco/glist.rb +21 -0
- data/lib/csspool/lib_croco.rb +78 -0
- data/lib/csspool/node.rb +5 -0
- data/lib/csspool/sac/document.rb +35 -0
- data/lib/csspool/sac/parser.rb +122 -0
- data/lib/csspool/sac.rb +2 -0
- data/lib/csspool/selector.rb +32 -0
- data/lib/csspool/selectors/additional.rb +6 -0
- data/lib/csspool/selectors/attribute.rb +21 -0
- data/lib/csspool/selectors/class.rb +11 -0
- data/lib/csspool/selectors/id.rb +11 -0
- data/lib/csspool/selectors/pseudo_class.rb +13 -0
- data/lib/csspool/selectors/simple.rb +22 -0
- data/lib/csspool/selectors/type.rb +6 -0
- data/lib/csspool/selectors/universal.rb +6 -0
- data/lib/csspool/selectors.rb +8 -0
- data/lib/csspool/terms/function.rb +17 -0
- data/lib/csspool/terms/hash.rb +6 -0
- data/lib/csspool/terms/ident.rb +15 -0
- data/lib/csspool/terms/number.rb +14 -0
- data/lib/csspool/terms/rgb.rb +23 -0
- data/lib/csspool/terms/string.rb +6 -0
- data/lib/csspool/terms/uri.rb +6 -0
- data/lib/csspool/terms.rb +7 -0
- data/lib/csspool/visitable.rb +18 -0
- data/lib/csspool/visitors/comparable.rb +78 -0
- data/lib/csspool/visitors/to_css.rb +201 -0
- data/lib/csspool/visitors/visitor.rb +17 -0
- data/lib/csspool/visitors.rb +3 -0
- data/lib/csspool.rb +18 -1
- data/test/css/test_document.rb +13 -0
- data/test/css/test_import_rule.rb +42 -0
- data/test/helper.rb +62 -6
- data/test/sac/test_parser.rb +115 -0
- data/test/sac/test_properties.rb +43 -0
- data/test/sac/test_terms.rb +134 -0
- data/test/test_collection.rb +81 -0
- data/test/test_parser.rb +75 -241
- data/test/test_selector.rb +45 -34
- data/test/visitors/test_comparable.rb +72 -0
- data/test/visitors/test_to_css.rb +141 -0
- metadata +98 -85
- data/README.txt +0 -79
- data/lib/css/sac/conditions/attribute_condition.rb +0 -56
- data/lib/css/sac/conditions/begin_hyphen_condition.rb +0 -22
- data/lib/css/sac/conditions/class_condition.rb +0 -22
- data/lib/css/sac/conditions/combinator_condition.rb +0 -40
- data/lib/css/sac/conditions/condition.rb +0 -35
- data/lib/css/sac/conditions/id_condition.rb +0 -27
- data/lib/css/sac/conditions/one_of_condition.rb +0 -22
- data/lib/css/sac/conditions/pseudo_class_condition.rb +0 -24
- data/lib/css/sac/conditions.rb +0 -5
- data/lib/css/sac/document_handler.rb +0 -67
- data/lib/css/sac/error_handler.rb +0 -14
- data/lib/css/sac/generated_parser.rb +0 -999
- data/lib/css/sac/generated_property_parser.rb +0 -9214
- data/lib/css/sac/lexeme.rb +0 -29
- data/lib/css/sac/lexical_unit.rb +0 -203
- data/lib/css/sac/parse_exception.rb +0 -6
- data/lib/css/sac/parser.rb +0 -115
- data/lib/css/sac/property_parser.rb +0 -47
- data/lib/css/sac/selectors/child_selector.rb +0 -40
- data/lib/css/sac/selectors/conditional_selector.rb +0 -49
- data/lib/css/sac/selectors/descendant_selector.rb +0 -40
- data/lib/css/sac/selectors/element_selector.rb +0 -39
- data/lib/css/sac/selectors/selector.rb +0 -31
- data/lib/css/sac/selectors/sibling_selector.rb +0 -39
- data/lib/css/sac/selectors/simple_selector.rb +0 -25
- data/lib/css/sac/selectors.rb +0 -5
- data/lib/css/sac/token.rb +0 -27
- data/lib/css/sac/tokenizer.rb +0 -187
- data/lib/css/sac/visitable.rb +0 -106
- data/lib/css/sac.rb +0 -14
- data/lib/css/stylesheet/rule.rb +0 -20
- data/lib/css/stylesheet/stylesheet.rb +0 -96
- data/lib/css/stylesheet.rb +0 -3
- data/lib/parser.y +0 -308
- data/lib/property_parser.y +0 -2346
- data/lib/property_parser.y.erb +0 -1321
- data/test/condition_test_case.rb +0 -6
- data/test/selector_test_case.rb +0 -20
- data/test/test_all.rb +0 -4
- data/test/test_attribute_condition.rb +0 -39
- data/test/test_begin_hyphen_condition.rb +0 -15
- data/test/test_child_selector.rb +0 -60
- data/test/test_class_condition.rb +0 -15
- data/test/test_combinator_condition.rb +0 -38
- data/test/test_condition.rb +0 -31
- data/test/test_conditional_selector.rb +0 -44
- data/test/test_descendant_selector.rb +0 -64
- data/test/test_element_selector.rb +0 -31
- data/test/test_error_recovery.rb +0 -28
- data/test/test_id_condition.rb +0 -16
- data/test/test_lexeme.rb +0 -39
- data/test/test_lexical_color.rb +0 -49
- data/test/test_lexical_function.rb +0 -31
- data/test/test_lexical_ident.rb +0 -30
- data/test/test_lexical_number.rb +0 -68
- data/test/test_lexical_string.rb +0 -23
- data/test/test_lexical_unit.rb +0 -106
- data/test/test_lexical_uri.rb +0 -28
- data/test/test_one_of_condition.rb +0 -15
- data/test/test_parse_error.rb +0 -199
- data/test/test_property_parser.rb +0 -593
- data/test/test_selector_as_string.rb +0 -94
- data/test/test_selector_parser.rb +0 -178
- data/test/test_sibling_selector.rb +0 -42
- data/test/test_simple_selector.rb +0 -9
- data/test/test_specificity.rb +0 -76
- data/test/test_stylesheet.rb +0 -95
- data/test/test_token.rb +0 -24
- data/test/test_tokenizer.rb +0 -127
- data/test/test_xpath.rb +0 -105
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
module CSSPool
|
4
|
+
module Visitors
|
5
|
+
class TestComparable < CSSPool::TestCase
|
6
|
+
def equalitest css
|
7
|
+
doc1 = CSSPool.CSS css
|
8
|
+
doc2 = CSSPool.CSS css
|
9
|
+
assert_equal doc1, doc2
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_not_equal
|
13
|
+
doc1 = CSSPool.CSS 'div { border: foo(1, 2); }'
|
14
|
+
assert_not_equal nil, doc1
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_hash_range
|
18
|
+
equalitest 'div { border: #123; }'
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_rgb
|
22
|
+
equalitest 'div { border: rgb(1,2,3); }'
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_rgb_with_percentage
|
26
|
+
equalitest 'div { border: rgb(100%,2%,3%); }'
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_negative_number
|
30
|
+
equalitest 'div { border: -1px; }'
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_positive_number
|
34
|
+
equalitest 'div { border: 1px; }'
|
35
|
+
end
|
36
|
+
|
37
|
+
%w{
|
38
|
+
1 1em 1ex 1px 1in 1cm 1mm 1pt 1pc 1% 1deg 1rad 1ms 1s 1Hz 1kHz
|
39
|
+
}.each do |num|
|
40
|
+
expected = num.sub(/1/, '1.0')
|
41
|
+
define_method(:"test_num_#{num}") do
|
42
|
+
equalitest "div { border: #{num}; }"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_string_term
|
47
|
+
equalitest 'div { border: "hello"; }'
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_inherit
|
51
|
+
equalitest 'div { color: inherit; }'
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_important
|
55
|
+
equalitest 'div { color: inherit !important; }'
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_function
|
59
|
+
equalitest 'div { border: foo("hello"); }'
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_uri
|
63
|
+
equalitest 'div { border: url(http://tenderlovemaking.com/); }'
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_import
|
67
|
+
equalitest '@import "foo.css" screen, print;'
|
68
|
+
equalitest '@import "foo.css";'
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,141 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
module CSSPool
|
4
|
+
module Visitors
|
5
|
+
class TestToCSS < CSSPool::TestCase
|
6
|
+
def test_font_serialization
|
7
|
+
doc = CSSPool.CSS 'p { font: 14px/30px Tahoma; }'
|
8
|
+
|
9
|
+
assert_equal 3, doc.rule_sets.first.declarations[0].expressions.length
|
10
|
+
|
11
|
+
doc = CSSPool.CSS(doc.to_css)
|
12
|
+
assert_equal 3, doc.rule_sets.first.declarations[0].expressions.length
|
13
|
+
|
14
|
+
assert_equal 'font: 14.0px / 30.0px Tahoma;',
|
15
|
+
doc.rule_sets.first.declarations.first.to_css.strip
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_hash_operator
|
19
|
+
doc = CSSPool.CSS 'p { font: foo, #666; }'
|
20
|
+
assert_equal 2, doc.rule_sets.first.declarations[0].expressions.length
|
21
|
+
|
22
|
+
doc = CSSPool.CSS(doc.to_css)
|
23
|
+
assert_equal 2, doc.rule_sets.first.declarations[0].expressions.length
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_uri_operator
|
27
|
+
doc = CSSPool.CSS 'p { font: foo, url(http://example.com/); }'
|
28
|
+
assert_equal 2, doc.rule_sets.first.declarations[0].expressions.length
|
29
|
+
|
30
|
+
doc = CSSPool.CSS(doc.to_css)
|
31
|
+
assert_equal 2, doc.rule_sets.first.declarations[0].expressions.length
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_string_operator
|
35
|
+
doc = CSSPool.CSS 'p { font: foo, "foo"; }'
|
36
|
+
assert_equal 2, doc.rule_sets.first.declarations[0].expressions.length
|
37
|
+
|
38
|
+
doc = CSSPool.CSS(doc.to_css)
|
39
|
+
assert_equal 2, doc.rule_sets.first.declarations[0].expressions.length
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_function_operator
|
43
|
+
doc = CSSPool.CSS 'p { font: foo, foo(1); }'
|
44
|
+
assert_equal 2, doc.rule_sets.first.declarations[0].expressions.length
|
45
|
+
|
46
|
+
doc = CSSPool.CSS(doc.to_css)
|
47
|
+
assert_equal 2, doc.rule_sets.first.declarations[0].expressions.length
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_rgb_operator
|
51
|
+
doc = CSSPool.CSS 'p { font: foo, rgb(1,2,3); }'
|
52
|
+
assert_equal 2, doc.rule_sets.first.declarations[0].expressions.length
|
53
|
+
|
54
|
+
doc = CSSPool.CSS(doc.to_css)
|
55
|
+
assert_equal 2, doc.rule_sets.first.declarations[0].expressions.length
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_includes
|
59
|
+
doc = CSSPool.CSS <<-eocss
|
60
|
+
div[bar ~= 'adsf'] { background: red, blue; }
|
61
|
+
eocss
|
62
|
+
|
63
|
+
assert_equal 1, doc.rule_sets.first.selectors.first.simple_selectors.first.additional_selectors.length
|
64
|
+
assert_equal 2, doc.rule_sets.first.declarations[0].expressions.length
|
65
|
+
|
66
|
+
doc = CSSPool.CSS(doc.to_css)
|
67
|
+
assert_equal 1, doc.rule_sets.first.selectors.first.simple_selectors.first.additional_selectors.length
|
68
|
+
assert_equal 2, doc.rule_sets.first.declarations[0].expressions.length
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_dashmatch
|
72
|
+
doc = CSSPool.CSS <<-eocss
|
73
|
+
div[bar |= 'adsf'] { background: red, blue; }
|
74
|
+
eocss
|
75
|
+
|
76
|
+
assert_equal 1, doc.rule_sets.first.selectors.first.simple_selectors.first.additional_selectors.length
|
77
|
+
|
78
|
+
doc = CSSPool.CSS(doc.to_css)
|
79
|
+
assert_equal 1, doc.rule_sets.first.selectors.first.simple_selectors.first.additional_selectors.length
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_media
|
83
|
+
doc = CSSPool.CSS <<-eocss
|
84
|
+
@media print {
|
85
|
+
div { background: red, blue; }
|
86
|
+
}
|
87
|
+
eocss
|
88
|
+
assert_equal 1, doc.rule_sets.first.media.length
|
89
|
+
|
90
|
+
doc = CSSPool.CSS(doc.to_css)
|
91
|
+
assert_equal 1, doc.rule_sets.first.media.length
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_multiple_media
|
95
|
+
doc = CSSPool.CSS <<-eocss
|
96
|
+
@media print, screen {
|
97
|
+
div { background: red, blue; }
|
98
|
+
}
|
99
|
+
|
100
|
+
@media all {
|
101
|
+
div { background: red, blue; }
|
102
|
+
}
|
103
|
+
eocss
|
104
|
+
assert_equal 2, doc.rule_sets.first.media.length
|
105
|
+
assert_equal 1, doc.rule_sets[1].media.length
|
106
|
+
|
107
|
+
doc = CSSPool.CSS(doc.to_css)
|
108
|
+
assert_equal 2, doc.rule_sets.first.media.length
|
109
|
+
assert_equal 1, doc.rule_sets[1].media.length
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_import
|
113
|
+
doc = CSSPool.CSS <<-eocss
|
114
|
+
@import "test.css";
|
115
|
+
@import url("test.css");
|
116
|
+
@import url("test.css") print, screen;
|
117
|
+
eocss
|
118
|
+
|
119
|
+
assert_equal 3, doc.import_rules.length
|
120
|
+
assert_equal 2, doc.import_rules.last.media.length
|
121
|
+
|
122
|
+
doc = CSSPool.CSS(doc.to_css)
|
123
|
+
|
124
|
+
assert_equal 3, doc.import_rules.length
|
125
|
+
assert_equal 2, doc.import_rules.last.media.length
|
126
|
+
end
|
127
|
+
|
128
|
+
def test_charsets
|
129
|
+
doc = CSSPool.CSS <<-eocss
|
130
|
+
@charset "UTF-8";
|
131
|
+
eocss
|
132
|
+
|
133
|
+
assert_equal 1, doc.charsets.length
|
134
|
+
|
135
|
+
doc = CSSPool.CSS(doc.to_css)
|
136
|
+
|
137
|
+
assert_equal 1, doc.charsets.length
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
metadata
CHANGED
@@ -1,121 +1,125 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: csspool
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aaron Patterson
|
8
|
+
- John Barnette
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
12
|
|
12
|
-
date:
|
13
|
+
date: 2009-07-07 00:00:00 -07:00
|
13
14
|
default_executable:
|
14
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:
|
15
26
|
- !ruby/object:Gem::Dependency
|
16
27
|
name: hoe
|
28
|
+
type: :development
|
17
29
|
version_requirement:
|
18
30
|
version_requirements: !ruby/object:Gem::Requirement
|
19
31
|
requirements:
|
20
32
|
- - ">="
|
21
33
|
- !ruby/object:Gem::Version
|
22
|
-
version:
|
34
|
+
version: 2.3.2
|
23
35
|
version:
|
24
|
-
description:
|
25
|
-
|
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:
|
40
|
+
- aaronp@rubyforge.org
|
41
|
+
- jabarnette@rubyforge.org
|
26
42
|
executables: []
|
27
43
|
|
28
44
|
extensions: []
|
29
45
|
|
30
46
|
extra_rdoc_files:
|
31
|
-
- CHANGELOG.txt
|
32
47
|
- Manifest.txt
|
33
|
-
- README.txt
|
34
48
|
files:
|
35
|
-
-
|
49
|
+
- .autotest
|
50
|
+
- CHANGELOG.rdoc
|
36
51
|
- Manifest.txt
|
37
|
-
- README.
|
52
|
+
- README.rdoc
|
38
53
|
- Rakefile
|
39
|
-
- lib/css/sac.rb
|
40
|
-
- lib/css/sac/conditions.rb
|
41
|
-
- lib/css/sac/conditions/attribute_condition.rb
|
42
|
-
- lib/css/sac/conditions/begin_hyphen_condition.rb
|
43
|
-
- lib/css/sac/conditions/class_condition.rb
|
44
|
-
- lib/css/sac/conditions/combinator_condition.rb
|
45
|
-
- lib/css/sac/conditions/condition.rb
|
46
|
-
- lib/css/sac/conditions/id_condition.rb
|
47
|
-
- lib/css/sac/conditions/one_of_condition.rb
|
48
|
-
- lib/css/sac/conditions/pseudo_class_condition.rb
|
49
|
-
- lib/css/sac/document_handler.rb
|
50
|
-
- lib/css/sac/error_handler.rb
|
51
|
-
- lib/css/sac/generated_parser.rb
|
52
|
-
- lib/css/sac/generated_property_parser.rb
|
53
|
-
- lib/css/sac/lexeme.rb
|
54
|
-
- lib/css/sac/lexical_unit.rb
|
55
|
-
- lib/css/sac/parse_exception.rb
|
56
|
-
- lib/css/sac/parser.rb
|
57
|
-
- lib/css/sac/property_parser.rb
|
58
|
-
- lib/css/sac/selectors.rb
|
59
|
-
- lib/css/sac/selectors/child_selector.rb
|
60
|
-
- lib/css/sac/selectors/conditional_selector.rb
|
61
|
-
- lib/css/sac/selectors/descendant_selector.rb
|
62
|
-
- lib/css/sac/selectors/element_selector.rb
|
63
|
-
- lib/css/sac/selectors/selector.rb
|
64
|
-
- lib/css/sac/selectors/sibling_selector.rb
|
65
|
-
- lib/css/sac/selectors/simple_selector.rb
|
66
|
-
- lib/css/sac/token.rb
|
67
|
-
- lib/css/sac/tokenizer.rb
|
68
|
-
- lib/css/sac/visitable.rb
|
69
|
-
- lib/css/stylesheet.rb
|
70
|
-
- lib/css/stylesheet/rule.rb
|
71
|
-
- lib/css/stylesheet/stylesheet.rb
|
72
54
|
- lib/csspool.rb
|
73
|
-
- lib/
|
74
|
-
- lib/
|
75
|
-
- lib/
|
76
|
-
-
|
55
|
+
- lib/csspool/collection.rb
|
56
|
+
- lib/csspool/css.rb
|
57
|
+
- lib/csspool/css/charset.rb
|
58
|
+
- lib/csspool/css/declaration.rb
|
59
|
+
- lib/csspool/css/document.rb
|
60
|
+
- lib/csspool/css/document_handler.rb
|
61
|
+
- lib/csspool/css/import_rule.rb
|
62
|
+
- lib/csspool/css/media.rb
|
63
|
+
- 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
|
77
|
+
- lib/csspool/node.rb
|
78
|
+
- lib/csspool/sac.rb
|
79
|
+
- lib/csspool/sac/document.rb
|
80
|
+
- lib/csspool/sac/parser.rb
|
81
|
+
- lib/csspool/selector.rb
|
82
|
+
- lib/csspool/selectors.rb
|
83
|
+
- lib/csspool/selectors/additional.rb
|
84
|
+
- lib/csspool/selectors/attribute.rb
|
85
|
+
- lib/csspool/selectors/class.rb
|
86
|
+
- lib/csspool/selectors/id.rb
|
87
|
+
- lib/csspool/selectors/pseudo_class.rb
|
88
|
+
- lib/csspool/selectors/simple.rb
|
89
|
+
- lib/csspool/selectors/type.rb
|
90
|
+
- lib/csspool/selectors/universal.rb
|
91
|
+
- lib/csspool/terms.rb
|
92
|
+
- lib/csspool/terms/function.rb
|
93
|
+
- lib/csspool/terms/hash.rb
|
94
|
+
- lib/csspool/terms/ident.rb
|
95
|
+
- lib/csspool/terms/number.rb
|
96
|
+
- lib/csspool/terms/rgb.rb
|
97
|
+
- lib/csspool/terms/string.rb
|
98
|
+
- lib/csspool/terms/uri.rb
|
99
|
+
- lib/csspool/visitable.rb
|
100
|
+
- lib/csspool/visitors.rb
|
101
|
+
- lib/csspool/visitors/comparable.rb
|
102
|
+
- lib/csspool/visitors/to_css.rb
|
103
|
+
- lib/csspool/visitors/visitor.rb
|
104
|
+
- test/css/test_document.rb
|
105
|
+
- test/css/test_import_rule.rb
|
77
106
|
- test/helper.rb
|
78
|
-
- test/
|
79
|
-
- test/
|
80
|
-
- test/
|
81
|
-
- test/
|
82
|
-
- test/test_child_selector.rb
|
83
|
-
- test/test_class_condition.rb
|
84
|
-
- test/test_combinator_condition.rb
|
85
|
-
- test/test_condition.rb
|
86
|
-
- test/test_conditional_selector.rb
|
87
|
-
- test/test_descendant_selector.rb
|
88
|
-
- test/test_element_selector.rb
|
89
|
-
- test/test_error_recovery.rb
|
90
|
-
- test/test_id_condition.rb
|
91
|
-
- test/test_lexeme.rb
|
92
|
-
- test/test_lexical_color.rb
|
93
|
-
- test/test_lexical_function.rb
|
94
|
-
- test/test_lexical_ident.rb
|
95
|
-
- test/test_lexical_number.rb
|
96
|
-
- test/test_lexical_string.rb
|
97
|
-
- test/test_lexical_unit.rb
|
98
|
-
- test/test_lexical_uri.rb
|
99
|
-
- test/test_one_of_condition.rb
|
100
|
-
- test/test_parse_error.rb
|
107
|
+
- test/sac/test_parser.rb
|
108
|
+
- test/sac/test_properties.rb
|
109
|
+
- test/sac/test_terms.rb
|
110
|
+
- test/test_collection.rb
|
101
111
|
- test/test_parser.rb
|
102
|
-
- test/test_property_parser.rb
|
103
112
|
- test/test_selector.rb
|
104
|
-
- test/
|
105
|
-
- test/
|
106
|
-
- test/test_sibling_selector.rb
|
107
|
-
- test/test_simple_selector.rb
|
108
|
-
- test/test_specificity.rb
|
109
|
-
- test/test_stylesheet.rb
|
110
|
-
- test/test_token.rb
|
111
|
-
- test/test_tokenizer.rb
|
112
|
-
- test/test_xpath.rb
|
113
|
+
- test/visitors/test_comparable.rb
|
114
|
+
- test/visitors/test_to_css.rb
|
113
115
|
has_rdoc: true
|
114
|
-
homepage: http://csspool.rubyforge.org
|
116
|
+
homepage: http://csspool.rubyforge.org
|
117
|
+
licenses: []
|
118
|
+
|
115
119
|
post_install_message:
|
116
120
|
rdoc_options:
|
117
121
|
- --main
|
118
|
-
- README.
|
122
|
+
- README.rdoc
|
119
123
|
require_paths:
|
120
124
|
- lib
|
121
125
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -133,9 +137,18 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
133
137
|
requirements: []
|
134
138
|
|
135
139
|
rubyforge_project: csspool
|
136
|
-
rubygems_version: 1.
|
140
|
+
rubygems_version: 1.3.4
|
137
141
|
signing_key:
|
138
|
-
specification_version:
|
139
|
-
summary:
|
142
|
+
specification_version: 3
|
143
|
+
summary: CSSPool is a CSS parser
|
140
144
|
test_files:
|
141
|
-
- test/
|
145
|
+
- test/css/test_document.rb
|
146
|
+
- test/css/test_import_rule.rb
|
147
|
+
- test/sac/test_parser.rb
|
148
|
+
- test/sac/test_properties.rb
|
149
|
+
- test/sac/test_terms.rb
|
150
|
+
- test/test_collection.rb
|
151
|
+
- test/test_parser.rb
|
152
|
+
- test/test_selector.rb
|
153
|
+
- test/visitors/test_comparable.rb
|
154
|
+
- test/visitors/test_to_css.rb
|
data/README.txt
DELETED
@@ -1,79 +0,0 @@
|
|
1
|
-
= CSSpool
|
2
|
-
|
3
|
-
http://csspool.rubyforge.org/
|
4
|
-
|
5
|
-
== Description
|
6
|
-
|
7
|
-
CSSpool (pronounced "cesspool") is a validating SAC parser for CSS. The parser
|
8
|
-
calls methods on a document handler depending on what it has found. CSSPool
|
9
|
-
currently only supports CSS 2.1. CSSPool will not yield invalid properties or
|
10
|
-
selectors.
|
11
|
-
|
12
|
-
== Dependencies
|
13
|
-
|
14
|
-
Building CSSpool requires:
|
15
|
-
|
16
|
-
- RACC (not just the runtime)
|
17
|
-
(http://i.loveruby.net/en/projects/racc)
|
18
|
-
|
19
|
-
- rubygems, hoe, flexmock
|
20
|
-
|
21
|
-
== Examples
|
22
|
-
|
23
|
-
=== Tidy a stylesheet
|
24
|
-
|
25
|
-
parser = CSS::SAC::Parser.new
|
26
|
-
doc = parser.parse(File.read(ARGV[0]))
|
27
|
-
puts doc.to_css
|
28
|
-
|
29
|
-
=== Find custom attributes
|
30
|
-
|
31
|
-
This example prints out all properties from a particular CSS file.
|
32
|
-
|
33
|
-
class DH < CSS::SAC::DocumentHandler
|
34
|
-
def start_selector(selectors)
|
35
|
-
puts selectors.map { |x| x.to_css }.join(', ')
|
36
|
-
end
|
37
|
-
|
38
|
-
def property(name, value, important)
|
39
|
-
puts "#{name} #{value.join(', ')} #{important}"
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
parser = CSS::SAC::Parser.new(DH.new)
|
44
|
-
parser.parse(File.read(ARGV[0]))
|
45
|
-
|
46
|
-
See CSS::SAC::DocumentHandler for callbacks to implement.
|
47
|
-
|
48
|
-
See SAC[http://www.w3.org/Style/CSS/SAC/] for more information on SAC.
|
49
|
-
|
50
|
-
== Authors
|
51
|
-
|
52
|
-
* {Aaron Patterson}[http://tenderlovemaking.com] <aaronp@rubyforge.org>
|
53
|
-
* {John Barnette}[http://geeksomnia.com] <jbarnette@rubyforge.org>
|
54
|
-
|
55
|
-
== LICENSE
|
56
|
-
|
57
|
-
(The MIT License)
|
58
|
-
|
59
|
-
Copyright (c) 2007 Aaron Patterson, John Barnette
|
60
|
-
|
61
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
62
|
-
a copy of this software and associated documentation files (the
|
63
|
-
'Software'), to deal in the Software without restriction, including
|
64
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
65
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
66
|
-
permit persons to whom the Software is furnished to do so, subject to
|
67
|
-
the following conditions:
|
68
|
-
|
69
|
-
The above copyright notice and this permission notice shall be
|
70
|
-
included in all copies or substantial portions of the Software.
|
71
|
-
|
72
|
-
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
73
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
74
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
75
|
-
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
76
|
-
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
77
|
-
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
78
|
-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
79
|
-
|
@@ -1,56 +0,0 @@
|
|
1
|
-
require "css/sac/conditions"
|
2
|
-
|
3
|
-
module CSS
|
4
|
-
module SAC
|
5
|
-
module Conditions
|
6
|
-
class AttributeCondition < Condition
|
7
|
-
attr_accessor :local_name, :value, :specified
|
8
|
-
alias :specified? :specified
|
9
|
-
|
10
|
-
class << self
|
11
|
-
def build(name, raw)
|
12
|
-
condition, value = raw
|
13
|
-
|
14
|
-
case condition
|
15
|
-
when "~="
|
16
|
-
OneOfCondition.new(name, value)
|
17
|
-
when "|="
|
18
|
-
BeginHyphenCondition.new(name, value)
|
19
|
-
else
|
20
|
-
AttributeCondition.new(name, value, true)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def initialize(local_name, value, specified, condition_type=:SAC_ATTRIBUTE_CONDITION)
|
26
|
-
super(condition_type)
|
27
|
-
|
28
|
-
@local_name = local_name
|
29
|
-
@value = value
|
30
|
-
@specified = specified
|
31
|
-
end
|
32
|
-
|
33
|
-
def to_css
|
34
|
-
"[#{local_name}#{value && "=#{value}"}]"
|
35
|
-
end
|
36
|
-
|
37
|
-
def to_xpath
|
38
|
-
"[@#{local_name}#{value && "='#{value}'"}]"
|
39
|
-
end
|
40
|
-
|
41
|
-
def specificity
|
42
|
-
[0, 0, 1, 0]
|
43
|
-
end
|
44
|
-
|
45
|
-
def ==(other)
|
46
|
-
super && local_name == other.local_name && value == other.value &&
|
47
|
-
specified == other.specified
|
48
|
-
end
|
49
|
-
|
50
|
-
def hash
|
51
|
-
[local_name, value, specified].hash
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
require "css/sac/conditions"
|
2
|
-
|
3
|
-
module CSS
|
4
|
-
module SAC
|
5
|
-
module Conditions
|
6
|
-
class BeginHyphenCondition < AttributeCondition
|
7
|
-
|
8
|
-
def initialize(local_name, value)
|
9
|
-
super(local_name, value, true, :SAC_BEGIN_HYPHEN_ATTRIBUTE_CONDITION)
|
10
|
-
end
|
11
|
-
|
12
|
-
def to_css
|
13
|
-
"[#{local_name}|=#{value}]"
|
14
|
-
end
|
15
|
-
|
16
|
-
def to_xpath
|
17
|
-
"[contains(@#{local_name}, '#{value}')]"
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
require "css/sac/conditions"
|
2
|
-
|
3
|
-
module CSS
|
4
|
-
module SAC
|
5
|
-
module Conditions
|
6
|
-
class ClassCondition < AttributeCondition
|
7
|
-
|
8
|
-
def initialize(klass)
|
9
|
-
super("class", klass, true, :SAC_CLASS_CONDITION)
|
10
|
-
end
|
11
|
-
|
12
|
-
def to_css
|
13
|
-
".#{value}"
|
14
|
-
end
|
15
|
-
|
16
|
-
def to_xpath
|
17
|
-
"[contains(@#{local_name}, '#{value}')]"
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
require "css/sac/conditions"
|
2
|
-
|
3
|
-
module CSS
|
4
|
-
module SAC
|
5
|
-
module Conditions
|
6
|
-
class CombinatorCondition < Condition
|
7
|
-
attr_accessor :first_condition, :second_condition
|
8
|
-
alias :first :first_condition
|
9
|
-
alias :second :second_condition
|
10
|
-
|
11
|
-
def initialize(first, second)
|
12
|
-
super(:SAC_AND_CONDITION)
|
13
|
-
|
14
|
-
@first_condition = first
|
15
|
-
@second_condition = second
|
16
|
-
end
|
17
|
-
|
18
|
-
def to_css
|
19
|
-
"#{first.to_css}#{second.to_css}"
|
20
|
-
end
|
21
|
-
|
22
|
-
def to_xpath
|
23
|
-
"#{first.to_xpath}#{second.to_xpath}"
|
24
|
-
end
|
25
|
-
|
26
|
-
def specificity
|
27
|
-
first.specificity.zip(second.specificity).map { |x,y| x + y }
|
28
|
-
end
|
29
|
-
|
30
|
-
def ==(other)
|
31
|
-
super && first == other.first && second == other.second
|
32
|
-
end
|
33
|
-
|
34
|
-
def hash
|
35
|
-
[first, second].hash
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
module CSS
|
2
|
-
module SAC
|
3
|
-
module Conditions
|
4
|
-
class Condition
|
5
|
-
include CSS::SAC::Visitable
|
6
|
-
|
7
|
-
attr_accessor :condition_type
|
8
|
-
|
9
|
-
def initialize(condition_type)
|
10
|
-
@condition_type = condition_type
|
11
|
-
end
|
12
|
-
|
13
|
-
def ==(other)
|
14
|
-
self.class === other && condition_type == other.condition_type
|
15
|
-
end
|
16
|
-
|
17
|
-
def hash
|
18
|
-
condition_type.hash
|
19
|
-
end
|
20
|
-
|
21
|
-
def eql?(other)
|
22
|
-
self == other
|
23
|
-
end
|
24
|
-
|
25
|
-
def to_css
|
26
|
-
nil
|
27
|
-
end
|
28
|
-
|
29
|
-
def =~(node)
|
30
|
-
MatchesVisitor.new(node).accept(self)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|