Skip to content

Commit

Permalink
add replace function
Browse files Browse the repository at this point in the history
  • Loading branch information
ixre committed May 4, 2020
1 parent 87532f8 commit 19e315f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ Usage of tto:
```
{{equal (3%2) 1}
```
替换, 如将`table_name`替换为:`table-name`
```
{{replace "table_name" "_" "-"}}
```
包含函数
```
{{contain .table.Pk "id"}}
Expand Down
2 changes: 1 addition & 1 deletion const.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package tto

// 版本号
const BuildVersion = "0.3.14"
const BuildVersion = "0.3.15"
7 changes: 7 additions & 0 deletions template_func.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ func (t *internalFunc) funcMap() ht.FuncMap {
fm["default"] = t.langDefaultValue
// 是否相等,如:{{equal "go" "rust"}
fm["equal"] = t.equal
// 替换,如: {{replace "table_name" "_" "-"}}
fm["replace"] = t.replace
// 包含函数, 如:{{contain .table.Pk "id"}}
fm["contain"] = t.contain
// 是否以指定字符开始, 如:{{starts_with .table.Pk "id"}}
Expand Down Expand Up @@ -116,6 +118,11 @@ func (t *internalFunc) equal(v1, v2 interface{}) bool {
return v1 == v2
}

// 替换,如: {{replace "table_name" "_" "-"}}
func (t *internalFunc) replace(s,oldStr,newStr string) string {
return strings.Replace(s,oldStr,newStr,-1)
}

// 是否包含
func (t *internalFunc) contain(v interface{}, s string) bool {
if v == nil {
Expand Down

0 comments on commit 19e315f

Please sign in to comment.