commit
6f7440dcda
5 changed files with 108 additions and 28 deletions
|
|
@ -2,20 +2,18 @@ package core
|
||||||
|
|
||||||
// ITemplate is the interface for the ITemplate
|
// ITemplate is the interface for the ITemplate
|
||||||
type ITemplate interface {
|
type ITemplate interface {
|
||||||
Get() error
|
|
||||||
Save() error
|
|
||||||
|
|
||||||
Pages() ([]IPage, error)
|
Pages() ([]IPage, error)
|
||||||
Blocks() ([]IBlock, error)
|
|
||||||
Components() ([]IComponent, error)
|
|
||||||
|
|
||||||
Page(route string) (IPage, error)
|
Page(route string) (IPage, error)
|
||||||
|
|
||||||
|
Blocks() ([]IBlock, error)
|
||||||
Block(name string) (IBlock, error)
|
Block(name string) (IBlock, error)
|
||||||
|
|
||||||
|
Components() ([]IComponent, error)
|
||||||
Component(name string) (IComponent, error)
|
Component(name string) (IComponent, error)
|
||||||
|
|
||||||
Styles() []string
|
Assets() []string
|
||||||
Locales() []string
|
Locales() []SelectOption
|
||||||
Themes() []string
|
Themes() []SelectOption
|
||||||
}
|
}
|
||||||
|
|
||||||
// IPage is the interface for the page
|
// IPage is the interface for the page
|
||||||
|
|
|
||||||
|
|
@ -41,11 +41,24 @@ type Block struct {
|
||||||
|
|
||||||
// Template is the struct for the template
|
// Template is the struct for the template
|
||||||
type Template struct {
|
type Template struct {
|
||||||
Version int `json:"version"` // Yao Builder version
|
Version int `json:"version"` // Yao Builder version
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Descrption string `json:"description"`
|
Descrption string `json:"description"`
|
||||||
Screenshots []string `json:"screenshots"`
|
Screenshots []string `json:"screenshots"`
|
||||||
|
Themes []SelectOption `json:"themes"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Theme is the struct for the theme
|
||||||
|
type Theme struct {
|
||||||
|
ID string `json:"id"`
|
||||||
|
Name string `json:"name,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// SelectOption is the struct for the select option
|
||||||
|
type SelectOption struct {
|
||||||
|
Label string `json:"label"`
|
||||||
|
Value string `json:"value"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// SourceCodes is the struct for the page codes
|
// SourceCodes is the struct for the page codes
|
||||||
|
|
|
||||||
|
|
@ -113,6 +113,7 @@ func (local *Local) getTemplate(id string, path string) (*Template, error) {
|
||||||
Name: strings.ToUpper(id),
|
Name: strings.ToUpper(id),
|
||||||
Version: 1,
|
Version: 1,
|
||||||
Screenshots: []string{},
|
Screenshots: []string{},
|
||||||
|
Themes: []core.SelectOption{},
|
||||||
}}
|
}}
|
||||||
|
|
||||||
// load the template.json
|
// load the template.json
|
||||||
|
|
|
||||||
|
|
@ -1,26 +1,44 @@
|
||||||
package local
|
package local
|
||||||
|
|
||||||
// Get get the template
|
import (
|
||||||
func (tmpl *Template) Get() error {
|
"path/filepath"
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save save the template
|
"github.com/yaoapp/yao/sui/core"
|
||||||
func (tmpl *Template) Save() error {
|
"golang.org/x/text/language"
|
||||||
return nil
|
)
|
||||||
}
|
|
||||||
|
|
||||||
// Styles get the global styles
|
// Assets get the assets treelist
|
||||||
func (tmpl *Template) Styles() []string {
|
func (tmpl *Template) Assets() []string {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Locales get the global locales
|
// Locales get the global locales
|
||||||
func (tmpl *Template) Locales() []string {
|
func (tmpl *Template) Locales() []core.SelectOption {
|
||||||
return nil
|
|
||||||
|
supportLocales := []core.SelectOption{}
|
||||||
|
path := filepath.Join(tmpl.Root, "__locales")
|
||||||
|
if !tmpl.local.fs.IsDir(path) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
dirs, err := tmpl.local.fs.ReadDir(path, false)
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, dir := range dirs {
|
||||||
|
locale := filepath.Base(dir)
|
||||||
|
label := language.Make(locale).String()
|
||||||
|
supportLocales = append(supportLocales, core.SelectOption{
|
||||||
|
Value: locale,
|
||||||
|
Label: label,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return supportLocales
|
||||||
}
|
}
|
||||||
|
|
||||||
// Themes get the global themes
|
// Themes get the global themes
|
||||||
func (tmpl *Template) Themes() []string {
|
func (tmpl *Template) Themes() []core.SelectOption {
|
||||||
return nil
|
return tmpl.Template.Themes
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1 +1,51 @@
|
||||||
package local
|
package local
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestTemplateThemes(t *testing.T) {
|
||||||
|
tests := prepare(t)
|
||||||
|
defer clean()
|
||||||
|
|
||||||
|
tmpl, err := tests.Demo.GetTemplate("tech-blue")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("GetTemplate error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
themes := tmpl.Themes()
|
||||||
|
if len(themes) < 2 {
|
||||||
|
t.Fatalf("Themes error: %v", len(themes))
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.Equal(t, "dark", themes[0].Value)
|
||||||
|
assert.Equal(t, "暗色主题", themes[0].Label)
|
||||||
|
assert.Equal(t, "light", themes[1].Value)
|
||||||
|
assert.Equal(t, "明亮主题", themes[1].Label)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestTemplateLocales(t *testing.T) {
|
||||||
|
tests := prepare(t)
|
||||||
|
defer clean()
|
||||||
|
|
||||||
|
tmpl, err := tests.Demo.GetTemplate("tech-blue")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("GetTemplate error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
locales := tmpl.Locales()
|
||||||
|
if len(locales) < 3 {
|
||||||
|
t.Fatalf("Locales error: %v", len(locales))
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.Equal(t, "ar", locales[0].Label)
|
||||||
|
assert.Equal(t, "ar", locales[0].Value)
|
||||||
|
|
||||||
|
assert.Equal(t, "zh-CN", locales[1].Label)
|
||||||
|
assert.Equal(t, "zh-cn", locales[1].Value)
|
||||||
|
|
||||||
|
assert.Equal(t, "zh-TW", locales[2].Label)
|
||||||
|
assert.Equal(t, "zh-tw", locales[2].Value)
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue