Merge pull request #751 from trheyi/main
Refactor dynamic component parsing in SUI core
This commit is contained in:
commit
b88ff67cd2
2 changed files with 34 additions and 11 deletions
|
|
@ -56,6 +56,9 @@ func (page *Page) Build(ctx *BuildContext, option *BuildOption) (*goquery.Docume
|
||||||
// Parse the imports
|
// Parse the imports
|
||||||
page.parseImports(doc)
|
page.parseImports(doc)
|
||||||
|
|
||||||
|
// Parse the dynamic components
|
||||||
|
page.parseDynamics(ctx, doc.Selection)
|
||||||
|
|
||||||
body := doc.Find("body")
|
body := doc.Find("body")
|
||||||
body.SetAttr("s:ns", namespace)
|
body.SetAttr("s:ns", namespace)
|
||||||
body.SetAttr("s:public", option.PublicRoot) // Save public root
|
body.SetAttr("s:public", option.PublicRoot) // Save public root
|
||||||
|
|
@ -195,6 +198,9 @@ func (page *Page) BuildAsComponent(sel *goquery.Selection, ctx *BuildContext, op
|
||||||
// Parse the imports
|
// Parse the imports
|
||||||
page.parseImports(doc)
|
page.parseImports(doc)
|
||||||
|
|
||||||
|
// Parse the dynamic components
|
||||||
|
page.parseDynamics(ctx, doc.Selection)
|
||||||
|
|
||||||
// Bind the component events
|
// Bind the component events
|
||||||
page.BindEvent(ctx, doc.Selection, component, false)
|
page.BindEvent(ctx, doc.Selection, component, false)
|
||||||
|
|
||||||
|
|
@ -266,6 +272,21 @@ func (page *Page) BuildAsComponent(sel *goquery.Selection, ctx *BuildContext, op
|
||||||
return source, nil
|
return source, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Parse the dynamic components, which are the is attribute is variable
|
||||||
|
func (page *Page) parseDynamics(ctx *BuildContext, sel *goquery.Selection) {
|
||||||
|
if ctx == nil {
|
||||||
|
ctx = NewBuildContext(nil)
|
||||||
|
}
|
||||||
|
sel.Find("dynamic").Each(func(i int, s *goquery.Selection) {
|
||||||
|
defer s.Remove()
|
||||||
|
route := s.AttrOr("route", "")
|
||||||
|
if route == "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ctx.addJitComponent(route)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func (page *Page) parseImports(doc *goquery.Document) {
|
func (page *Page) parseImports(doc *goquery.Document) {
|
||||||
imports := doc.Find("import")
|
imports := doc.Find("import")
|
||||||
mapping := map[string]PageImport{}
|
mapping := map[string]PageImport{}
|
||||||
|
|
|
||||||
|
|
@ -60,16 +60,17 @@ type ParserOption struct {
|
||||||
Request *Request `json:"request,omitempty"`
|
Request *Request `json:"request,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var keepWords = map[string]bool{
|
// var keepWords = map[string]bool{
|
||||||
"s:if": true,
|
// "s:if": true,
|
||||||
"s:for": true,
|
// "s:for": true,
|
||||||
"s:for-item": true,
|
// "s:for-item": true,
|
||||||
"s:for-index": true,
|
// "s:for-index": true,
|
||||||
"s:elif": true,
|
// "s:elif": true,
|
||||||
"s:else": true,
|
// "s:else": true,
|
||||||
"s:set": true,
|
// "s:set": true,
|
||||||
"s:bind": true,
|
// "set": true,
|
||||||
}
|
// "s:bind": true,
|
||||||
|
// }
|
||||||
|
|
||||||
var allowUsePropAttrs = map[string]bool{
|
var allowUsePropAttrs = map[string]bool{
|
||||||
"s:if": true,
|
"s:if": true,
|
||||||
|
|
@ -268,7 +269,8 @@ func (parser *TemplateParser) parseElementNode(sel *goquery.Selection) {
|
||||||
parser.ifStatementNode(sel)
|
parser.ifStatementNode(sel)
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, exist := sel.Attr("s:set"); exist || node.Data == "s:set" {
|
// keep the node if the editor is enabled
|
||||||
|
if _, exist := sel.Attr("s:set"); exist || node.Data == "s:set" || node.Data == "set" {
|
||||||
parser.setStatementNode(sel)
|
parser.setStatementNode(sel)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue