Skip to content

Commit

Permalink
Merge pull request #24 from gcp-kit/issue/23/main
Browse files Browse the repository at this point in the history
[]stringの場合も置換するようにした
  • Loading branch information
moezakura authored May 9, 2022
2 parents c232a92 + 0196619 commit 8cf23f8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
29 changes: 29 additions & 0 deletions pkg/inserter/common_inserter.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,35 @@ func (c *CommonInserter) setRefs(item map[string]interface{}) map[string]interfa
reg := regexp.MustCompile(`\#\{.*?\}`)
for k, v := range item {
switch vt := v.(type) {
case []interface{}:
new := make([]string, len(vt))
isStr := true
for i, vtv := range vt {
vStr, ok := vtv.(string)
if !ok {
isStr = false
break
}
if strings.HasPrefix(vStr, "$") && !reg.MatchString(vStr) {
refID := strings.TrimPrefix(vStr, "$")
rv, ok := c.refIDs[refID]
if !ok {
log.Printf("%s was not found", refID)
} else {
new[i] = rv
}
continue
}
n := c.replaceMultiRefs(vStr, reg)
if n != "" {
new[i] = n
continue
}
new[i] = vStr
}
if isStr {
item[k] = new
}
case map[string]interface{}:
for vtk, vtv := range vt {
if strings.HasPrefix(vtk, "$") && !reg.MatchString(vtk) {
Expand Down
3 changes: 3 additions & 0 deletions samples/Survey/dummies.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
payload: {
defaultOption: "$Option__dummy_0",
optionsText: "/#{Option__dummy_0}/#{Option__dummy_0}/",
optionsArray: ["$Option__dummy_0", "#{Option__dummy_1}(default)"],
point: [10, 30],
postText: ["10", "30"],
options: {
$Option__dummy_0: true,
$Option__dummy_1: true,
Expand Down

0 comments on commit 8cf23f8

Please sign in to comment.