示例#1
0
    def test_cached_loader(self):
        from jinja2 import loaders

        with override_settings(TEMPLATE_LOADERS=[
            ('django.template.loaders.cached.Loader', (
                'django.template.loaders.filesystem.Loader',
                'django.template.loaders.app_directories.Loader',
            )),]):
            env = get_env()
            assert len(env.loader.loaders) == 1
            cached_loader = get_env().loader.loaders[0]
            assert hasattr(cached_loader, 'template_cache')
            assert len(cached_loader.loader.loaders) == 2
            assert isinstance(cached_loader.loader.loaders[0], loaders.FileSystemLoader)

            # the cached loader can find a template too.
            assert env.loader.load(env, 'render-x.html').render({'x': 'foo'}) == 'foo'
示例#2
0
def test_env_builtins_django():
    """Test that when the environment is assembled, Django libraries which
    are included in the list of builtins are properly supported.
    """
    from coffin.common import get_env
    from coffin.template import add_to_builtins
    add_to_builtins('apps.django_lib')
    assert get_env().from_string('a{{ "b"|foo_django_builtin }}c').render() == 'a{foo}c'
示例#3
0
def test_env_builtins_django():
    """Test that when the environment is assembled, Django libraries which
    are included in the list of builtins are properly supported.
    """
    from coffin.common import get_env
    from coffin.template import add_to_builtins
    add_to_builtins('apps.django_lib')
    assert get_env().from_string(
        'a{{ "b"|foo_django_builtin }}c').render() == 'a{foo}c'
示例#4
0
    def test_cached_loader(self):
        from jinja2 import loaders

        with override_settings(TEMPLATE_LOADERS=[
            ('django.template.loaders.cached.Loader', (
                'django.template.loaders.filesystem.Loader',
                'django.template.loaders.app_directories.Loader',
            )),
        ]):
            env = get_env()
            assert len(env.loader.loaders) == 1
            cached_loader = get_env().loader.loaders[0]
            assert hasattr(cached_loader, 'template_cache')
            assert len(cached_loader.loader.loaders) == 2
            assert isinstance(cached_loader.loader.loaders[0],
                              loaders.FileSystemLoader)

            # the cached loader can find a template too.
            assert env.loader.load(env,
                                   'render-x.html').render({'x':
                                                            'foo'}) == 'foo'
示例#5
0
    def __new__(cls, template_string, origin=None, name=None):
        # We accept the "origin" and "name" arguments, but discard them
        # right away - Jinja's Template class (apparently) stores no
        # equivalent information.

        return get_env().from_string(template_string, template_class=cls)
示例#6
0
def get_template_from_string(source):
    """
    Does not support then ``name`` and ``origin`` parameters from
    the Django version.
    """
    return get_env().from_string(source)
示例#7
0
def get_template(template_name):
    # Jinja will handle this for us, and get_env() also initializes
    # the loader backends the first time it is called.
    return get_env().get_template(template_name)
示例#8
0
def test_i18n():
    with override_settings(USE_I18N=True):
        assert get_env().from_string('{{ _("test") }}').render() == 'test'
示例#9
0
    def __new__(cls, template_string, origin=None, name=None):
        # We accept the "origin" and "name" arguments, but discard them
        # right away - Jinja's Template class (apparently) stores no
        # equivalent information.

        return get_env().from_string(template_string, template_class=cls)
示例#10
0
def test_i18n():
    with override_settings(USE_I18N=True):
        assert get_env().from_string('{{ _("test") }}').render() == 'test'