-
Notifications
You must be signed in to change notification settings - Fork 660
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
108 additions
and
28 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 |
---|---|---|
@@ -1,26 +1,44 @@ | ||
package local | ||
|
||
// Get get the template | ||
func (tmpl *Template) Get() error { | ||
return nil | ||
} | ||
import ( | ||
"path/filepath" | ||
|
||
// Save save the template | ||
func (tmpl *Template) Save() error { | ||
return nil | ||
} | ||
"github.com/yaoapp/yao/sui/core" | ||
"golang.org/x/text/language" | ||
) | ||
|
||
// Styles get the global styles | ||
func (tmpl *Template) Styles() []string { | ||
// Assets get the assets treelist | ||
func (tmpl *Template) Assets() []string { | ||
return nil | ||
} | ||
|
||
// Locales get the global locales | ||
func (tmpl *Template) Locales() []string { | ||
return nil | ||
func (tmpl *Template) Locales() []core.SelectOption { | ||
|
||
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 | ||
func (tmpl *Template) Themes() []string { | ||
return nil | ||
func (tmpl *Template) Themes() []core.SelectOption { | ||
return tmpl.Template.Themes | ||
} |
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 |
---|---|---|
@@ -1 +1,51 @@ | ||
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) | ||
} |