diff --git a/tests/res/apps/templatelibs_app/templatetags/jinja2_objects.py b/tests/res/apps/templatelibs_app/templatetags/jinja2_objects.py new file mode 100644 index 0000000..37ed59e --- /dev/null +++ b/tests/res/apps/templatelibs_app/templatetags/jinja2_objects.py @@ -0,0 +1,9 @@ +"""Register a Jinja2 global object with a Coffin library object. +""" + +def hello_func(name): + return u"Hello %s" % name + +from coffin.template import Library +register = Library() +register.object('hello', hello_func) diff --git a/tests/test_library.py b/tests/test_library.py index f95e04f..2eb0f83 100644 --- a/tests/test_library.py +++ b/tests/test_library.py @@ -31,6 +31,15 @@ def test_nodes_and_extensions(): assert Template('{% load django_tags %}a{% foo_coffin %}b').render(Context()) == 'a{foo}b' +def test_objects(): + """For coffin, global objects can be registered. + """ + from coffin.common import env + + # Jinja2 global objects, loaded from a Coffin library + assert env.from_string('{{ hello("John") }}').render() == 'Hello John' + + def test_filters(): """Test availability of registered filters. """