-
Notifications
You must be signed in to change notification settings - Fork 657
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #460 from trheyi/main
[add] SUI & Page Builder API (10%)
- Loading branch information
Showing
17 changed files
with
663 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package core | ||
|
||
import ( | ||
"github.com/yaoapp/gou/application" | ||
) | ||
|
||
// Load load the dsl | ||
func Load(file string, id string) (*DSL, error) { | ||
|
||
data, err := application.App.Read(file) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
dsl := DSL{} | ||
err = application.Parse(file, data, &dsl) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &dsl, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package core | ||
|
||
// ITemplate is the interface for the ITemplate | ||
type ITemplate interface { | ||
Get() error | ||
Save() error | ||
|
||
Pages() ([]IPage, error) | ||
Blocks() ([]IBlock, error) | ||
Components() ([]IComponent, error) | ||
|
||
Page(route string) (IPage, error) | ||
Block(name string) (IBlock, error) | ||
Component(name string) (IComponent, error) | ||
|
||
Styles() []string | ||
Locales() []string | ||
Themes() []string | ||
} | ||
|
||
// IPage is the interface for the page | ||
type IPage interface { | ||
Get() error | ||
Save() error | ||
|
||
// Render() | ||
|
||
// Html() | ||
// Script() | ||
// Style() | ||
// Data() | ||
|
||
// Compile() | ||
// Locale() | ||
} | ||
|
||
// IBlock is the interface for the block | ||
type IBlock interface { | ||
Get() error | ||
Save() error | ||
} | ||
|
||
// IComponent is the interface for the component | ||
type IComponent interface { | ||
Get() error | ||
Save() error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package core | ||
|
||
// SUI is the interface for the SUI | ||
type SUI interface { | ||
GetTemplates() ([]ITemplate, error) | ||
GetTemplate(name string) (ITemplate, error) | ||
UploadTemplate(src string, dst string) (ITemplate, error) | ||
} | ||
|
||
// Page is the struct for the page | ||
type Page struct { | ||
template *Template | ||
route string | ||
file string | ||
} | ||
|
||
// Component is the struct for the component | ||
type Component struct { | ||
templage *Template | ||
name string | ||
} | ||
|
||
// Block is the struct for the block | ||
type Block struct { | ||
template *Template | ||
name string | ||
} | ||
|
||
// Template is the struct for the template | ||
type Template struct { | ||
Version int `json:"version"` // Yao Builder version | ||
ID string `json:"id"` | ||
Name string `json:"name"` | ||
Descrption string `json:"description"` | ||
Screenshots []string `json:"screenshots"` | ||
} | ||
|
||
// DSL the struct for the DSL | ||
type DSL struct { | ||
ID string `json:"-"` | ||
Name string `json:"name,omitempty"` | ||
Storage *Storage `json:"storage,omitempty"` | ||
Public *Public `json:"public,omitempty"` | ||
} | ||
|
||
// Public is the struct for the static | ||
type Public struct { | ||
Host string `json:"host,omitempty"` | ||
Root string `json:"root,omitempty"` | ||
Index string `json:"index,omitempty"` | ||
} | ||
|
||
// Storage is the struct for the storage | ||
type Storage struct { | ||
Driver string `json:"driver"` | ||
Option map[string]interface{} `json:"option,omitempty"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package azure | ||
|
||
import ( | ||
"fmt" | ||
"net/url" | ||
|
||
"github.com/yaoapp/yao/sui/core" | ||
) | ||
|
||
// Remote is the struct for the azure sui | ||
type Remote struct{ url url.URL } | ||
|
||
// new create a new azure sui | ||
func new(host url.URL) (*Remote, error) { | ||
return &Remote{url: host}, nil | ||
} | ||
|
||
// New create a new azure sui | ||
func New(dsl *core.DSL) (*Remote, error) { | ||
|
||
if dsl.Storage.Option == nil { | ||
return nil, fmt.Errorf("option.host is required") | ||
} | ||
|
||
if dsl.Storage.Option["host"] == nil { | ||
return nil, fmt.Errorf("option.host is required") | ||
} | ||
|
||
host, ok := dsl.Storage.Option["host"].(string) | ||
if !ok { | ||
return nil, fmt.Errorf("option.host %s is not a valid string", host) | ||
} | ||
|
||
u, err := url.Parse(host) | ||
if err != nil { | ||
return nil, fmt.Errorf("option.host %s is not a valid url", host) | ||
} | ||
|
||
return new(*u) | ||
} | ||
|
||
// GetTemplates get the templates | ||
func (azure *Remote) GetTemplates() ([]core.ITemplate, error) { | ||
return nil, nil | ||
} | ||
|
||
// GetTemplate get the template | ||
func (azure *Remote) GetTemplate(name string) (core.ITemplate, error) { | ||
return nil, nil | ||
} | ||
|
||
// UploadTemplate upload the template | ||
func (azure *Remote) UploadTemplate(src string, dst string) (core.ITemplate, error) { | ||
return nil, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package local | ||
|
||
// NewBlock create a new local block | ||
func NewBlock(file string) (*Block, error) { | ||
return nil, nil | ||
} | ||
|
||
// Get get the block | ||
func (block *Block) Get() error { | ||
return nil | ||
} | ||
|
||
// Save save the block | ||
func (block *Block) Save() error { | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package local | ||
|
||
// NewComponent create a new local component | ||
func NewComponent(file string) (*Component, error) { | ||
return nil, nil | ||
} | ||
|
||
// Get get the component | ||
func (comp *Component) Get() error { | ||
return nil | ||
} | ||
|
||
// Save save the component | ||
func (comp *Component) Save() error { | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package local | ||
|
||
import ( | ||
"github.com/yaoapp/gou/fs" | ||
"github.com/yaoapp/kun/log" | ||
sui "github.com/yaoapp/yao/sui/core" | ||
) | ||
|
||
// New create a new local sui | ||
func New(dsl *sui.DSL) (*Local, error) { | ||
|
||
templateRoot := "/data/sui/templates" | ||
if dsl.Storage.Option != nil && dsl.Storage.Option["root"] != nil { | ||
templateRoot = dsl.Storage.Option["root"].(string) | ||
} | ||
|
||
root := "/" | ||
host := "/" | ||
index := "/index" | ||
if dsl.Public != nil { | ||
if dsl.Public.Root != "" { | ||
root = dsl.Public.Root | ||
} | ||
|
||
if dsl.Public.Host != "" { | ||
host = dsl.Public.Host | ||
} | ||
|
||
if dsl.Public.Index != "" { | ||
index = dsl.Public.Index | ||
} | ||
} | ||
|
||
dataFS, err := fs.Get("system") | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
dsl.Public = &sui.Public{ | ||
Host: host, | ||
Root: root, | ||
Index: index, | ||
} | ||
|
||
return &Local{ | ||
root: templateRoot, | ||
fs: dataFS, | ||
DSL: dsl, | ||
}, nil | ||
} | ||
|
||
// GetTemplates get the templates | ||
func (local *Local) GetTemplates() ([]sui.ITemplate, error) { | ||
|
||
templates := []sui.ITemplate{} | ||
dirs, err := local.fs.ReadDir(local.root, false) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for _, dir := range dirs { | ||
if !local.fs.IsDir(dir) { | ||
continue | ||
} | ||
|
||
tmpl, err := local.NewTemplate(dir) | ||
if err != nil { | ||
log.Error("GetTemplates %s error: %s", dir, err.Error()) | ||
continue | ||
} | ||
templates = append(templates, tmpl) | ||
} | ||
|
||
return templates, nil | ||
} | ||
|
||
// GetTemplate get the template | ||
func (local *Local) GetTemplate(name string) (sui.ITemplate, error) { | ||
return nil, nil | ||
} | ||
|
||
// UploadTemplate upload the template | ||
func (local *Local) UploadTemplate(src string, dst string) (sui.ITemplate, error) { | ||
return nil, nil | ||
} |
Oops, something went wrong.