本文整理汇总了Python中webassets.Bundle类的典型用法代码示例。如果您正苦于以下问题:Python Bundle类的具体用法?Python Bundle怎么用?Python Bundle使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Bundle类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _bundle_3rd_party_js
def _bundle_3rd_party_js(app, env, debug=False):
"""Combine thrid party js libs into libs.js.
For debug, they are left uncompressed. For production the minified
versions are used. We suggest using hte vendor supplied minified version
of each library.
"""
JSPATH = path.join('js', 'lib')
if debug:
scripts = ()
if not scripts:
return
all_js = Bundle(
*scripts,
output=path.join('..', '..', app, 'static', 'script', 'libs.js')
)
else:
JSPATH = path.join(JSPATH, 'min')
scripts = ()
if not scripts:
return
all_js = Bundle(
*scripts,
output=path.join('..', '..', app, 'static', 'script', 'libs.js')
)
env.add(all_js)
if debug:
all_js.build()
示例2: _bundle_3rd_party_js
def _bundle_3rd_party_js(env, debug=False):
"""Combine thrid party js libs into libs.js.
For debug, they are left uncompressed. For production the minified
versions are used. We suggest using hte vendor supplied minified version
of each library.
"""
JSPATH = path.join('js', 'lib')
if debug:
all_js = Bundle(
path.join(JSPATH, 'json2.js'),
path.join(JSPATH, 'jquery.js'),
path.join(JSPATH, 'underscore.js'),
path.join(JSPATH, 'backbone.js'),
path.join(JSPATH, 'bootstrap.js'),
path.join(JSPATH, 'leaflet.js'),
path.join(JSPATH, 'bootstrap-typeahead-improved.js'),
output=path.join('..', 'static', 'script', 'libs.js')
)
else:
JSPATH = path.join(JSPATH, 'min')
all_js = Bundle(
path.join(JSPATH, 'json2.min.js'),
path.join(JSPATH, 'jquery-min.js'),
path.join(JSPATH, 'underscore-min.js'),
path.join(JSPATH, 'backbone-min.js'),
path.join(JSPATH, 'bootstrap-min.js'),
path.join(JSPATH, 'leaflet-min.js'),
path.join(JSPATH, 'bootstrap-typeahead-improved-min.js'),
output=path.join('..', 'static', 'script', 'libs.js')
)
env.add(all_js)
if debug:
all_js.build()
示例3: _bundle_app_coffee
def _bundle_app_coffee(env, debug=False):
"""Compile the apps coffeescript and bundle it into appname.js"""
COFFEE_PATH = 'coffee'
APP_PATH = path.join(COFFEE_PATH, 'appname')
scripts = (
path.join(COFFEE_PATH, 'nested.coffee'),
path.join(COFFEE_PATH, 'app.coffee'),
path.join(APP_PATH, 'app.coffee'),
path.join(APP_PATH, 'menu.coffee'),
path.join(APP_PATH, 'channel.coffee'),
path.join(APP_PATH, 'contact.coffee'),
path.join(APP_PATH, 'tag.coffee'),
path.join(APP_PATH, 'person.coffee'),
path.join(APP_PATH, 'vendor.coffee'),
path.join(APP_PATH, 'activity.coffee'),
path.join(APP_PATH, 'transaction.coffee'),
path.join(APP_PATH, 'summary.coffee'),
path.join(APP_PATH, 'router.coffee'),
)
all_js = Bundle(
*scripts,
filters='coffeescript',
output=path.join('..', 'static', 'script', 'appname.js')
)
env.add(all_js)
if not debug:
all_js.filters = 'closure_js'
示例4: test
def test(self):
bundle = Bundle("one.css", "two.css", output="styles.css")
assets_env = create_assets_env(
source_dir="./tests/fixtures/bundle", build_dir=self.build_dir, static_url="/", bundles={}
)
bundle.build(env=assets_env)
self.assertTrue("styles.css" in os.listdir(self.build_dir))
示例5: register_tpl_bundle
def register_tpl_bundle(self, name, *files):
def noop(_in, out, **kw):
out.write(_in.read())
bundle = Bundle(*files, filters=(noop,), output='tpls/{}'.format(name))
fileName = bundle.resolve_output(self.assets)
if os.path.isfile(fileName):
os.remove(fileName)
bundle.build(self.assets,force=False,disable_cache=True)
self.assets.register(name, bundle)
示例6: __init__
def __init__(self, *a, **kw):
Bundle.__init__(self, *a, **kw)
self.env = assets_env
self.dbg = kw.get('debug', None)
# Kind of hacky, but gives us access to the last Bundle
# instance used by the extension.
test_instance.the_bundle = self
示例7: test_pass_down_env
def test_pass_down_env(self):
"""[Regression] When a root *container* bundle is connected
to an environment, the child bundles do not have to be.
"""
child = Bundle('1', '2')
child.env = None
root = self.MockBundle(child)
root.env = self.m
# Does no longer raise an "unconnected env" exception
assert root.urls() == ['/1', '/2']
示例8: _bundle_app_jsts
def _bundle_app_jsts(app, env, debug=False):
"""Compile and bundle JSTs into template.js"""
all_js = Bundle(
path.join('templates', '**', '*.jst'), debug=False, filters='jst',
output=path.join('..', '..', app, 'static', 'script', 'template.js')
)
env.add(all_js)
if not debug:
all_js.filters = 'closure_js'
示例9: _bundle_app_less
def _bundle_app_less(env, debug):
"""Compile and minify appname's less files into appname.css."""
bundle = Bundle(
Bundle(path.join('less', 'appname.less'), filters='less'),
output=path.join('..', 'static', 'css', 'appname.css')
)
if not debug:
bundle.filters = 'cssmin'
env.add(bundle)
示例10: _bundle_app_less
def _bundle_app_less(app, env, debug):
"""Compile and minify demo's less files into demo.css."""
bundle = Bundle(
Bundle(path.join('less', '%s.less' % (app.lower(),)), filters='less'),
output=path.join('..', '..', app, 'static', 'css', '%s.css' % (app.lower(),))
)
if not debug:
bundle.filters = 'cssmin'
env.add(bundle)
示例11: test_init_extra_kwarg
def test_init_extra_kwarg(self):
"""Bundles may be given an ``extra`` dictionary."""
assert Bundle().extra == {}
assert Bundle(extra={'foo': 'bar'}).extra == {'foo': 'bar'}
# Nested extra values
assert Bundle(Bundle(extra={'foo': 'bar'}),
Bundle(extra={'baz': 'qux'})).extra == {
'foo': 'bar', 'baz': 'qux'}
# [Regression] None values in child bundles raise no exception
bundle = Bundle('foo')
bundle.extra = None
assert Bundle(bundle).extra == {}
示例12: resolve_source_to_url
def resolve_source_to_url(self, filepath, item):
request = get_current_request()
env = self.env
# Copied from webassets 0.8. Reproduced here for backwards
# compatibility with the previous webassets release.
# This ensures files which do not require building are still served
# with proper versioning of URLs.
# This can likely be removed once miracle2k/webassets#117 is fixed.
# Only query the version if we need to for performance
version = None
if has_placeholder(filepath) or env.url_expire is not False:
# If auto-build is enabled, we must not use a cached version
# value, or we might serve old versions.
bundle = Bundle(item, output=filepath)
version = bundle.get_version(env, refresh=env.auto_build)
url = filepath
if has_placeholder(url):
url = url % {'version': version}
# This part is different from webassets. Try to resolve with an asset
# spec first, then try the base class source URL resolver.
resolved = False
if request is not None:
# Attempt to resolve the filepath as passed (but after versioning).
# If this fails, it may be because the static route was registered
# with an asset spec. In this case, the original item may also be
# an asset spec contained therein, so try to resolve that.
for attempt in (url, item):
try:
url = request.static_url(attempt)
except ValueError:
continue
else:
resolved = True
break
if not resolved:
url = super(PyramidResolver, self).resolve_source_to_url(
url,
item
)
if env.url_expire or (
env.url_expire is None and not has_placeholder(filepath)):
url = "%s?%s" % (url, version)
return url
示例13: test_asset_spec_is_resolved
def test_asset_spec_is_resolved(self):
from webassets import Bundle
self.create_files({
'dotted/__init__.py': '',
'dotted/package/__init__.py': '',
'dotted/package/name/__init__.py': '',
'dotted/package/name/static/zing.css':
'* { text-decoration: underline }'})
asset_spec = 'dotted.package.name:static/zing.css'
bundle = Bundle(asset_spec, output='gen/zung.css')
urls = bundle.urls(self.env)
assert urls == ['/static/gen/zung.css']
assert file(self.tempdir+urls[0]).read() == '* { text-decoration: underline }'
示例14: assets
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)
urls = bundle.urls(env=env)
return urls
示例15: test_url
def test_url(self, base_url, static_view, webasset, expected):
"""
Test final urls
Special notes on the parametrized variables:
- expected file, if it ends in o.css, it setups output in the bundle
- static_view set to manual changes also the base_dir to /mypkg instead
of /static
"""
from webassets import Bundle
expected = self.format_expected(expected, webasset)
params = {} if not 'o.css' in expected else {'output': 'o.css'}
bundle = Bundle(webasset, **params)
res = bundle.urls(self.build_env(base_url, static_view))
assert [expected] == res