Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
admpub committed Jun 21, 2021
1 parent b61265d commit 47031a9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
19 changes: 19 additions & 0 deletions config/element.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package config

import "strings"

type Element struct {
ID string `json:"id"`
Type string `json:"type"`
Expand All @@ -23,3 +25,20 @@ func (e *Element) Clone() *Element {
r := *e
return &r
}

func (e *Element) HasAttr(attrs ...string) bool {
mk := map[string]struct{}{}
for _, attr := range attrs {
mk[strings.ToLower(attr)] = struct{}{}
}
for _, v := range e.Attributes {
if len(v) == 0 || len(v[0]) == 0 {
continue
}
v[0] = strings.ToLower(v[0])
if _, ok := mk[v[0]]; ok {
return true
}
}
return false
}
8 changes: 7 additions & 1 deletion config/utils.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package config

const (
STATIC = "static"
Disabled = "disabled"
Readonly = "readonly"
)

func getNames(elements []*Element, languages []*Language) []string {
var names []string
for _, elem := range elements {
Expand All @@ -11,7 +17,7 @@ func getNames(elements []*Element, languages []*Language) []string {
names = append(names, getNames(elem.Elements, languages)...)
continue
}
if len(elem.Name) > 0 {
if len(elem.Name) > 0 && elem.Type != STATIC && !elem.HasAttr(Disabled, Readonly) {
if len(languages) == 0 {
names = append(names, elem.Name)
} else {
Expand Down

0 comments on commit 47031a9

Please sign in to comment.