maca-fork-csspool 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +72 -0
- data/History.txt +4 -0
- data/Manifest.txt +70 -0
- data/README.rdoc +78 -0
- data/Rakefile +35 -0
- data/lib/csspool.rb +20 -0
- data/lib/csspool/collection.rb +50 -0
- data/lib/csspool/css.rb +7 -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/lib_croco.rb +78 -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 +33 -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/node.rb +5 -0
- data/lib/csspool/sac.rb +2 -0
- data/lib/csspool/sac/document.rb +35 -0
- data/lib/csspool/sac/parser.rb +122 -0
- data/lib/csspool/selector.rb +35 -0
- data/lib/csspool/selectors.rb +8 -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/terms.rb +7 -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/visitable.rb +30 -0
- data/lib/csspool/visitors.rb +5 -0
- data/lib/csspool/visitors/children.rb +50 -0
- data/lib/csspool/visitors/comparable.rb +85 -0
- data/lib/csspool/visitors/iterator.rb +80 -0
- data/lib/csspool/visitors/to_css.rb +188 -0
- data/lib/csspool/visitors/visitor.rb +17 -0
- data/test/css/test_document.rb +13 -0
- data/test/css/test_import_rule.rb +42 -0
- data/test/helper.rb +67 -0
- 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 +91 -0
- data/test/test_selector.rb +47 -0
- data/test/visitors/test_children.rb +20 -0
- data/test/visitors/test_comparable.rb +103 -0
- data/test/visitors/test_each.rb +19 -0
- data/test/visitors/test_to_css.rb +200 -0
- metadata +173 -0
@@ -0,0 +1,21 @@
|
|
1
|
+
module CSSPool
|
2
|
+
module LibCroco
|
3
|
+
class GList < FFI::Struct
|
4
|
+
layout(
|
5
|
+
:data, :pointer,
|
6
|
+
:next, :pointer,
|
7
|
+
:prev, :pointer
|
8
|
+
)
|
9
|
+
|
10
|
+
def to_a
|
11
|
+
list = [self]
|
12
|
+
pointer = list.last[:next]
|
13
|
+
until pointer.null?
|
14
|
+
list << GList.new(pointer)
|
15
|
+
pointer = list.last[:next]
|
16
|
+
end
|
17
|
+
list.map { |x| x[:data] }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/csspool/node.rb
ADDED
data/lib/csspool/sac.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
module CSSPool
|
2
|
+
module SAC
|
3
|
+
class Document
|
4
|
+
def start_document
|
5
|
+
end
|
6
|
+
|
7
|
+
def end_document
|
8
|
+
end
|
9
|
+
|
10
|
+
def charset name, location
|
11
|
+
end
|
12
|
+
|
13
|
+
def import_style media_list, uri, default_ns, location
|
14
|
+
end
|
15
|
+
|
16
|
+
def start_selector selector_list
|
17
|
+
end
|
18
|
+
|
19
|
+
def end_selector selector_list
|
20
|
+
end
|
21
|
+
|
22
|
+
def property name, expression, important
|
23
|
+
end
|
24
|
+
|
25
|
+
def comment comment
|
26
|
+
end
|
27
|
+
|
28
|
+
def start_media media_list, parse_location
|
29
|
+
end
|
30
|
+
|
31
|
+
def end_media media_list, parse_location
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
module CSSPool
|
2
|
+
module SAC
|
3
|
+
class Parser
|
4
|
+
attr_accessor :document
|
5
|
+
|
6
|
+
def initialize document = CSSPool::SAC::Document.new
|
7
|
+
@document = document
|
8
|
+
@selector_stack = []
|
9
|
+
end
|
10
|
+
|
11
|
+
def parse string
|
12
|
+
parse_memory(string, 5)
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
def push selectors
|
17
|
+
@selector_stack << selectors
|
18
|
+
end
|
19
|
+
|
20
|
+
def pop
|
21
|
+
@selector_stack.pop
|
22
|
+
end
|
23
|
+
|
24
|
+
def parse_memory string, encoding
|
25
|
+
parser = LibCroco::CRParser.new(
|
26
|
+
LibCroco.cr_parser_new_from_buf(
|
27
|
+
string,
|
28
|
+
string.length,
|
29
|
+
5,
|
30
|
+
0
|
31
|
+
)
|
32
|
+
)
|
33
|
+
sac_handler =
|
34
|
+
LibCroco::CRDocHandler.new(LibCroco.cr_doc_handler_new)
|
35
|
+
|
36
|
+
selector_stack = []
|
37
|
+
media_stack = []
|
38
|
+
|
39
|
+
sac_handler[:start_document] = lambda { |parser|
|
40
|
+
@document.start_document
|
41
|
+
}
|
42
|
+
sac_handler[:end_document] = lambda { |parser|
|
43
|
+
@document.end_document
|
44
|
+
}
|
45
|
+
sac_handler[:charset] = lambda { |dh, name, location|
|
46
|
+
@document.charset(
|
47
|
+
LibCroco.cr_string_peek_raw_str(name).read_string,
|
48
|
+
LibCroco::CRParsingLocation.new(location).to_h
|
49
|
+
)
|
50
|
+
}
|
51
|
+
|
52
|
+
sac_handler[:import_style] = lambda { |dh, media_list, uri, ns, loc|
|
53
|
+
media_list = media_list.null? ? [] : LibCroco::GList.new(media_list)
|
54
|
+
media_list = media_list.to_a.map { |data|
|
55
|
+
LibCroco.cr_string_peek_raw_str(data).read_string
|
56
|
+
}
|
57
|
+
uri = uri.null? ? nil :
|
58
|
+
LibCroco.cr_string_peek_raw_str(uri).read_string
|
59
|
+
|
60
|
+
ns = ns.null? ? nil : LibCroco.cr_string_peek_raw_str(ns).read_string
|
61
|
+
|
62
|
+
@document.import_style(
|
63
|
+
media_list,
|
64
|
+
uri,
|
65
|
+
ns,
|
66
|
+
LibCroco::CRParsingLocation.new(loc).to_h
|
67
|
+
)
|
68
|
+
}
|
69
|
+
|
70
|
+
sac_handler[:start_selector] = lambda { |dh, list|
|
71
|
+
list = [LibCroco::CRSelector.new(list)]
|
72
|
+
pointer = list.last[:next]
|
73
|
+
until pointer.null?
|
74
|
+
list << LibCroco::CRSelector.new(pointer)
|
75
|
+
pointer = list.last[:next]
|
76
|
+
end
|
77
|
+
selector_stack.push list.map { |l| l.to_selector }
|
78
|
+
@document.start_selector selector_stack.last
|
79
|
+
}
|
80
|
+
|
81
|
+
sac_handler[:end_selector] = lambda { |dh, list|
|
82
|
+
@document.end_selector selector_stack.pop
|
83
|
+
}
|
84
|
+
|
85
|
+
sac_handler[:property] = lambda { |dh, name, expr, important|
|
86
|
+
expr_list = []
|
87
|
+
until expr.null?
|
88
|
+
expr_list << LibCroco::CRTerm.new(expr)
|
89
|
+
expr = expr_list.last[:next]
|
90
|
+
end
|
91
|
+
@document.property(
|
92
|
+
LibCroco.cr_string_peek_raw_str(name).read_string,
|
93
|
+
expr_list.map { |ex| ex.to_term },
|
94
|
+
important == 1
|
95
|
+
)
|
96
|
+
}
|
97
|
+
|
98
|
+
sac_handler[:comment] = lambda { |dh, comment|
|
99
|
+
@document.comment(
|
100
|
+
LibCroco.cr_string_peek_raw_str(comment).read_string
|
101
|
+
)
|
102
|
+
}
|
103
|
+
|
104
|
+
sac_handler[:start_media] = lambda { |dh,media_list,location|
|
105
|
+
media_list = LibCroco::GList.new(media_list)
|
106
|
+
media_stack << [media_list.to_a.map { |data|
|
107
|
+
LibCroco.cr_string_peek_raw_str(data).read_string
|
108
|
+
}, LibCroco::CRParsingLocation.new(location).to_h]
|
109
|
+
@document.start_media(*media_stack.last)
|
110
|
+
}
|
111
|
+
|
112
|
+
sac_handler[:end_media] = lambda { |dh,media_list|
|
113
|
+
@document.end_media(*media_stack.pop)
|
114
|
+
}
|
115
|
+
|
116
|
+
LibCroco.cr_parser_set_sac_handler(parser, sac_handler)
|
117
|
+
LibCroco.cr_parser_parse(parser)
|
118
|
+
LibCroco.cr_doc_handler_destroy(sac_handler)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module CSSPool
|
2
|
+
class Selector < CSSPool::Node
|
3
|
+
attr_accessor :simple_selectors
|
4
|
+
attr_accessor :parse_location
|
5
|
+
attr_accessor :rule_set
|
6
|
+
|
7
|
+
COMBINATORS = [nil, ' ', ' + ', ' > ']
|
8
|
+
|
9
|
+
|
10
|
+
def initialize simple_selectors = [], parse_location = {}
|
11
|
+
@simple_selectors = simple_selectors
|
12
|
+
@parse_location = parse_location
|
13
|
+
@rule_set = nil
|
14
|
+
end
|
15
|
+
|
16
|
+
def declarations
|
17
|
+
@rule_set.declarations
|
18
|
+
end
|
19
|
+
|
20
|
+
def specificity
|
21
|
+
a = b = c = 0
|
22
|
+
simple_selectors.each do |s|
|
23
|
+
c += 1
|
24
|
+
s.additional_selectors.each do |additional_selector|
|
25
|
+
if Selectors::Id === additional_selector
|
26
|
+
a += 1
|
27
|
+
else
|
28
|
+
b += 1
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
[a, b, c]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
require 'csspool/selectors/simple'
|
2
|
+
require 'csspool/selectors/universal'
|
3
|
+
require 'csspool/selectors/type'
|
4
|
+
require 'csspool/selectors/additional'
|
5
|
+
require 'csspool/selectors/id'
|
6
|
+
require 'csspool/selectors/class'
|
7
|
+
require 'csspool/selectors/pseudo_class'
|
8
|
+
require 'csspool/selectors/attribute'
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module CSSPool
|
2
|
+
module Selectors
|
3
|
+
class Attribute < CSSPool::Selectors::Additional
|
4
|
+
attr_accessor :name
|
5
|
+
attr_accessor :value
|
6
|
+
attr_accessor :match_way
|
7
|
+
|
8
|
+
NO_MATCH = 0
|
9
|
+
SET = 1
|
10
|
+
EQUALS = 2
|
11
|
+
INCLUDES = 3
|
12
|
+
DASHMATCH = 4
|
13
|
+
|
14
|
+
def initialize name, value, match_way
|
15
|
+
@name = name
|
16
|
+
@value = value
|
17
|
+
@match_way = match_way
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module CSSPool
|
2
|
+
module Selectors
|
3
|
+
class Simple < CSSPool::Node
|
4
|
+
NO_COMBINATOR = 0
|
5
|
+
DESCENDENT = 1
|
6
|
+
PRECEDED_BY = 2
|
7
|
+
CHILD = 3
|
8
|
+
|
9
|
+
attr_accessor :name
|
10
|
+
attr_accessor :parse_location
|
11
|
+
attr_accessor :additional_selectors
|
12
|
+
attr_accessor :combinator
|
13
|
+
|
14
|
+
def initialize name, combinator = nil
|
15
|
+
@name = name
|
16
|
+
@combinator = combinator
|
17
|
+
@parse_location = nil
|
18
|
+
@additional_selectors = []
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module CSSPool
|
2
|
+
module Terms
|
3
|
+
class Function < CSSPool::Node
|
4
|
+
attr_accessor :name
|
5
|
+
attr_accessor :params
|
6
|
+
attr_accessor :parse_location
|
7
|
+
attr_accessor :operator
|
8
|
+
|
9
|
+
def initialize name, params, operator, parse_location
|
10
|
+
@name = name
|
11
|
+
@params = params
|
12
|
+
@operator = operator
|
13
|
+
@parse_location = parse_location
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module CSSPool
|
2
|
+
module Terms
|
3
|
+
class Ident < CSSPool::Node
|
4
|
+
attr_accessor :value
|
5
|
+
attr_accessor :operator
|
6
|
+
attr_accessor :parse_location
|
7
|
+
|
8
|
+
def initialize value, operator, parse_location
|
9
|
+
@value = value
|
10
|
+
@operator = operator
|
11
|
+
@parse_location = parse_location
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module CSSPool
|
2
|
+
module Terms
|
3
|
+
class Number < Ident
|
4
|
+
attr_accessor :type
|
5
|
+
attr_accessor :unary_operator
|
6
|
+
|
7
|
+
def initialize type, unary_operator, value, operator, parse_location
|
8
|
+
@type = type
|
9
|
+
@unary_operator = unary_operator
|
10
|
+
super(value, operator, parse_location)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module CSSPool
|
2
|
+
module Terms
|
3
|
+
class Rgb < CSSPool::Node
|
4
|
+
attr_accessor :red
|
5
|
+
attr_accessor :green
|
6
|
+
attr_accessor :blue
|
7
|
+
attr_accessor :percentage
|
8
|
+
attr_accessor :parse_location
|
9
|
+
attr_accessor :operator
|
10
|
+
alias :percentage? :percentage
|
11
|
+
|
12
|
+
def initialize red, green, blue, percentage, operator, parse_location
|
13
|
+
super()
|
14
|
+
@red = red
|
15
|
+
@green = green
|
16
|
+
@blue = blue
|
17
|
+
@percentage = percentage
|
18
|
+
@operator = operator
|
19
|
+
@parse_location = parse_location
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|