refactor: Update parsing logic for JIT components
This commit is contained in:
parent
a2d1ee8ca9
commit
536621d72e
2 changed files with 19 additions and 17 deletions
|
|
@ -261,8 +261,6 @@ func (page *Page) buildComponents(doc *goquery.Document, ctx *BuildContext, opti
|
|||
return
|
||||
}
|
||||
|
||||
sel.SetAttr("parsed", "true")
|
||||
|
||||
// Check if Just-In-Time Component ( "is" has variable )
|
||||
if ctx.isJitComponent(name) {
|
||||
sel.SetAttr("s:jit", "true")
|
||||
|
|
@ -271,6 +269,7 @@ func (page *Page) buildComponents(doc *goquery.Document, ctx *BuildContext, opti
|
|||
return
|
||||
}
|
||||
|
||||
sel.SetAttr("parsed", "true")
|
||||
ipage, err := tmpl.Page(name)
|
||||
if err != nil {
|
||||
setError(sel, err)
|
||||
|
|
|
|||
|
|
@ -271,14 +271,14 @@ func (parser *TemplateParser) parseNode(node *html.Node) {
|
|||
|
||||
func (parser *TemplateParser) parseElementNode(sel *goquery.Selection) {
|
||||
|
||||
if _, exist := sel.Attr("s:if"); exist {
|
||||
parser.ifStatementNode(sel)
|
||||
}
|
||||
|
||||
if _, exist := sel.Attr("s:for"); exist {
|
||||
parser.forStatementNode(sel)
|
||||
}
|
||||
|
||||
if _, exist := sel.Attr("s:if"); exist {
|
||||
parser.ifStatementNode(sel)
|
||||
}
|
||||
|
||||
if _, exist := sel.Attr("s:set"); exist || sel.Get(0).Data == "s:set" {
|
||||
parser.setStatementNode(sel)
|
||||
}
|
||||
|
|
@ -303,6 +303,7 @@ func (parser *TemplateParser) parseJitElementNode(sel *goquery.Selection) {
|
|||
return
|
||||
}
|
||||
|
||||
parser.parsed(sel)
|
||||
// Render the JIT component Data
|
||||
is, _ = parser.data.Replace(is)
|
||||
root := sel.AttrOr("s:root", "/")
|
||||
|
|
@ -312,23 +313,25 @@ func (parser *TemplateParser) parseJitElementNode(sel *goquery.Selection) {
|
|||
content, err := application.App.Read(file)
|
||||
if err != nil {
|
||||
log.Error("[parser] %s JIT %s", file, err.Error())
|
||||
setError(sel, err)
|
||||
return
|
||||
}
|
||||
sel.ReplaceWith(string(content))
|
||||
|
||||
// With Properties
|
||||
|
||||
// copy options
|
||||
option := *parser.option
|
||||
option.Component = true
|
||||
p := NewTemplateParser(parser.data, &option)
|
||||
html, err := p.Render(string(content))
|
||||
if err != nil {
|
||||
log.Error("[parser] %s JIT %s", file, err.Error())
|
||||
return
|
||||
}
|
||||
// // copy options
|
||||
// option := *parser.option
|
||||
// option.Component = true
|
||||
// p := NewTemplateParser(parser.data, &option)
|
||||
// html, err := p.Render(string(content))
|
||||
// if err != nil {
|
||||
// log.Error("[parser] %s JIT %s", file, err.Error())
|
||||
// return
|
||||
// }
|
||||
|
||||
// Replace the node
|
||||
sel.ReplaceWithHtml(html)
|
||||
// // Replace the node
|
||||
// sel.ReplaceWithHtml(html)
|
||||
}
|
||||
|
||||
func (parser *TemplateParser) transElementNode(sel *goquery.Selection) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue