Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[add] sui page build Add default Sid if not set #509

Merged
merged 1 commit into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions sui/core/editor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
4 changes: 4 additions & 0 deletions sui/core/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions sui/core/page.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package core

import (
"fmt"
"path/filepath"
"strings"

Expand All @@ -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 {

Expand Down
5 changes: 5 additions & 0 deletions sui/core/sui.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions sui/storages/local/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down