From a5f4764a0c40825cf6b2cf9e63f7b1d2cfd4899a Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 6 Dec 2023 13:45:06 +0800 Subject: [PATCH] [add] sui page build Add default Sid if not set --- sui/core/editor.go | 5 +++++ sui/core/interfaces.go | 4 ++++ sui/core/page.go | 19 +++++++++++++++++++ sui/core/sui.go | 5 +++++ sui/storages/local/build.go | 1 + 5 files changed, 34 insertions(+) diff --git a/sui/core/editor.go b/sui/core/editor.go index 78c94023a..a129cae24 100644 --- a/sui/core/editor.go +++ b/sui/core/editor.go @@ -35,6 +35,11 @@ func (page *Page) EditorRender() (*ResponseEditorRender, error) { // Render the page request := NewRequestMock(page.Config.Mock) + // Set Default Sid + if request.Sid == "" { + request.Sid, _ = page.Sid() + } + // Render tools // res.Scripts = append(res.Scripts, filepath.Join("@assets", "__render.js")) // res.Styles = append(res.Styles, filepath.Join("@assets", "__render.css")) diff --git a/sui/core/interfaces.go b/sui/core/interfaces.go index 2e11dfa14..4d28df0c6 100644 --- a/sui/core/interfaces.go +++ b/sui/core/interfaces.go @@ -25,6 +25,7 @@ type SUI interface { GetTemplate(name string) (ITemplate, error) UploadTemplate(src string, dst string) (ITemplate, error) WithSid(sid string) + GetSid() string PublicRootMatcher() *Matcher GetPublic() *Public PublicRootWithSid(sid string) (string, error) @@ -65,6 +66,9 @@ type ITemplate interface { type IPage interface { Load() error + SUI() (SUI, error) + Sid() (string, error) + Get() *Page GetConfig() *PageConfig Save(request *RequestSource) error diff --git a/sui/core/page.go b/sui/core/page.go index 942ee1334..8680b3ea1 100644 --- a/sui/core/page.go +++ b/sui/core/page.go @@ -1,6 +1,7 @@ package core import ( + "fmt" "path/filepath" "strings" @@ -14,6 +15,24 @@ func (page *Page) Get() *Page { return page } +// SUI get the sui +func (page *Page) SUI() (SUI, error) { + sui, has := SUIs[page.SuiID] + if !has { + return nil, fmt.Errorf("[sui] get page sui %s not found", page.SuiID) + } + return sui, nil +} + +// Sid get the sid +func (page *Page) Sid() (string, error) { + sui, err := page.SUI() + if err != nil { + return "", err + } + return sui.GetSid(), nil +} + // GetConfig get the config func (page *Page) GetConfig() *PageConfig { diff --git a/sui/core/sui.go b/sui/core/sui.go index 5632740b4..7c989c5a5 100644 --- a/sui/core/sui.go +++ b/sui/core/sui.go @@ -28,6 +28,11 @@ func (sui *DSL) WithSid(sid string) { sui.Sid = sid } +// GetSid returns the sid +func (sui *DSL) GetSid() string { + return sui.Sid +} + // PublicRootMatcher returns the public root matcher func (sui *DSL) PublicRootMatcher() *Matcher { pub := sui.GetPublic() diff --git a/sui/storages/local/build.go b/sui/storages/local/build.go index bc598cb5c..73a4e5c00 100644 --- a/sui/storages/local/build.go +++ b/sui/storages/local/build.go @@ -84,6 +84,7 @@ func (page *Page) Build(option *core.BuildOption) error { option.AssetRoot = filepath.Join(page.tmpl.local.DSL.Public.Root, "assets") } + log.Trace("Build the page %s AssetRoot: %s", page.Route, option.AssetRoot) html, err := page.Page.Compile(option) if err != nil { return err