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
|
||||
attrs := map[string]string{}
|
||||
if sel.Length() > 0 {
|
||||
if page.Attrs != nil {
|
||||
parentProps := Data{"$prop": page.Attrs}
|
||||
for k, v := range page.Attrs {
|
||||
if k == "is" {
|
||||
continue
|
||||
}
|
||||
attrs[k], _ = parentProps.ReplaceUse(slotRe, v)
|
||||
for _, attr := range sel.Nodes[0].Attr {
|
||||
if attr.Key == "is" || attr.Key == "parsed" {
|
||||
continue
|
||||
}
|
||||
} else {
|
||||
for _, attr := range sel.Nodes[0].Attr {
|
||||
if attr.Key == "is" {
|
||||
continue
|
||||
}
|
||||
attrs[attr.Key] = attr.Val
|
||||
val := attr.Val
|
||||
if page.Attrs != nil {
|
||||
parentProps := Data{"$prop": page.Attrs}
|
||||
val, _ = parentProps.ReplaceUse(slotRe, val)
|
||||
}
|
||||
attrs[attr.Key] = val
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -159,14 +159,18 @@ func (parser *TemplateParser) setStatementNode(sel *goquery.Selection) {
|
|||
}
|
||||
|
||||
valueExp := sel.AttrOr("value", "")
|
||||
val, err := parser.data.Exec(valueExp)
|
||||
if err != nil {
|
||||
log.Warn("Set %s: %s", valueExp, err)
|
||||
parser.data[name] = nil
|
||||
if stmtRe.MatchString(valueExp) {
|
||||
val, err := parser.data.Exec(valueExp)
|
||||
if err != nil {
|
||||
log.Warn("Set %s: %s", valueExp, err)
|
||||
parser.data[name] = valueExp
|
||||
return
|
||||
}
|
||||
parser.data[name] = val
|
||||
return
|
||||
}
|
||||
|
||||
parser.data[name] = val
|
||||
parser.data[name] = valueExp
|
||||
}
|
||||
|
||||
func (parser *TemplateParser) parseElementAttrs(sel *goquery.Selection) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue