Fix style application
This commit is contained in:
parent
e4cba4a7c9
commit
fbb6d61cfc
@ -5,20 +5,21 @@ import "git.tebibyte.media/tomo/tomo"
|
|||||||
type styleApplicator struct {
|
type styleApplicator struct {
|
||||||
style *tomo.Style
|
style *tomo.Style
|
||||||
role tomo.Role
|
role tomo.Role
|
||||||
rules []*tomo.Rule
|
rules []tomo.Rule
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *styleApplicator) apply (box anyBox) {
|
func (this *styleApplicator) apply (box anyBox) {
|
||||||
if box.Role() != this.role {
|
if box.Role() != this.role {
|
||||||
|
this.role = box.Role()
|
||||||
// the role has changed, so re-cache the list of rules
|
// the role has changed, so re-cache the list of rules
|
||||||
this.rules = make([]*tomo.Rule, 0, 4)
|
this.rules = nil
|
||||||
for _, rule := range this.style.Rules {
|
for _, rule := range this.style.Rules {
|
||||||
role := box.Role()
|
role := box.Role()
|
||||||
// blank fields match anything
|
// blank fields match anything
|
||||||
if rule.Role.Package == "" { role.Package = "" }
|
if rule.Role.Package == "" { role.Package = "" }
|
||||||
if rule.Role.Object == "" { role.Object = "" }
|
if rule.Role.Object == "" { role.Object = "" }
|
||||||
if rule.Role == role {
|
if rule.Role == role {
|
||||||
this.rules = append(this.rules, &rule)
|
this.rules = append(this.rules, rule)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -27,12 +28,10 @@ func (this *styleApplicator) apply (box anyBox) {
|
|||||||
attrs := make(tomo.AttrSet)
|
attrs := make(tomo.AttrSet)
|
||||||
for _, rule := range this.rules {
|
for _, rule := range this.rules {
|
||||||
satisifed := true
|
satisifed := true
|
||||||
if rule.Tags != nil {
|
for _, tag := range rule.Tags {
|
||||||
for _, tag := range rule.Tags {
|
if !box.Tag(tag) {
|
||||||
if !box.Tag(tag) {
|
satisifed = false
|
||||||
satisifed = false
|
break
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user