Skip to content

Commit

Permalink
Merge pull request #5 from koreset/master
Browse files Browse the repository at this point in the history
Added title template function
  • Loading branch information
leekchan committed Apr 16, 2018
2 parents 08ecefa + de593f3 commit 79e3a68
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions gtf.go
Expand Up @@ -26,6 +26,10 @@ var GtfTextFuncMap = textTemplate.FuncMap{

return strings.Replace(s2, s1, "", -1)
},
"title": func(s string) string {
defer recovery()
return strings.Title(s)
},
"default": func(arg interface{}, value interface{}) interface{} {
defer recovery()

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

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

ParseTest(&buffer, "{{ \"The Go Programming Language\" | default \"default value\" }}", "")
AssertEqual(t, &buffer, "The Go Programming Language")

Expand Down

0 comments on commit 79e3a68

Please sign in to comment.