Skip to content

Commit

Permalink
Move example into its own file.
Browse files Browse the repository at this point in the history
  • Loading branch information
technosophos committed Mar 30, 2016
1 parent d8a0cc3 commit f695184
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
25 changes: 25 additions & 0 deletions example_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package sprig

import (
"fmt"
"os"
"text/template"
)

func Example() {
// Set up variables and template.
vars := map[string]interface{}{"Name": " John Jacob Jingleheimer Schmidt "}
tpl := `Hello {{.Name | trim | lower}}`

// Get the Sprig function map.
fmap := TxtFuncMap()
t := template.Must(template.New("test").Funcs(fmap).Parse(tpl))

err := t.Execute(os.Stdout, vars)
if err != nil {
fmt.Printf("Error during template execution: %s", err)
return
}
// Output:
// Hello john jacob jingleheimer schmidt
}
16 changes: 0 additions & 16 deletions functions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,6 @@ import (
"github.com/aokoli/goutils"
)

func Example() {
vars := map[string]interface{}{"Name": " John Jacob Jingleheimer Schmidt "}
tpl := `Hello {{.Name | trim | lower}}`
fmap := TxtFuncMap()
t := template.Must(template.New("test").Funcs(fmap).Parse(tpl))
var b bytes.Buffer
err := t.Execute(&b, vars)
if err != nil {
fmt.Printf("Error during template execution: %s", err)
return
}
fmt.Println(b.String())
// Output:
// Hello john jacob jingleheimer schmidt
}

// This is woefully incomplete. Please help.

func TestSubstr(t *testing.T) {
Expand Down

0 comments on commit f695184

Please sign in to comment.