[add] widget table env default value support
This commit is contained in:
parent
ef1866e7ea
commit
fb19e8d288
4 changed files with 25 additions and 7 deletions
1
.github/workflows/pr-test.yml
vendored
1
.github/workflows/pr-test.yml
vendored
|
|
@ -41,6 +41,7 @@ env:
|
|||
TAB_NAME: "::PET ADMIN"
|
||||
PAGE_SIZE: "20"
|
||||
PAGE_LINK: "https://yaoapps.com"
|
||||
PAGE_ICON: "icon-trash"
|
||||
|
||||
DEMO_APP: ${{ github.WORKSPACE }}/../app
|
||||
|
||||
|
|
|
|||
1
.github/workflows/unit-test.yml
vendored
1
.github/workflows/unit-test.yml
vendored
|
|
@ -45,6 +45,7 @@ env:
|
|||
TAB_NAME: "::PET ADMIN"
|
||||
PAGE_SIZE: "20"
|
||||
PAGE_LINK: "https://yaoapps.com"
|
||||
PAGE_ICON: "icon-trash"
|
||||
|
||||
DEMO_APP: ${{ github.WORKSPACE }}/../app
|
||||
|
||||
|
|
|
|||
|
|
@ -52,21 +52,36 @@ func replaceAny(value interface{}, defaults map[string]interface{}) interface{}
|
|||
|
||||
func replaceStr(value string, defaults map[string]interface{}) interface{} {
|
||||
|
||||
if strings.HasPrefix(value, "\\$$ENV.") {
|
||||
return fmt.Sprintf("$ENV.%s", strings.TrimLeft(value, "\\$$ENV."))
|
||||
v := strings.TrimSpace(value)
|
||||
if strings.HasPrefix(v, "\\$$ENV.") {
|
||||
return fmt.Sprintf("$ENV.%s", strings.TrimLeft(v, "\\$$ENV."))
|
||||
}
|
||||
|
||||
if !strings.HasPrefix(value, "$ENV.") {
|
||||
if !strings.HasPrefix(v, "$ENV.") {
|
||||
return value
|
||||
}
|
||||
|
||||
name := strings.TrimLeft(value, "$ENV.")
|
||||
return getEnv(v, defaults)
|
||||
}
|
||||
|
||||
func getEnv(value string, defaults map[string]interface{}) interface{} {
|
||||
|
||||
vars := strings.Split(value, "||")
|
||||
name := strings.TrimLeft(strings.TrimSpace(vars[0]), "$ENV.")
|
||||
v := os.Getenv(name)
|
||||
if v != "" {
|
||||
return v
|
||||
}
|
||||
|
||||
return defaults[name]
|
||||
if len(vars) > 1 {
|
||||
v = strings.TrimSpace(vars[1])
|
||||
}
|
||||
|
||||
if v == "" {
|
||||
return defaults[name]
|
||||
}
|
||||
|
||||
return v
|
||||
}
|
||||
|
||||
func replaceMap(values map[string]interface{}, defaults map[string]interface{}) map[string]interface{} {
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ func TestReadFile(t *testing.T) {
|
|||
assert.Equal(t, "::PET ADMIN", res.Get("name"))
|
||||
assert.Equal(t, "20", res.Get("action.search.default.2"))
|
||||
assert.Equal(t, "https://yaoapps.com", res.Get("layout.header.preset.import.operation.0.link"))
|
||||
assert.Equal(t, "cured", res.Get("layout.table.operation.actions.2.action.Table.save.status"))
|
||||
|
||||
assert.Equal(t, "cured", res.Get("layout.table.operation.actions[2].action.Table.save.status"))
|
||||
assert.Equal(t, "提示", res["layout.table.operation.actions[5].confirm.title"])
|
||||
assert.Equal(t, "icon-trash", res["layout.table.operation.actions[5].icon"])
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue