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 committed by Simon Zeltser
parent fc272ffb7b
commit 75135e6c7f
4 changed files with 12 additions and 11 deletions

View file

@ -17,7 +17,10 @@ import (
) )
var ( 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 { func ensureSessionID(next http.HandlerFunc) http.HandlerFunc {
@ -282,3 +285,7 @@ func cartIDs(c []*pb.CartItem) []string {
} }
return out 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"> <div class="col text-left">
Qty: {{.Quantity}}<br/> Qty: {{.Quantity}}<br/>
<strong> <strong>
{{.Price.CurrencyCode}} {{ renderMoney .Price}}
{{.Price.Amount.Decimal}}.
{{- .Price.Amount.Fractional}}{{- if lt .Price.Amount.Fractional 10}}0{{end}}
</strong> </strong>
</div> </div>
</div> </div>

View file

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

View file

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