Fix handling of numeric types
This commit is contained in:
parent
8e83ac046b
commit
f0b9ab0d63
@ -10,6 +10,14 @@ https://pypi.org/project/template-nest/.
|
||||
|
||||
* News
|
||||
|
||||
** v0.1.3 - 2024-11-24
|
||||
|
||||
+ Fix handling of numeric types.
|
||||
|
||||
Earlier numeric values would result in an error (value type not supported),
|
||||
this was due to a programming error. I've fixed the error and added support
|
||||
for more numeric types.
|
||||
|
||||
** v0.1.0 - 2024-11-18
|
||||
|
||||
+ Initial Release.
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
@ -295,8 +296,30 @@ func (nest *TemplateNest) Render(toRender interface{}) (string, error) {
|
||||
}
|
||||
return html.EscapeString(v), nil
|
||||
|
||||
case float64, int, int64:
|
||||
return fmt.Sprintf("%v", v), nil
|
||||
case float32:
|
||||
return strconv.FormatFloat(float64(v), 'f', -1, 32), nil
|
||||
case float64:
|
||||
return strconv.FormatFloat(v, 'f', -1, 64), nil
|
||||
case int:
|
||||
return strconv.Itoa(v), nil
|
||||
case int8:
|
||||
return strconv.FormatInt(int64(v), 10), nil
|
||||
case int16:
|
||||
return strconv.FormatInt(int64(v), 10), nil
|
||||
case int32:
|
||||
return strconv.FormatInt(int64(v), 10), nil
|
||||
case int64:
|
||||
return strconv.FormatInt(v, 10), nil
|
||||
case uint:
|
||||
return strconv.FormatUint(uint64(v), 10), nil
|
||||
case uint8:
|
||||
return strconv.FormatUint(uint64(v), 10), nil
|
||||
case uint16:
|
||||
return strconv.FormatUint(uint64(v), 10), nil
|
||||
case uint32:
|
||||
return strconv.FormatUint(uint64(v), 10), nil
|
||||
case uint64:
|
||||
return strconv.FormatUint(v, 10), nil
|
||||
|
||||
case Hash:
|
||||
return nest.renderHash(v)
|
||||
@ -305,7 +328,7 @@ func (nest *TemplateNest) Render(toRender interface{}) (string, error) {
|
||||
return nest.renderHash(v)
|
||||
|
||||
default:
|
||||
return "", fmt.Errorf("unsupported template hash value type: %+v", v)
|
||||
return "", fmt.Errorf("unsupported template hash value type: %T: %+v", v, v)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user