1 | // sass.hpp must go before all system headers to get the |
---|---|
2 | // __EXTENSIONS__ fix on Solaris. |
3 | #include "sass.hpp" |
4 | #include "ast.hpp" |
5 | |
6 | #include "remove_placeholders.hpp" |
7 | |
8 | namespace Sass { |
9 | |
10 | Remove_Placeholders::Remove_Placeholders() |
11 | { } |
12 | |
13 | void Remove_Placeholders::operator()(Block* b) { |
14 | for (size_t i = 0, L = b->length(); i < L; ++i) { |
15 | if (b->get(i)) b->get(i)->perform(op: this); |
16 | } |
17 | } |
18 | |
19 | void Remove_Placeholders::remove_placeholders(SimpleSelector* simple) |
20 | { |
21 | if (PseudoSelector * pseudo = simple->getPseudoSelector()) { |
22 | if (pseudo->selector()) remove_placeholders(pseudo->selector()); |
23 | } |
24 | } |
25 | |
26 | void Remove_Placeholders::remove_placeholders(CompoundSelector* compound) |
27 | { |
28 | for (size_t i = 0, L = compound->length(); i < L; ++i) { |
29 | if (compound->get(i)) remove_placeholders(simple: compound->get(i)); |
30 | } |
31 | listEraseItemIf(vec&: compound->elements(), predicate: listIsEmpty<SimpleSelector>); |
32 | } |
33 | |
34 | void Remove_Placeholders::remove_placeholders(ComplexSelector* complex) |
35 | { |
36 | if (complex->has_placeholder()) { |
37 | complex->clear(); // remove all |
38 | } |
39 | else { |
40 | for (size_t i = 0, L = complex->length(); i < L; ++i) { |
41 | if (CompoundSelector * compound = complex->get(i)->getCompound()) { |
42 | if (compound) remove_placeholders(compound); |
43 | } |
44 | } |
45 | listEraseItemIf(vec&: complex->elements(), predicate: listIsEmpty<SelectorComponent>); |
46 | } |
47 | } |
48 | |
49 | SelectorList* Remove_Placeholders::remove_placeholders(SelectorList* sl) |
50 | { |
51 | for (size_t i = 0, L = sl->length(); i < L; ++i) { |
52 | if (sl->get(i)) remove_placeholders(complex: sl->get(i)); |
53 | } |
54 | listEraseItemIf(vec&: sl->elements(), predicate: listIsEmpty<ComplexSelector>); |
55 | return sl; |
56 | } |
57 | |
58 | void Remove_Placeholders::operator()(CssMediaRule* rule) |
59 | { |
60 | if (rule->block()) operator()(b: rule->block()); |
61 | } |
62 | |
63 | void Remove_Placeholders::operator()(StyleRule* r) |
64 | { |
65 | if (SelectorListObj sl = r->selector()) { |
66 | // Set the new placeholder selector list |
67 | r->selector(selector__: (remove_placeholders(sl))); |
68 | } |
69 | // Iterate into child blocks |
70 | Block_Obj b = r->block(); |
71 | for (size_t i = 0, L = b->length(); i < L; ++i) { |
72 | if (b->get(i)) { b->get(i)->perform(op: this); } |
73 | } |
74 | } |
75 | |
76 | void Remove_Placeholders::operator()(SupportsRule* m) |
77 | { |
78 | if (m->block()) operator()(b: m->block()); |
79 | } |
80 | |
81 | void Remove_Placeholders::operator()(AtRule* a) |
82 | { |
83 | if (a->block()) a->block()->perform(op: this); |
84 | } |
85 | |
86 | } |
87 |