Skip to content

Commit

Permalink
Merge pull request #509 from trheyi/main
Browse files Browse the repository at this point in the history
[add] sui page build Add default Sid if not set
  • Loading branch information
trheyi authored Dec 6, 2023
2 parents 3a44464 + a5f4764 commit 03f63b7
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 0 deletions.
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

0 comments on commit 03f63b7

Please sign in to comment.