Skip to content

Commit

Permalink
feat: add intword mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
thefab committed Feb 16, 2021
1 parent de55e45 commit 52ce735
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions .metwork-framework/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Following [humanize](https://python-humanize.readthedocs.io/) functions are curr
- `naturaldelta`
- `naturaltime`
- `precisedelta`
- `humanize_intword`

See [humanize](https://python-humanize.readthedocs.io/) documentation for argument details.

Expand Down
11 changes: 8 additions & 3 deletions jinja2_humanize_extension/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import jinja2
from jinja2.ext import Extension
from humanize import (
naturalsize,
)
from humanize import naturalsize

from humanize.time import (
abs_timedelta,
Expand All @@ -13,13 +11,19 @@
naturaltime,
precisedelta,
)
from humanize.number import intword


@jinja2.evalcontextfilter
def humanize_abs_timedelta(eval_ctx, delta):
return abs_timedelta(delta)


@jinja2.evalcontextfilter
def humanize_intword(eval_ctx, value, format="%.1f"):
return intword(value, format=format)


@jinja2.evalcontextfilter
def humanize_naturalsize(eval_ctx, value, binary=False, gnu=False, format="%.1f"):
return naturalsize(value, binary=binary, gnu=gnu, format=format)
Expand Down Expand Up @@ -76,3 +80,4 @@ def __init__(self, environment):
environment.filters["humanize_naturaldelta"] = humanize_naturaldelta
environment.filters["humanize_naturaltime"] = humanize_naturaltime
environment.filters["humanize_precisedelta"] = humanize_precisedelta
environment.filters["humanize_intword"] = humanize_intword

0 comments on commit 52ce735

Please sign in to comment.