-
Notifications
You must be signed in to change notification settings - Fork 0
/
modifier.go
60 lines (57 loc) · 1.56 KB
/
modifier.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
package go2css
import (
"fmt"
)
type (
ModifierConfigurator struct {
rule *Rule
traitRules []*Rule
stylesheet *Stylesheet
}
)
func (cfg *ModifierConfigurator) D(property string, value string) {
newDeclaration := &Declaration{
property: property,
value: value,
}
for _, d := range cfg.rule.declarations {
if d.property == newDeclaration.property {
panic(fmt.Sprintf("declaration \"%s\" already exists", d.property))
}
}
cfg.rule.declarations = append(cfg.rule.declarations, newDeclaration)
}
func (cfg *ModifierConfigurator) Has(path []string) {
rule := cfg.stylesheet.includeTrait(path)
for _, newDeclaration := range rule.declarations {
for _, oldDeclaration := range cfg.rule.declarations {
if newDeclaration.property == oldDeclaration.property {
panic(
fmt.Sprintf(
"declaration \"%s\" already exists. old: %s | new: %s",
newDeclaration.property,
oldDeclaration.value,
newDeclaration.value,
))
}
}
for _, previousTraitRule := range cfg.traitRules {
for _, oldDeclaration := range previousTraitRule.declarations {
if newDeclaration.property == oldDeclaration.property {
panic(
fmt.Sprintf(
"declaration \"%s\" already exists. old: \"%s\" from trait \"%s\" | new: \"%s\" from trait \"%s\"",
newDeclaration.property,
oldDeclaration.value,
previousTraitRule.comment,
newDeclaration.value,
rule.comment,
),
)
}
}
}
}
rule.selectors = append(rule.selectors, cfg.rule.selectors[0])
cfg.traitRules = append(cfg.traitRules, rule)
}