本文整理汇总了Python中webassets.Bundle.bind方法的典型用法代码示例。如果您正苦于以下问题:Python Bundle.bind方法的具体用法?Python Bundle.bind怎么用?Python Bundle.bind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类webassets.Bundle
的用法示例。
在下文中一共展示了Bundle.bind方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: assets
# 需要导入模块: from webassets import Bundle [as 别名]
# 或者: from webassets.Bundle import bind [as 别名]
def assets(request, *args, **kwargs):
env = get_webassets_env_from_request(request)
result = []
for f in args:
try:
result.append(env[f])
except KeyError:
result.append(f)
bundle = Bundle(*result, **kwargs)
if USING_WEBASSETS_CONTEXT:
with bundle.bind(env):
urls = bundle.urls()
else: # pragma: no cover
urls = bundle.urls(env=env)
return urls
示例2: _render_assets
# 需要导入模块: from webassets import Bundle [as 别名]
# 或者: from webassets.Bundle import bind [as 别名]
def _render_assets(tokens, env):
#pylint:disable=too-many-locals
# Construct a bundle with the given options
output = None
filters = None
depends = None
bundle_kwargs = {
'output': output,
'filters': filters,
'debug': False, # because of `Bundle.iterbuild`, this is useless.
'depends': depends,
}
# Resolve bundle names.
files = []
state = None
buffered_tokens = []
for token in tokens:
if state is None:
if token[1] == 'block_begin':
state = STATE_BLOCK_BEGIN
elif state == STATE_BLOCK_BEGIN:
if token[1] == 'name':
# nothing to be done?
pass
elif token[1] == 'string':
files = [token[2][1:-1]] # removes '"'.
if token[1] == 'block_end':
state = STATE_BLOCK_CONTENT
elif state == STATE_BLOCK_CONTENT:
if token[1] == 'block_begin':
state = None
else:
buffered_tokens += [token]
content = ''.join([token[2] for token in buffered_tokens]).strip()
urls = []
bundle_names = []
for fname in files:
try:
bundle = env[fname]
debug = bundle.config.get('debug')
bundle.config.update({'debug': False})
with bundle.bind(env):
urls += bundle.urls()
bundle.config.update({'debug': debug})
except KeyError:
bundle_names.append(fname)
if bundle_names:
bundle = Bundle(*bundle_names, **bundle_kwargs)
# Retrieve urls (this may or may not cause a build)
with bundle.bind(env):
urls += bundle.urls()
# For each url, execute the content of this template tag (represented
# by the macro ```caller`` given to use by Jinja2).
result = content
for url in urls:
look = re.match(r'(.*)({{\s*ASSET_URL.*}})(.*)', content)
if look:
parts = urlparse(url)
url = urlunparse((parts.scheme, parts.netloc, parts.path,
None, None, None))
result = look.group(1) + url + look.group(3)
else:
result = content
return result