Refactor attribute handling in build and parser functions
This commit is contained in:
parent
669ccfb1e1
commit
cb2f6e8748
2 changed files with 17 additions and 18 deletions
|
|
@ -189,21 +189,16 @@ func (page *Page) parse(doc *goquery.Document, option *BuildOption, warnings []s
|
||||||
// Set Attrs
|
// Set Attrs
|
||||||
attrs := map[string]string{}
|
attrs := map[string]string{}
|
||||||
if sel.Length() > 0 {
|
if sel.Length() > 0 {
|
||||||
if page.Attrs != nil {
|
for _, attr := range sel.Nodes[0].Attr {
|
||||||
parentProps := Data{"$prop": page.Attrs}
|
if attr.Key == "is" || attr.Key == "parsed" {
|
||||||
for k, v := range page.Attrs {
|
continue
|
||||||
if k == "is" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
attrs[k], _ = parentProps.ReplaceUse(slotRe, v)
|
|
||||||
}
|
}
|
||||||
} else {
|
val := attr.Val
|
||||||
for _, attr := range sel.Nodes[0].Attr {
|
if page.Attrs != nil {
|
||||||
if attr.Key == "is" {
|
parentProps := Data{"$prop": page.Attrs}
|
||||||
continue
|
val, _ = parentProps.ReplaceUse(slotRe, val)
|
||||||
}
|
|
||||||
attrs[attr.Key] = attr.Val
|
|
||||||
}
|
}
|
||||||
|
attrs[attr.Key] = val
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -159,14 +159,18 @@ func (parser *TemplateParser) setStatementNode(sel *goquery.Selection) {
|
||||||
}
|
}
|
||||||
|
|
||||||
valueExp := sel.AttrOr("value", "")
|
valueExp := sel.AttrOr("value", "")
|
||||||
val, err := parser.data.Exec(valueExp)
|
if stmtRe.MatchString(valueExp) {
|
||||||
if err != nil {
|
val, err := parser.data.Exec(valueExp)
|
||||||
log.Warn("Set %s: %s", valueExp, err)
|
if err != nil {
|
||||||
parser.data[name] = nil
|
log.Warn("Set %s: %s", valueExp, err)
|
||||||
|
parser.data[name] = valueExp
|
||||||
|
return
|
||||||
|
}
|
||||||
|
parser.data[name] = val
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
parser.data[name] = val
|
parser.data[name] = valueExp
|
||||||
}
|
}
|
||||||
|
|
||||||
func (parser *TemplateParser) parseElementAttrs(sel *goquery.Selection) {
|
func (parser *TemplateParser) parseElementAttrs(sel *goquery.Selection) {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue