本文整理汇总了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(...);
示例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)
示例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):
示例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)
示例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'})
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)