Skip to content

Commit

Permalink
[add] SUI & Page Builder API (10%)
Browse files Browse the repository at this point in the history
  • Loading branch information
trheyi committed Sep 24, 2023
1 parent d4695e7 commit 198fd88
Show file tree
Hide file tree
Showing 17 changed files with 663 additions and 7 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/pr-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ env:
## Path
YAO_TEST_APPLICATION: ${{ github.WORKSPACE }}/../app
YAO_EXTENSION_ROOT: ${{ github.WORKSPACE }}/../extension
YAO_TEST_BUILDER_APPLICATION: ${{ github.WORKSPACE }}/../page-builder-app

## Runtime
YAO_RUNTIME_MIN: 3
Expand Down Expand Up @@ -159,6 +160,13 @@ jobs:
repository: yaoapp/yao-dev-app
path: app

- name: Checkout Page Builder App
uses: actions/checkout@v3
with:
repository: yaoapp/page-builder-app
token: ${{ secrets.YAO_TEST_TOKEN }}
path: page-builder-app

- name: Checkout Extension
uses: actions/checkout@v3
with:
Expand All @@ -173,6 +181,7 @@ jobs:
mv v8go ../
mv app ../
mv extension ../
mv page-builder-app ../
ls -l .
ls -l ../
Expand Down
11 changes: 10 additions & 1 deletion .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ env:
## Path
YAO_TEST_APPLICATION: ${{ github.WORKSPACE }}/../app
YAO_EXTENSION_ROOT: ${{ github.WORKSPACE }}/../extension

YAO_TEST_BUILDER_APPLICATION: ${{ github.WORKSPACE }}/../page-builder-app

## Runtime
YAO_RUNTIME_MIN: 3
YAO_RUNTIME_MAX: 6
Expand Down Expand Up @@ -116,6 +117,13 @@ jobs:
repository: yaoapp/yao-dev-app
path: app

- name: Checkout Page Builder App
uses: actions/checkout@v3
with:
repository: yaoapp/page-builder-app
token: ${{ secrets.YAO_TEST_TOKEN }}
path: page-builder-app

- name: Checkout Extension
uses: actions/checkout@v3
with:
Expand All @@ -130,6 +138,7 @@ jobs:
mv v8go ../
mv app ../
mv extension ../
mv page-builder-app ../
ls -l .
ls -l ../
Expand Down
3 changes: 2 additions & 1 deletion service/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ func TestStartStop(t *testing.T) {
if err != nil {
t.Fatal(err)
}
assert.Equal(t, "Demo Application", data["name"])
// assert.Equal(t, "Demo Application", data["name"])
assert.True(t, len(data["name"].(string)) > 0)

// Public
req = test.NewRequest(port).Route("/")
Expand Down
22 changes: 22 additions & 0 deletions sui/core/core.go
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
}
47 changes: 47 additions & 0 deletions sui/core/interfaces.go
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
}
57 changes: 57 additions & 0 deletions sui/core/types.go
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"`
}
55 changes: 55 additions & 0 deletions sui/storages/azure/azure.go
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
}
16 changes: 16 additions & 0 deletions sui/storages/local/block.go
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
}
16 changes: 16 additions & 0 deletions sui/storages/local/component.go
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
}
85 changes: 85 additions & 0 deletions sui/storages/local/local.go
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
}
Loading

0 comments on commit 198fd88

Please sign in to comment.