當前位置: 首頁>>代碼示例>>Python>>正文


Python Library.tag方法代碼示例

本文整理匯總了Python中coffin.template.Library.tag方法的典型用法代碼示例。如果您正苦於以下問題:Python Library.tag方法的具體用法?Python Library.tag怎麽用?Python Library.tag使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在coffin.template.Library的用法示例。


在下文中一共展示了Library.tag方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: JsIncludeExtension

# 需要導入模塊: from coffin.template import Library [as 別名]
# 或者: from coffin.template.Library import tag [as 別名]
    Minifier = minify.MinifyJs
    extension = 'js'

class JsIncludeExtension(JsExtension, IncludeExtension):
    tags = ['jsinclude', 'endjsinclude']
    template = settings.JS_INCLUDE

    def _get_filename(self, request, include, minify):
        if minify or len(include) != 1:
            url = IncludeExtension._get_filename(self, request, include, minify)
        else:
            url = settings.MEDIA_URL + include[0]
        
        return url

register.tag(JsIncludeExtension)

class JsHeadExtension(JsIncludeExtension):
    tags = ['js_head', 'endjs_head']
    template = settings.JS_HEAD_INCLUDE

    @contextfunction
    def _join_nodes(self, context, nodes):
        return super(JsHeadExtension, self)._join_nodes(context, nodes, separator=',')

register.tag(JsHeadExtension)

