Skip to content

Commit

Permalink
✨ provide repr filter, fix #26
Browse files Browse the repository at this point in the history
  • Loading branch information
chfw committed May 30, 2018
1 parent 77e4131 commit 9a671ab
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions moban/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@


BUILTIN_EXENSIONS = [
'moban.filters.repr'
]


Expand Down
9 changes: 9 additions & 0 deletions moban/filters/repr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from moban.extensions import JinjaFilter


@JinjaFilter('repr')
def repr_function(string):
if isinstance(string, list):
return ["'{}'".format(str(element)) for element in string]
else:
return "'{}'".format(str(string))
14 changes: 14 additions & 0 deletions tests/test_filter_repr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from moban.filters.repr import repr_function
from nose.tools import eq_


def test_string():
me = 'abc'
expected = repr_function(me)
eq_(expected, "'abc'")


def test_list():
me = [1, 2, 3]
expected = repr_function(me)
eq_(expected, ["'1'", "'2'", "'3'"])

0 comments on commit 9a671ab

Please sign in to comment.