diff --git a/sui/api/render.go b/sui/api/render.go index 06f2ac23..8c5acf6d 100644 --- a/sui/api/render.go +++ b/sui/api/render.go @@ -164,7 +164,7 @@ func TemplateRender(process *process.Process) interface{} { source := process.ArgsString(2) page := tmpl.CreatePage(source) route := page.Get().Route - globalCtx := core.NewGlobalBuildContext() + globalCtx := core.NewGlobalBuildContext(tmpl) suicode, _, err := page.Get().CompileAsComponent(core.NewBuildContext(globalCtx), &core.BuildOption{ PublicRoot: root, AssetRoot: assetRoot, diff --git a/sui/core/compile.go b/sui/core/compile.go index 9e847486..2d2d36b2 100644 --- a/sui/core/compile.go +++ b/sui/core/compile.go @@ -89,8 +89,27 @@ func (page *Page) Compile(ctx *BuildContext, option *BuildOption) (string, strin } // Page Components - if ctx != nil && ctx.components != nil && len(ctx.components) > 0 { - rawComponents, _ := jsoniter.MarshalToString(ctx.components) + if ctx != nil { + components := map[string]string{} + for _, component := range ctx.GetComponents() { + components[component] = component + } + + // Add Jit Components + if ctx.global != nil && ctx.global.tmpl != nil { + patterns := ctx.GetJitComponents() + + // Get all pages + routes, err := ctx.global.tmpl.GlobRoutes(patterns, true) + if err != nil { + return "", "", warnings, fmt.Errorf("Get jit components error: %s", err.Error()) + } + for _, route := range routes { + components[route] = route + } + } + + rawComponents, _ := jsoniter.MarshalToString(components) body.AppendHtml("\n\n" + `\n\n") } diff --git a/sui/core/context.go b/sui/core/context.go index 7e8fd02a..7e77e32e 100644 --- a/sui/core/context.go +++ b/sui/core/context.go @@ -26,9 +26,10 @@ func NewTranslateContext() *TranslateContext { } // NewGlobalBuildContext create a new global build context -func NewGlobalBuildContext() *GlobalBuildContext { +func NewGlobalBuildContext(tmpl ITemplate) *GlobalBuildContext { return &GlobalBuildContext{ jitComponents: map[string]bool{}, + tmpl: tmpl, } } diff --git a/sui/core/data.go b/sui/core/data.go index da191fb4..875af4be 100644 --- a/sui/core/data.go +++ b/sui/core/data.go @@ -187,6 +187,7 @@ func (data Data) ReplaceUse(tokens Tokens, value string) (string, []StringValue) values = append(values, v) return v.Value }) + return res, values } diff --git a/sui/core/interfaces.go b/sui/core/interfaces.go index 59eb5ddd..7338d0d9 100644 --- a/sui/core/interfaces.go +++ b/sui/core/interfaces.go @@ -69,6 +69,8 @@ type ITemplate interface { ExecAfterBuildScripts() []TemplateScirptResult Trans(option *BuildOption) ([]string, error) + + GlobRoutes(patterns []string, unique ...bool) ([]string, error) } // IPage is the interface for the page diff --git a/sui/core/parser.go b/sui/core/parser.go index f4ff30da..5c312564 100644 --- a/sui/core/parser.go +++ b/sui/core/parser.go @@ -292,7 +292,7 @@ func (parser *TemplateParser) parseElementNode(sel *goquery.Selection) { func (parser *TemplateParser) parseElementComponent(sel *goquery.Selection) { parser.parsed(sel) - com := sel.AttrOr("s:cn", "") + com := sel.AttrOr("s:route", "") props := map[string]interface{}{} for _, attr := range sel.Nodes[0].Attr { if strings.HasPrefix(attr.Key, "prop:") { diff --git a/sui/core/token.go b/sui/core/token.go index 360d1668..14788df0 100644 --- a/sui/core/token.go +++ b/sui/core/token.go @@ -6,7 +6,7 @@ import ( var propTokens = Tokens{ {start: "{%", end: "%}"}, // {% xxx %} - {start: "[{", end: "}]"}, // [{ xxx }] + // {start: "[{", end: "}]"}, // [{ xxx }] Deprecated } var dataTokens = Tokens{ diff --git a/sui/storages/local/build.go b/sui/storages/local/build.go index 1f91cf70..72adda87 100644 --- a/sui/storages/local/build.go +++ b/sui/storages/local/build.go @@ -68,7 +68,7 @@ func (tmpl *Template) Build(option *core.BuildOption) ([]string, error) { } // Build all pages - ctx := core.NewGlobalBuildContext() + ctx := core.NewGlobalBuildContext(tmpl) pages, err := tmpl.Pages() if err != nil { return warnings, err @@ -149,7 +149,7 @@ func (tmpl *Template) Trans(option *core.BuildOption) ([]string, error) { var err error warnings := []string{} - ctx := core.NewGlobalBuildContext() + ctx := core.NewGlobalBuildContext(tmpl) pages, err := tmpl.Pages() if err != nil { return warnings, err