19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/csspool/lib_croco/cr_term.rb', line 19
def to_term
operator = {
0 => nil,
1 => '/',
2 => ','
}[self[:operator]]
unary_op = {
0 => nil,
1 => :plus,
2 => :minus
}[self[:unary_op]]
case self[:type]
when 0 when 1 num = CRNum.new(self[:content])
CSSPool::Terms::Number.new(
num[:type],
unary_op,
num[:value],
operator,
LibCroco.location_to_h(self)
)
when 2 name = LibCroco.cr_string_peek_raw_str(self[:content]).read_string
params = []
term = self[:ext_content]
until term.null?
params << LibCroco::CRTerm.new(term)
term = params.last[:next]
end
CSSPool::Terms::Function.new(
name,
params.map { |param| param.to_term },
operator,
LibCroco.location_to_h(self)
)
when 3 CSSPool::Terms::String.new(
LibCroco.cr_string_peek_raw_str(self[:content]).read_string,
operator,
LibCroco.location_to_h(self)
)
when 4 CSSPool::Terms::Ident.new(
LibCroco.cr_string_peek_raw_str(self[:content]).read_string,
operator,
LibCroco.location_to_h(self)
)
when 5 CSSPool::Terms::URI.new(
LibCroco.cr_string_peek_raw_str(self[:content]).read_string,
operator,
LibCroco.location_to_h(self)
)
when 6 rgb = LibCroco::CRRgb.new(self[:content])
CSSPool::Terms::Rgb.new(
rgb[:red],
rgb[:green],
rgb[:blue],
rgb[:is_percentage] == 1,
operator,
LibCroco.location_to_h(rgb)
)
when 7 raise "libcroco doesn't seem to support this term"
when 8 CSSPool::Terms::Hash.new(
LibCroco.cr_string_peek_raw_str(self[:content]).read_string,
operator,
LibCroco.location_to_h(self)
)
end
end
|