Refactor SUI core to load backend scripts for templates
This commit is contained in:
parent
58ca39a32b
commit
fe247d1e28
3 changed files with 11 additions and 10 deletions
|
|
@ -650,12 +650,16 @@ func (page *Page) BuildScripts(ctx *BuildContext, option *BuildOption, component
|
|||
code := string(source)
|
||||
if constants != "" {
|
||||
code = fmt.Sprintf("this.Constants = %s\n%s", constants, code)
|
||||
|
||||
}
|
||||
|
||||
parent := "body"
|
||||
if !ispage {
|
||||
parent = "head"
|
||||
code = fmt.Sprintf("function %s(){\n%s\n}\n", component, addTabToEachLine(code))
|
||||
if constants != "" {
|
||||
fmt.Println("page.Script.ConstantsToString", page.Route)
|
||||
}
|
||||
}
|
||||
|
||||
scripts = append(scripts, ScriptNode{
|
||||
|
|
|
|||
|
|
@ -354,11 +354,6 @@ func (page *Page) Build(globalCtx *core.GlobalBuildContext, option *core.BuildOp
|
|||
}
|
||||
page.Root = root
|
||||
|
||||
err = page.loadBackendScript()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
html, warnings, err := page.Page.Compile(ctx, option)
|
||||
if err != nil {
|
||||
return warnings, fmt.Errorf("Compile the page %s error: %s", page.Route, err.Error())
|
||||
|
|
@ -431,11 +426,6 @@ func (page *Page) BuildAsComponent(globalCtx *core.GlobalBuildContext, option *c
|
|||
option.AssetRoot = filepath.Join(root, "assets")
|
||||
}
|
||||
|
||||
err := page.loadBackendScript()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
html, messages, err := page.Page.CompileAsComponent(ctx, option)
|
||||
if err != nil {
|
||||
return warnings, err
|
||||
|
|
|
|||
|
|
@ -453,6 +453,13 @@ func (page *Page) Load() error {
|
|||
|
||||
// Set the page global data
|
||||
page.GlobalData = page.tmpl.GlobalData
|
||||
|
||||
// Load the backend script
|
||||
err := page.loadBackendScript()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue