line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CSS::Struct::Output::Indent::ANSIColor; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
76543
|
use base qw(CSS::Struct::Output::Indent); |
|
2
|
|
|
|
|
11
|
|
|
2
|
|
|
|
|
1194
|
|
4
|
2
|
|
|
2
|
|
71570
|
use strict; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
39
|
|
5
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
43
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
11
|
use Indent; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
33
|
|
8
|
2
|
|
|
2
|
|
8
|
use Readonly; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
86
|
|
9
|
2
|
|
|
2
|
|
1349
|
use Term::ANSIColor; |
|
2
|
|
|
|
|
16764
|
|
|
2
|
|
|
|
|
2718
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# Constants. |
12
|
|
|
|
|
|
|
Readonly::Scalar my $EMPTY_STR => q{}; |
13
|
|
|
|
|
|
|
Readonly::Scalar my $SPACE => q{ }; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $CSS_COMMENT = 'r064g085b107'; |
16
|
|
|
|
|
|
|
our $CSS_SELECTOR_ELEMENT = 'red'; |
17
|
|
|
|
|
|
|
our $CSS_SELECTOR_CLASS = 'r255g156b000'; |
18
|
|
|
|
|
|
|
our $CSS_SELECTOR_ID = 'r255g156b000'; |
19
|
|
|
|
|
|
|
our $CSS_AT_RULE_KEYWORD = 'r255g156b000'; |
20
|
|
|
|
|
|
|
our $CSS_AT_RULE_VALUE = 'yellow'; |
21
|
|
|
|
|
|
|
our $CSS_DEFINITION_KEY = 'green'; |
22
|
|
|
|
|
|
|
our $CSS_DEFINITION_KEY_PREFIX = 'blue'; |
23
|
|
|
|
|
|
|
our $CSS_DEFINITION_VALUE_NUMBER = 'red'; |
24
|
|
|
|
|
|
|
our $CSS_DEFINITION_VALUE_STRING = 'blue'; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
our $VERSION = 0.01; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# At-rules. |
29
|
|
|
|
|
|
|
sub _put_at_rules { |
30
|
0
|
|
|
0
|
|
|
my ($self, $at_rule, $file) = @_; |
31
|
0
|
|
|
|
|
|
push @{$self->{'flush_code'}}, color($CSS_AT_RULE_KEYWORD).$at_rule.color('reset'). |
|
0
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
' "'.color($CSS_AT_RULE_VALUE).$file.color('reset').'";'; |
33
|
0
|
|
|
|
|
|
$self->{'processed'} = 1; |
34
|
0
|
|
|
|
|
|
return; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# Comment. |
38
|
|
|
|
|
|
|
sub _put_comment { |
39
|
0
|
|
|
0
|
|
|
my ($self, @comments) = @_; |
40
|
0
|
0
|
|
|
|
|
if (! $self->{'skip_comments'}) { |
41
|
0
|
|
|
|
|
|
push @comments, $SPACE.$self->{'comment_delimeters'}->[1]; |
42
|
0
|
|
|
|
|
|
unshift @comments, $self->{'comment_delimeters'}->[0].$SPACE; |
43
|
0
|
0
|
|
|
|
|
if ($self->{'processed'}) { |
44
|
0
|
|
|
|
|
|
push @{$self->{'flush_code'}}, $EMPTY_STR; |
|
0
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
} |
46
|
0
|
|
|
|
|
|
my $comment = color($CSS_COMMENT). |
47
|
|
|
|
|
|
|
(join $EMPTY_STR, @comments). |
48
|
|
|
|
|
|
|
color('reset'); |
49
|
0
|
0
|
|
|
|
|
if (@{$self->{'tmp_code'}}) { |
|
0
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
my $sep = $EMPTY_STR; |
51
|
0
|
0
|
|
|
|
|
if ($self->{'comment_after_selector'} == 0) { |
52
|
0
|
|
|
|
|
|
$sep = $self->{'output_sep'}; |
53
|
0
|
|
|
|
|
|
pop @{$self->{'tmp_code'}}; |
|
0
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
} |
55
|
0
|
|
|
|
|
|
push @{$self->{'tmp_code'}}, ($sep) x 2, $comment, |
56
|
0
|
|
|
|
|
|
$self->{'output_sep'}; |
57
|
0
|
|
|
|
|
|
$self->{'comment_after_selector'} += 4; |
58
|
|
|
|
|
|
|
} else { |
59
|
0
|
|
|
|
|
|
push @{$self->{'flush_code'}}, |
60
|
0
|
|
|
|
|
|
$self->{'indent'}->get.$comment; |
61
|
|
|
|
|
|
|
} |
62
|
0
|
|
|
|
|
|
$self->{'processed'} = 0; |
63
|
|
|
|
|
|
|
} |
64
|
0
|
|
|
|
|
|
return; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# Definition. |
68
|
|
|
|
|
|
|
sub _put_definition { |
69
|
0
|
|
|
0
|
|
|
my ($self, $key, $value) = @_; |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
$self->_check_opened_selector; |
72
|
0
|
|
|
|
|
|
$self->_flush_tmp; |
73
|
0
|
|
|
|
|
|
push @{$self->{'flush_code'}}, |
74
|
0
|
|
|
|
|
|
$self->{'indent'}->get. |
75
|
|
|
|
|
|
|
$self->_colorize_definition_key($key). |
76
|
|
|
|
|
|
|
':'. |
77
|
|
|
|
|
|
|
$SPACE. |
78
|
|
|
|
|
|
|
$self->_colorize_definition_value($value). |
79
|
|
|
|
|
|
|
';'; |
80
|
0
|
|
|
|
|
|
$self->{'processed'} = 1; |
81
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
return; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
# Selectors. |
86
|
|
|
|
|
|
|
sub _put_selector { |
87
|
0
|
|
|
0
|
|
|
my ($self, $selector) = @_; |
88
|
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
$selector = $self->_split_selector($selector); |
90
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
push @{$self->{'tmp_code'}}, $selector, ',', ' '; |
|
0
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
$self->{'comment_after_selector'} = 0; |
93
|
0
|
|
|
|
|
|
$self->{'open_selector'} = 1; |
94
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
return; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub _split_selector { |
99
|
0
|
|
|
0
|
|
|
my ($self, $selector) = @_; |
100
|
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
|
my @selector; |
102
|
0
|
0
|
|
|
|
|
if ($selector =~ m/\s+/ms) { |
103
|
0
|
|
|
|
|
|
@selector = split m/\s+/ms, $selector; |
104
|
|
|
|
|
|
|
} else { |
105
|
0
|
|
|
|
|
|
@selector = $selector; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
0
|
|
|
|
|
|
my $ret_selector; |
109
|
0
|
|
|
|
|
|
foreach my $one_selector (@selector) { |
110
|
0
|
0
|
|
|
|
|
if (defined $ret_selector) { |
111
|
0
|
|
|
|
|
|
$ret_selector .= ' '; |
112
|
|
|
|
|
|
|
} |
113
|
0
|
|
|
|
|
|
$ret_selector .= $self->_detect_selector($one_selector); |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
0
|
|
|
|
|
|
return $ret_selector; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub _detect_selector { |
120
|
0
|
|
|
0
|
|
|
my ($self, $selector) = @_; |
121
|
|
|
|
|
|
|
|
122
|
0
|
0
|
|
|
|
|
if ($selector =~ m/^\./ms) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
123
|
0
|
|
|
|
|
|
$selector = $self->_colorize_selector($selector, 'class'); |
124
|
|
|
|
|
|
|
} elsif ($selector =~ m/^(.*)(#.*)$/ms) { |
125
|
0
|
|
|
|
|
|
$selector = $self->_colorize_selector($1, 'element'). |
126
|
|
|
|
|
|
|
$self->_colorize_selector($2, 'id'); |
127
|
|
|
|
|
|
|
} elsif ($selector =~ m/^(.*)(\..*)$/ms) { |
128
|
0
|
|
|
|
|
|
$selector = $self->_colorize_selector($1, 'element'). |
129
|
|
|
|
|
|
|
$self->_colorize_selector($2, 'class'); |
130
|
|
|
|
|
|
|
} else { |
131
|
0
|
|
|
|
|
|
$selector = $self->_colorize_selector($selector, 'element'); |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
0
|
|
|
|
|
|
return $selector; |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub _colorize_selector { |
138
|
0
|
|
|
0
|
|
|
my ($self, $selector, $type) = @_; |
139
|
|
|
|
|
|
|
|
140
|
0
|
0
|
|
|
|
|
if ($type eq 'element') { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
141
|
0
|
|
|
|
|
|
$selector = color($CSS_SELECTOR_ELEMENT).$selector.color('reset'); |
142
|
|
|
|
|
|
|
} elsif ($type eq 'class') { |
143
|
0
|
|
|
|
|
|
$selector = color($CSS_SELECTOR_CLASS).$selector.color('reset'); |
144
|
|
|
|
|
|
|
} elsif ($type eq 'id') { |
145
|
0
|
|
|
|
|
|
$selector = color($CSS_SELECTOR_ID).$selector.color('reset'); |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
0
|
|
|
|
|
|
return $selector; |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub _colorize_definition_key { |
152
|
0
|
|
|
0
|
|
|
my ($self, $key) = @_; |
153
|
|
|
|
|
|
|
|
154
|
0
|
0
|
|
|
|
|
if ($key =~ m/^--/ms) { |
155
|
0
|
|
|
|
|
|
$key = color($CSS_DEFINITION_KEY_PREFIX).$key.color('reset'); |
156
|
|
|
|
|
|
|
} else { |
157
|
0
|
|
|
|
|
|
$key = color($CSS_DEFINITION_KEY).$key.color('reset'); |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
|
160
|
0
|
|
|
|
|
|
return $key; |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
sub _colorize_definition_value { |
164
|
0
|
|
|
0
|
|
|
my ($self, $value) = @_; |
165
|
|
|
|
|
|
|
|
166
|
0
|
0
|
|
|
|
|
if ($value =~ m/^\d+$/ms) { |
167
|
0
|
|
|
|
|
|
$value = color($CSS_DEFINITION_VALUE_NUMBER).$value.color('reset'); |
168
|
|
|
|
|
|
|
} else { |
169
|
0
|
|
|
|
|
|
$value = color($CSS_DEFINITION_VALUE_STRING).$value.color('reset'); |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
|
172
|
0
|
|
|
|
|
|
return $value; |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
1; |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
__END__ |