dollarize the money
This commit is contained in:
parent
b0cda81247
commit
55ad067967
11
template.go
11
template.go
@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sync"
|
"sync"
|
||||||
@ -9,13 +10,21 @@ import (
|
|||||||
var cachedTemplates = map[string]*template.Template{}
|
var cachedTemplates = map[string]*template.Template{}
|
||||||
var cachedMutex sync.Mutex
|
var cachedMutex sync.Mutex
|
||||||
|
|
||||||
|
func dollarize(value int) string {
|
||||||
|
return fmt.Sprintf("$%0.2f", float32(value)/100.0)
|
||||||
|
}
|
||||||
|
|
||||||
|
var funcs = template.FuncMap{
|
||||||
|
"dollarize": dollarize,
|
||||||
|
}
|
||||||
|
|
||||||
func T(name string) *template.Template {
|
func T(name string) *template.Template {
|
||||||
cachedMutex.Lock()
|
cachedMutex.Lock()
|
||||||
defer cachedMutex.Unlock()
|
defer cachedMutex.Unlock()
|
||||||
if t, ok := cachedTemplates[name]; ok {
|
if t, ok := cachedTemplates[name]; ok {
|
||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
t := template.New("_base.html")
|
t := template.New("_base.html").Funcs(funcs)
|
||||||
t = template.Must(t.ParseFiles(
|
t = template.Must(t.ParseFiles(
|
||||||
"templates/_base.html",
|
"templates/_base.html",
|
||||||
filepath.Join(*template_dir, name),
|
filepath.Join(*template_dir, name),
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
{{ .Name }}
|
{{ .Name }}
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{{ .Money }}
|
{{ dollarize .Money }}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
Loading…
Reference in New Issue
Block a user