mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-23 21:53:09 +02:00
tpl: Add a delimiter parameter to lang.NumFmt
The original implementation of NumFmt did not take into account that the options delimiter (a space) could be a valid option. Adding a delim parameter seems like the simplest, safest, and most flexible way to solve this oversight in a backwards-compatible way. Fixes #5260
This commit is contained in:
committed by
Bjørn Erik Pedersen
parent
91f49c0700
commit
ce264b936c
@@ -67,15 +67,27 @@ func (ns *Namespace) NumFmt(precision, number interface{}, options ...interface{
|
||||
var neg, dec, grp string
|
||||
|
||||
if len(options) == 0 {
|
||||
// TODO(moorereason): move to site config
|
||||
// defaults
|
||||
neg, dec, grp = "-", ".", ","
|
||||
} else {
|
||||
delim := " "
|
||||
|
||||
if len(options) == 2 {
|
||||
// custom delimiter
|
||||
s, err := cast.ToStringE(options[1])
|
||||
if err != nil {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
delim = s
|
||||
}
|
||||
|
||||
s, err := cast.ToStringE(options[0])
|
||||
if err != nil {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
rs := strings.Fields(s)
|
||||
rs := strings.Split(s, delim)
|
||||
switch len(rs) {
|
||||
case 0:
|
||||
case 1:
|
||||
|
Reference in New Issue
Block a user