frontend/templates: fix money rendering

Signed-off-by: Ahmet Alp Balkan <ahmetb@google.com>
This commit is contained in:
Ahmet Alp Balkan 2018-06-27 14:55:19 -07:00
parent 6c2336b21e
commit 10748d6b0a
4 changed files with 12 additions and 11 deletions

View file

@ -17,7 +17,10 @@ import (
)
var (
templates = template.Must(template.ParseGlob("templates/*.html"))
templates = template.Must(template.New("").
Funcs(template.FuncMap{
"renderMoney": renderMoney,
}).ParseGlob("templates/*.html"))
)
func ensureSessionID(next http.HandlerFunc) http.HandlerFunc {
@ -282,3 +285,7 @@ func cartIDs(c []*pb.CartItem) []string {
}
return out
}
func renderMoney(money pb.Money) string {
return fmt.Sprintf("%s %d.%02d", money.GetCurrencyCode(), money.GetUnits(), money.GetNanos()/10000000)
}

View file

@ -26,9 +26,7 @@
<div class="col text-left">
Qty: {{.Quantity}}<br/>
<strong>
{{.Price.CurrencyCode}}
{{.Price.Amount.Decimal}}.
{{- .Price.Amount.Fractional}}{{- if lt .Price.Amount.Fractional 10}}0{{end}}
{{ renderMoney .Price}}
</strong>
</div>
</div>

View file

@ -38,10 +38,8 @@
</a>
</div>
<small class="text-muted">
{{.Price.CurrencyCode}}
<strong>{{.Price.Amount.Decimal}}.{{.Price.Amount.Fractional}}
{{- if lt .Price.Amount.Fractional 10}}0{{end}}
</strong>
{{ renderMoney .Price }}
</strong>
</small>
</div>
</div>

View file

@ -13,9 +13,7 @@
<h2>{{$.product.Item.Name}}</h2>
<p class="text-muted">
{{$.product.Price.CurrencyCode}}
{{$.product.Price.Amount.Decimal}}.
{{- $.product.Price.Amount.Fractional}}{{- if lt $.product.Price.Amount.Fractional 10}}0{{end}}
{{ renderMoney $.product.Price}}
</p>
<hr/>
<p>