Skip to content

Commit

Permalink
pugtemplate: deduplicate class attributes
Browse files Browse the repository at this point in the history
multiple same-classes are currently merged, but should be checked
for duplicates.

e.g. `h1.foo.bar.foo` should render
`<h1 class="foo bar">`
not
`<h1 class="foo bar foo">`

Closes #2
  • Loading branch information
bastianccm committed Oct 23, 2017
1 parent f90edfe commit 38d95ef
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pugjs/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ var funcmap = FuncMap{
a := make(map[string][]tmpattr)
var order []string
for _, list := range attrs {
attrloop:
for _, attr := range list.items {
if attr == nil {
continue
Expand All @@ -186,6 +187,12 @@ var funcmap = FuncMap{
att.val = val
if _, ok := a[name]; ok {
if name == "class" {
for _, s := range a[name] {
if s == att {
// we already now this attribute value for class, continue
continue attrloop
}
}
a[name] = append(a[name], att)
} else {
a[name] = []tmpattr{att}
Expand Down

0 comments on commit 38d95ef

Please sign in to comment.