Skip to content

Commit

Permalink
Merge 3239445 into 1dc9b8c
Browse files Browse the repository at this point in the history
  • Loading branch information
hcpss-banderson committed Feb 7, 2019
2 parents 1dc9b8c + 3239445 commit a9ec071
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
15 changes: 15 additions & 0 deletions README.md
Expand Up @@ -202,6 +202,7 @@ If a panic occurs inside a gtf function, the function will silently swallow the
### Index

* [replace](#replace)
* [findreplace](#findreplace)
* [default](#default)
* [length](#length)
* [lower](#lower)
Expand Down Expand Up @@ -245,6 +246,20 @@ If value is "The Go Programming Language", the output will be "TheGoProgrammingL



#### findreplace

Replaces all instances of the first argument with the second.

* supported value types : string
* supported argument types : string

```
{{ value | findreplace " " "-" }}
```
If value is "The Go Programming Language", the output will be "The-Go-Programming-Language".



#### default

1. If the given string is ""(empty string), uses the given default argument.
Expand Down
5 changes: 5 additions & 0 deletions gtf.go
Expand Up @@ -26,6 +26,11 @@ var GtfTextFuncMap = textTemplate.FuncMap{

return strings.Replace(s2, s1, "", -1)
},
"findreplace": func(s1 string, s2 string, s3 string) string {
defer recovery()

return strings.Replace(s3, s1, s2, -1)
},
"title": func(s string) string {
defer recovery()
return strings.Title(s)
Expand Down
3 changes: 3 additions & 0 deletions gtf_test.go
Expand Up @@ -43,6 +43,9 @@ func TestGtfFuncMap(t *testing.T) {
ParseTest(&buffer, "{{ \"The Go Programming Language\" | replace \" \" }}", "")
AssertEqual(t, &buffer, "TheGoProgrammingLanguage")

ParseTest(&buffer, "{{ \"The Go Programming Language\" | findreplace \" \" \"X\" }}", "")
AssertEqual(t, &buffer, "TheXGoXProgrammingXLanguage")

ParseTest(&buffer, "{{ \"the go programming language\" | title }}", "")
AssertEqual(t, &buffer, "The Go Programming Language")

Expand Down
3 changes: 3 additions & 0 deletions gtf_text_test.go
Expand Up @@ -18,6 +18,9 @@ func TestTextTemplateGtfFuncMap(t *testing.T) {
TextTemplateParseTest(&buffer, "{{ \"The Go Programming Language\" | replace \" \" }}", "")
AssertEqual(t, &buffer, "TheGoProgrammingLanguage")

TextTemplateParseTest(&buffer, "{{ \"The Go Programming Language\" | findreplace \" \" \"X\" }}", "")
AssertEqual(t, &buffer, "TheXGoXProgrammingXLanguage")

TextTemplateParseTest(&buffer, "{{ \"The Go Programming Language\" | length }}", "")
AssertEqual(t, &buffer, "27")

Expand Down

0 comments on commit a9ec071

Please sign in to comment.