class JsHeadIncludeExtension(JsHeadExtension):
    """
    wraps all nodes with a template 
    <head>...</head> or head.js(...);
開發者ID:tbarbugli,項目名稱:django-minify,代碼行數:33,代碼來源:combine_jinja.py

示例2: AssetsNode

# 需要導入模塊: from coffin.template import Library [as 別名]
# 或者: from coffin.template.Library import tag [as 別名]
            filters = value
            warnings.warn('The "filter" option of the {% assets %} '
                          'template tag has been renamed to '
                          '"filters" for consistency reasons.',
                            ImminentDeprecationWarning)
        # positional arguments are source files
        elif name is None:
            files.append(value)
        else:
            raise template.TemplateSyntaxError('Unsupported keyword argument "%s"'%name)

    # capture until closing tag
    childnodes = parser.parse(("endassets",))
    parser.delete_first_token()
    return AssetsNode(filters, output, files, childnodes)



# If Coffin is installed, expose the Jinja2 extension
try:
    from coffin.template import Library as CoffinLibrary
except ImportError:
    register = template.Library()
else:
    register = CoffinLibrary()
    from webassets.ext.jinja2 import AssetsExtension
    from django_assets.env import get_env
    register.tag(AssetsExtension, environment={'assets_environment': get_env()})

# expose the default Django tag
register.tag('assets', assets)
開發者ID:chexov,項目名稱:webassets,代碼行數:33,代碼來源:assets.py

示例3: Jinja

# 需要導入模塊: from coffin.template import Library [as 別名]
# 或者: from coffin.template.Library import tag [as 別名]
    '''If our token has a `source` attribute than template_debugging is
    enabled. If it's enabled create a valid source attribute for the Django
    template debugger'''
    if source_token:
        source = source_token.source[0], (source_token.source[1][0],
            source_token.source[1][1])
    else:
        source = None

    return Jinja(Template(''.join(tokens), source=source))


def django_noop(parser, token):
    return DjangoNoop()

register.tag('django', django_noop)
register.tag('end_django', django_noop)


class JinjaNoop(ext.Extension):
    tags = set(['jinja', 'end_jinja'])

    def parse(self, parser):
        while not parser.stream.current.type == 'block_end':
            parser.stream.next()
        return []

register.tag(JinjaNoop)


class Django(ext.Extension):
開發者ID:WoLpH,項目名稱:coffin,代碼行數:33,代碼來源:jinja.py

示例4: FooExtension

# 需要導入模塊: from coffin.template import Library [as 別名]
# 或者: from coffin.template.Library import tag [as 別名]
"""Register a Jinja2 extension with a Coffin library object.
"""

from jinja2.ext import Extension
from jinja2 import nodes

class FooExtension(Extension):
    tags = set(['foo'])

    def parse(self, parser):
        parser.stream.next()
        return nodes.Const('{foo}')

from coffin.template import Library
register = Library()
register.tag(FooExtension)
開發者ID:HubertD,項目名稱:coffin,代碼行數:18,代碼來源:foo_ext.py

示例5: FooExtension

# 需要導入模塊: from coffin.template import Library [as 別名]
# 或者: from coffin.template.Library import tag [as 別名]
"""Register a Jinja2 extension with a Coffin library object.
"""

from jinja2.ext import Extension
from jinja2 import nodes

class FooExtension(Extension):
    tags = set(['foo'])

    def parse(self, parser):
        parser.stream.next()
        return nodes.Const('{foo}')

class FooWithConfigExtension(Extension):
    tags = set(['foo_ex'])

    def __init__(self, environment):
        Extension.__init__(self, environment)
        environment.extend(
            foo_custom_output='foo',
        )

    def parse(self, parser):
        parser.stream.next()
        return nodes.Const('{%s}' % self.environment.foo_custom_output)

from coffin.template import Library
register = Library()
register.tag(FooExtension)
register.tag(FooWithConfigExtension, environment={'foo_custom_output': 'my_foo'})
開發者ID:dchaplinsky,項目名稱:coffin,代碼行數:32,代碼來源:foo_ext.py

示例6: set

# 需要導入模塊: from coffin.template import Library [as 別名]
# 或者: from coffin.template.Library import tag [as 別名]
    tags = set(['csrf_token'])

    def parse(self, parser):
        lineno = parser.stream.next().lineno
        return nodes.Output([
            self.call_method('_render', [nodes.Name('csrf_token', 'load')]),
        ]).set_lineno(lineno)

    def _render(self, csrf_token):
        from django.template.defaulttags import CsrfTokenNode
        return Markup(CsrfTokenNode().render({'csrf_token': csrf_token}))


# nicer import names
load = LoadExtension
url = URLExtension
with_ = WithExtension
cache = CacheExtension
spaceless = SpacelessExtension
csrf_token = CsrfTokenExtension

register = Library()
register.tag(load)
register.tag(url)
register.tag(with_)
register.tag(cache)
register.tag(spaceless)
register.tag(csrf_token)

開發者ID:Eksmo,項目名稱:coffin,代碼行數:30,代碼來源:defaulttags.py

示例7: StaticExtension

# 需要導入模塊: from coffin.template import Library [as 別名]
# 或者: from coffin.template.Library import tag [as 別名]
class StaticExtension(CoffinStaticExtension):
    """Implements the {% static %} tag as provided by the ``staticfiles``
    contrib module.

    Returns the URL to a file using staticfiles' storage backend.

    Usage::

        {% static path [as varname] %}

    Examples::

        {% static "myapp/css/base.css" %}
        {% static variable_with_path %}
        {% static "myapp/css/base.css" as admin_base_css %}
        {% static variable_with_path as varname %}

    """

    @classmethod
    def get_static_url(cls, path):
        return super(StaticExtension, cls).get_static_url(
            staticfiles_storage.url(path))


register.tag(StaticExtension)


def static(path):
    return StaticExtension.get_static_url(path)
開發者ID:spothero,項目名稱:coffin,代碼行數:32,代碼來源:static.py

示例8: AssetsNode

# 需要導入模塊: from coffin.template import Library [as 別名]
# 或者: from coffin.template.Library import tag [as 別名]
        # handle known keyword arguments
        if name == 'output':
            output = value
        elif name == 'filter':
            filter = value
        # positional arguments are source files
        elif name is None:
            files.append(value)
        else:
            raise template.TemplateSyntaxError('Unsupported keyword argument "%s"'%name)

    # capture until closing tag
    childnodes = parser.parse(("endassets",))
    parser.delete_first_token()
    return AssetsNode(filter, output, files, childnodes)



# if Coffin is installed, expose the Jinja2 extension
try:
    from coffin.template import Library as CoffinLibrary
except ImportError:
    register = template.Library()
else:
    register = CoffinLibrary()
    from django_assets.jinja2.extension import AssetsExtension
    register.tag(AssetsExtension)

# expose the default Django tag
register.tag('assets', assets)
開發者ID:Aaron1011,項目名稱:oh-mainline,代碼行數:32,代碼來源:assets.py

示例9: parse

# 需要導入模塊: from coffin.template import Library [as 別名]
# 或者: from coffin.template.Library import tag [as 別名]
    """

    tags = ['spaceless']

    def parse(self, parser):
        lineno = parser.stream.next().lineno
        body = parser.parse_statements(['name:endspaceless'], drop_needle=True)
        return nodes.CallBlock(
            self.call_method('_strip_spaces', [], [], None, None),
            [], [], body
        ).set_lineno(lineno)

    def _strip_spaces(self, caller=None):
        from django.utils.html import strip_spaces_between_tags
        return strip_spaces_between_tags(caller().strip())


# nicer import names
load = LoadExtension
url = URLExtension
with_ = WithExtension
cache = CacheExtension
spaceless = SpacelessExtension


register = Library()
register.tag(load)
register.tag(url)
register.tag(with_)
register.tag(cache)
register.tag(spaceless)
開發者ID:ALBAstryde,項目名稱:albastryde,代碼行數:33,代碼來源:defaulttags.py

