ordinal-filter added.
This commit is contained in:
parent
5c75b2918a
commit
f8f8725dc5
@ -22,6 +22,7 @@ All additional filters/tags will be registered automatically.
|
||||
- **[filesizeformat](https://docs.djangoproject.com/en/1.6/ref/templates/builtins/#filesizeformat)** (human-readable filesize; takes bytes as input)
|
||||
- **[timesince](https://docs.djangoproject.com/en/1.6/ref/templates/builtins/#timesince)/[timeuntil](https://docs.djangoproject.com/en/1.6/ref/templates/builtins/#timeuntil)/[naturaltime](https://docs.djangoproject.com/en/dev/ref/contrib/humanize/#naturaltime)** (human-readable time [duration] indicator)
|
||||
- **[intcomma](https://docs.djangoproject.com/en/dev/ref/contrib/humanize/#intcomma)** (put decimal marks into the number)
|
||||
- **[ordinal](https://docs.djangoproject.com/en/dev/ref/contrib/humanize/#ordinal)** (convert integer to its ordinal as string)
|
||||
|
||||
## Tags
|
||||
|
||||
|
@ -19,6 +19,7 @@ func init() {
|
||||
pongo2.RegisterFilter("timesince", filterTimeuntilTimesince)
|
||||
pongo2.RegisterFilter("naturaltime", filterTimeuntilTimesince)
|
||||
pongo2.RegisterFilter("intcomma", filterIntcomma)
|
||||
pongo2.RegisterFilter("ordinal", filterOrdinal)
|
||||
}
|
||||
|
||||
func filterMarkdown(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, error) {
|
||||
@ -54,3 +55,7 @@ func filterTimeuntilTimesince(in *pongo2.Value, param *pongo2.Value) (*pongo2.Va
|
||||
func filterIntcomma(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, error) {
|
||||
return pongo2.AsValue(humanize.Comma(int64(in.Integer()))), nil
|
||||
}
|
||||
|
||||
func filterOrdinal(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, error) {
|
||||
return pongo2.AsValue(humanize.Ordinal(in.Integer())), nil
|
||||
}
|
||||
|
@ -52,4 +52,8 @@ func (s *TestSuite1) TestFilters(c *C) {
|
||||
|
||||
// Intcomma
|
||||
c.Assert(pongo2.RenderTemplateString("{{ 123456789|intcomma }}", nil), Equals, "123,456,789")
|
||||
|
||||
// Ordinal
|
||||
c.Assert(pongo2.RenderTemplateString("{{ 1|ordinal }} {{ 2|ordinal }} {{ 3|ordinal }} {{ 18241|ordinal }}", nil),
|
||||
Equals, "1st 2nd 3rd 18241st")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user