frontend/templates: fix money rendering
Signed-off-by: Ahmet Alp Balkan <ahmetb@google.com>
This commit is contained in:
parent
fc272ffb7b
commit
75135e6c7f
4 changed files with 12 additions and 11 deletions
|
@ -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)
|
||||||
|
}
|
||||||
|
|
|
@ -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>
|
||||||
|
|
|
@ -38,10 +38,8 @@
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<small class="text-muted">
|
<small class="text-muted">
|
||||||
{{.Price.CurrencyCode}}
|
{{ renderMoney .Price }}
|
||||||
<strong>{{.Price.Amount.Decimal}}.{{.Price.Amount.Fractional}}
|
</strong>
|
||||||
{{- if lt .Price.Amount.Fractional 10}}0{{end}}
|
|
||||||
</strong>
|
|
||||||
</small>
|
</small>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -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>
|
||||||
|
|
Loading…
Reference in a new issue