本文整理汇总了Python中webassets.Bundle类的典型用法代码示例。如果您正苦于以下问题:Python Bundle类的具体用法?Python Bundle怎么用?Python Bundle使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Bundle类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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()
开发者ID:EzoxSystems,项目名称:gae-skeleton,代码行数:33,代码来源:app_assets.py
示例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()
开发者ID:Workiva,项目名称:gae-financials,代码行数:35,代码来源:assets.py
示例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'
开发者ID:Workiva,项目名称:gae-financials,代码行数:29,代码来源:assets.py
示例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))
开发者ID:aromanovich,项目名称:carcade,代码行数:8,代码来源:environments_tests.py
示例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)
开发者ID:cmorgia,项目名称:indicopicture,代码行数:9,代码来源:__init__.py
示例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
开发者ID:0x1997,项目名称:webassets,代码行数:9,代码来源:test_jinja2.py
示例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']
开发者ID:thatguystone,项目名称:webassets,代码行数:10,代码来源:test_bundle.py
示例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'
开发者ID:EzoxSystems,项目名称:gae-skeleton,代码行数:10,代码来源:app_assets.py
示例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)
开发者ID:Workiva,项目名称:gae-financials,代码行数:11,代码来源:assets.py
示例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)
开发者ID:EzoxSystems,项目名称:gae-skeleton,代码行数:11,代码来源:app_assets.py
示例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 == {}
开发者ID:Topidesta,项目名称:webassets,代码行数:14,代码来源:test_bundle_various.py
示例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
开发者ID:sekimura,项目名称:pyramid_webassets,代码行数:50,代码来源:__init__.py
示例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 }'
开发者ID:groner,项目名称:pyramid_webassets,代码行数:15,代码来源:test_webassets.py
示例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
开发者ID:longhotsummer,项目名称:pyramid_webassets,代码行数:15,代码来源:__init__.py
示例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
开发者ID:sekimura,项目名称:pyramid_webassets,代码行数:16,代码来源:test_webassets.py
示例16: test_asset_spec_missing_file
def test_asset_spec_missing_file(self):
from webassets import Bundle
from webassets.exceptions import BundleError
self.create_files({
'dotted/__init__.py': '',
'dotted/package/__init__.py': '',
'dotted/package/name/__init__.py': ''})
asset_spec = 'dotted.package.name:static/zing.css'
bundle = Bundle(asset_spec)
with self.assertRaises(BundleError) as cm:
bundle.urls(self.env)
assert cm.exception.args[0].message == '{0!r} does not exist'.format(
self.tempdir+'/dotted/package/name/static/zing.css')
开发者ID:groner,项目名称:pyramid_webassets,代码行数:16,代码来源:test_webassets.py
示例17: test_asset_spec_globbing
def test_asset_spec_globbing(self):
from webassets import Bundle
self.create_files({
'static/__init__.py': '',
'static/zing.css':
'* { text-decoration: underline }',
'static/zang.css':
'* { text-decoration: underline }'})
asset_spec = 'static:z*ng.css'
bundle = Bundle(asset_spec)
urls = bundle.urls(self.env)
assert len(urls) == 2
assert 'http://example.com/static/zing.css' in urls
assert 'http://example.com/static/zang.css' in urls
开发者ID:sekimura,项目名称:pyramid_webassets,代码行数:16,代码来源:test_webassets.py
示例18: test_asset_spec_missing_file
def test_asset_spec_missing_file(self):
from webassets import Bundle
from webassets.exceptions import BundleError
self.create_files({
'dotted/__init__.py': '',
'dotted/package/__init__.py': '',
'dotted/package/name/__init__.py': ''})
asset_spec = 'dotted.package.name:static/zing.css'
bundle = Bundle(asset_spec)
with self.assertRaises(BundleError) as cm:
bundle.urls(self.env)
fname = self.tempdir+'/dotted/package/name/static/zing.css'
assert str(cm.exception.message) == ("'%s' does not exist" % (fname,))
开发者ID:sekimura,项目名称:pyramid_webassets,代码行数:16,代码来源:test_webassets.py
示例19: test_asset_spec_passthru_uses_static_url
def test_asset_spec_passthru_uses_static_url(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)
self.request.static_url = Mock(return_value='http://example.com/foo/')
urls = bundle.urls(self.env)
self.request.static_url.assert_called_with(asset_spec)
assert urls == ['http://example.com/foo/']
开发者ID:groner,项目名称:pyramid_webassets,代码行数:16,代码来源:test_webassets.py
示例20: test_asset_spec_no_static_view
def test_asset_spec_no_static_view(self):
from webassets import Bundle
from webassets.exceptions import BundleError
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)
with self.assertRaises(BundleError) as cm:
bundle.urls(self.env)
assert cm.exception.args[0].message == 'No static URL definition matching '+asset_spec
开发者ID:groner,项目名称:pyramid_webassets,代码行数:17,代码来源:test_webassets.py
注:本文中的webassets.Bundle类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论