コード例 #1
0
ファイル: test_env.py プロジェクト: Deepwalker/coffin
    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
ファイル: test_library.py プロジェクト: Deepwalker/coffin
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
ファイル: test_env.py プロジェクト: xiaol/eachcloud_community
    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
ファイル: test_env.py プロジェクト: xiaol/eachcloud_community
def test_i18n():
    with override_settings(USE_I18N=True):
        assert get_env().from_string('{{ _("test") }}').render() == 'test'
コード例 #9
0
ファイル: __init__.py プロジェクト: ALBAstryde/albastryde
    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
ファイル: test_env.py プロジェクト: Deepwalker/coffin
def test_i18n():
    with override_settings(USE_I18N=True):
        assert get_env().from_string('{{ _("test") }}').render() == 'test'