示例10: Library

# 需要導入模塊: from coffin.template import Library [as 別名]
# 或者: from coffin.template.Library import tag [as 別名]
from coffin.template import Library
from django.template.loader import render_to_string
from jinja2 import nodes
from jinja2.ext import Extension


register = Library()


class MerchantExtension(Extension):

    tags = set(['render_integration'])

    def parse(self, parser):
        stream = parser.stream
        lineno = stream.next().lineno

        obj = parser.parse_expression()
        call_node = self.call_method('render_integration', args=[obj])

        return nodes.Output([call_node]).set_lineno(lineno)

    @classmethod
    def render_integration(self, obj):
        form_str = render_to_string(obj.template, {'integration': obj})
        return form_str

register.tag(MerchantExtension)
開發者ID:BrajeshKhare,項目名稱:merchant,代碼行數:30,代碼來源:jinja2_tags.py

示例11: CdnExtension

# 需要導入模塊: from coffin.template import Library [as 別名]
# 或者: from coffin.template.Library import tag [as 別名]
class CdnExtension(PrefixExtension):
    tags = set(['cdn'])

    def parse(self, parser):
        stream = parser.stream
        lineno = stream.next().lineno

        path = parser.parse_expression()
        call_node = self.call_method('get_statc_url', args=[path])

        if stream.next_if('name:as'):
            var = nodes.Name(stream.expect('name').value, 'store')
            return nodes.Assign(var, call_node).set_lineno(lineno)
        else:
            return nodes.Output([call_node]).set_lineno(lineno)

    @classmethod
    def get_statc_url(cls, path):
        if settings.DEBUG:
            return path
        f = StaticFile(path)
        return f.cdn_path


register.tag(CdnExtension)


def static(path):
    return CdnExtension.get_static_url(path)
開發者ID:torpedoallen,項目名稱:django-cdn-extension,代碼行數:31,代碼來源:extensions.py

示例12: AddGuideExtension

# 需要導入模塊: from coffin.template import Library [as 別名]
# 或者: from coffin.template.Library import tag [as 別名]
    class AddGuideExtension(Extension):
        """
        Jinja2-version of the ``render_guides`` tag.
        """

        tags = set(['add_guide'])

        def parse(self, parser):
            lineno = parser.stream.next().lineno
            args = []
            while not parser.stream.current.test('block_end'):
                args.append(parser.parse_expression())
                parser.stream.skip_if('comma')
            return nodes.Output([
                self.call_method('_render', [nodes.Name('request', 'load'), nodes.List(args)]),
            ]).set_lineno(lineno)

        def _render(self, request, args):
            if not hasattr(request, 'current_guide_name_list'):
                request.current_guide_name_list = list()
            for name in args:
                request.current_guide_name_list.append(name)
            return ''


    @register.object
    def render_guides(request):
        return Markup(origin_render_guides({'request': request}))

    register.tag(AddGuideExtension)
開發者ID:frol,項目名稱:django-guide,代碼行數:32,代碼來源:jinja2_guide_tags.py

示例13: set

# 需要導入模塊: from coffin.template import Library [as 別名]
# 或者: from coffin.template.Library import tag [as 別名]
    """

    tags = set(['static'])

    def parse(self, parser):
        stream = parser.stream
        lineno = stream.next().lineno

        path = parser.parse_expression()
        call_node = self.call_method('get_static_url', args=[path])

        if stream.next_if('name:as'):
            var = nodes.Name(stream.expect('name').value, 'store')
            return nodes.Assign(var, call_node).set_lineno(lineno)
        else:
            return nodes.Output([call_node]).set_lineno(lineno)

    @classmethod
    def get_static_url(cls, path):
        return urljoin(PrefixExtension.get_uri_setting("STATIC_URL"), path)


register.tag(GetStaticPrefixExtension)
register.tag(GetMediaPrefixExtension)
register.tag(StaticExtension)


def static(path):
    return StaticExtension.get_static_url(path)
開發者ID:spothero,項目名稱:coffin,代碼行數:31,代碼來源:static.py

示例14: FooNode

# 需要導入模塊: from coffin.template import Library [as 別名]
# 或者: from coffin.template.Library import tag [as 別名]
"""Register a Django tag with a Coffin library object.
"""

from django.template import Node

class FooNode(Node):
    def render(self, context):
        return u'{foo}'

def do_foo(parser, token):
    return FooNode()

from coffin.template import Library
register = Library()
register.tag('foo_coffin', do_foo)
開發者ID:Deepwalker,項目名稱:coffin,代碼行數:17,代碼來源:django_tags.py


注:本文中的coffin.template.Library.tag方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。