本文整理汇总了Python中webassets.Environment类的典型用法代码示例。如果您正苦于以下问题:Python Environment类的具体用法?Python Environment怎么用?Python Environment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Environment类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: setupAssetEnviromentFromYAML
def setupAssetEnviromentFromYAML(app, yamlFile):
appDir = './' + app.config['APP_DIRECTORY'] + '/'
assetEnv = AssetsEnvironment(appDir, '/')
bundles = YAMLLoader(appDir + yamlFile).load_bundles()
for bundle in bundles:
assetEnv.register(bundle, bundles[bundle])
app.templateEnv.assets_environment = assetEnv
开发者ID:matsumos,项目名称:toodooo,代码行数:7,代码来源:main.py
示例2: setup
def setup(self):
# Setup the assets environment.
assets_env = AssetsEnvironment('', '')
self.foo_bundle = Bundle()
self.bar_bundle = Bundle()
assets_env.register('foo_bundle', self.foo_bundle)
assets_env.register('bar_bundle', self.bar_bundle)
# Inject a mock bundle class into the Jinja2 extension, so we
# can check on what exactly it does.
test_instance = self
class MockBundle(Bundle):
urls_to_fake = ['foo']
def __init__(self, *a, **kw):
Bundle.__init__(self, *a, **kw)
self.env = assets_env
# Kind of hacky, but gives us access to the last Bundle
# instance used by the extension.
test_instance.the_bundle = self
def urls(self, *a, **kw):
return self.urls_to_fake
self._old_bundle_class = AssetsExtension.BundleClass
AssetsExtension.BundleClass = self.BundleClass = MockBundle
# Setup the Jinja2 environment.
self.jinja_env = JinjaEnvironment()
self.jinja_env.add_extension(AssetsExtension)
self.jinja_env.assets_environment = assets_env
开发者ID:arturosevilla,项目名称:webassets,代码行数:28,代码来源:test_jinja2.py
示例3: test_options
def test_options(self):
"""Test option declaration.
"""
class TestFilter(Filter):
options = {
"attr1": "ATTR1",
"attr2": ("secondattr", "ATTR2"),
"attr3": (False, "ATTR3"),
"attr4": ("attr4", False),
}
# Test __init__ arguments
assert TestFilter(attr1="foo").attr1 == "foo"
assert TestFilter(secondattr="foo").attr2 == "foo"
assert_raises(TypeError, TestFilter, attr3="foo")
assert TestFilter(attr4="foo").attr4 == "foo"
# Test config vars
env = Environment(None, None)
env.config["attr1"] = "bar"
env.config["attr4"] = "bar"
f = TestFilter()
f.env = env
f.setup()
assert f.attr1 == "bar"
assert f.attr4 is None # Was configured to not support env
开发者ID:ghk,项目名称:webassets,代码行数:27,代码来源:test_filters.py
示例4: compileJavascript
def compileJavascript():
environment = Environment('vendor/bootstrap/js/', 'javascript')
output = '../../../codemitts/resources/static/javascript/bootstrap.js'
bootstrap_javascript_bundle = Bundle('*', output=output)
environment.register('bootstrap_javascript_bundle',
bootstrap_javascript_bundle)
environment['bootstrap_javascript_bundle'].urls()
开发者ID:kodare,项目名称:codemitts,代码行数:7,代码来源:assets.py
示例5: generate_webasset_bundles
def generate_webasset_bundles(config):
compo_bundles = extract_static_assets_from_components(epflutil.Discover.discovered_components)
page_bundles = []
pages = [epflpage.Page] + epflutil.Discover.discovered_pages
for cls in pages:
page_bundles.append(extract_static_assets_from_components([cls]))
if not asbool(config.registry.settings.get('epfl.webassets.active', False)):
return
ar = AssetResolver()
epfl_static = ar.resolve('solute.epfl:static')
my_env = Environment('%s/bundles' % epfl_static.abspath(), 'bundles')
for i, page in enumerate(pages):
js_paths, js_name, css_paths, css_name = page_bundles[i]
js_paths += compo_bundles[0]
js_name += compo_bundles[1]
css_paths += compo_bundles[2]
css_name += compo_bundles[3]
my_env.register('js%s' % i, Bundle(js_paths, filters='rjsmin', output='epfl.%(version)s.js'))
my_env.register('css%s' % i, Bundle(css_paths, output='epfl.%(version)s.css'))
page.js_name += [("solute.epfl:static", url) for url in my_env['js%s' % i].urls()]
page.css_name += [("solute.epfl:static", url) for url in my_env['css%s' % i].urls()]
page.bundled_names = js_name + css_name
开发者ID:JustusW,项目名称:pyramid_epfl,代码行数:32,代码来源:__init__.py
示例6: _set_env
def _set_env(debug=True, cache=False):
env = Environment(BASE_PATH)
if debug:
env.manifest = False
env.cache = cache
return env
开发者ID:lyddonb,项目名称:spicolis,代码行数:9,代码来源:build.py
示例7: load_environment
def load_environment(self):
"""Load an ``Environment`` instance defined in the YAML file.
Expects the following format::
directory: ../static
url: /media
debug: True
updater: timestamp
config:
compass_bin: /opt/compass
another_custom_config_value: foo
bundles:
bundle-name:
filters: sass,cssutils
output: cache/default.css
contents:
- css/jquery.ui.calendar.css
- css/jquery.ui.slider.css
"""
f, filename = self._open()
try:
obj = self.yaml.load(f) or {}
# construct the environment
if not 'url' in obj or not 'directory' in obj:
raise LoaderError('"url" and "directory" must be defined')
directory = obj['directory']
if filename:
# If we know the location of the file, make sure that the
# paths included are considered relative to the file location.
directory = path.normpath(path.join(path.dirname(filename), directory))
env = Environment(directory, obj['url'])
# load environment settings
for setting in ('debug', 'cache', 'versions', 'url_expire',
'auto_build',
# TODO: The deprecated values; remove at some point
'expire', 'updater'):
if setting in obj:
setattr(env, setting, obj[setting])
# load custom config options
if 'config' in obj:
env.config.update(obj['config'])
# load bundles
bundles = self._get_bundles(obj.get('bundles', {}))
for name, bundle in bundles.iteritems():
env.register(name, bundle)
return env
finally:
f.close()
开发者ID:abourget,项目名称:webassets,代码行数:55,代码来源:loaders.py
示例8: main
def main():
log = logging.getLogger('webassets')
log.addHandler(logging.StreamHandler())
log.setLevel(logging.DEBUG)
call(["coffee", "-c", "src/tambur.coffee"])
call(["coffee", "-c", "src/tambur_publisher.coffee"])
env = Environment('.', '/static')
tamburjs = Bundle(
'deps/sockjs-0.3.js',
'src/tambur.js', output='out/tambur.js')
tamburminjs = Bundle(
'deps/sockjs-0.3.js',
'src/tambur.js', filters='yui_js', output='out/tambur.min.js')
publishjs = Bundle(
'deps/sha1.js',
'deps/oauth.js',
'src/tambur_publisher.js', output='out/tambur_pub.js')
publishminjs = Bundle(
'deps/sha1.js',
'deps/oauth.js',
'src/tambur_publisher.js', filters='yui_js', output='out/tambur_pub.min.js')
env.register('tambur.js', tamburjs)
env.register('tambur.min.js', tamburminjs)
env.register('tambur_pub.js', publishjs)
env.register('tambur_pub.min.js', publishminjs)
cmdenv = CommandLineEnvironment(env, log)
cmdenv.build()
开发者ID:tamburio,项目名称:tambur.js,代码行数:29,代码来源:assets.py
示例9: test_jinja2_config
def test_jinja2_config(self):
app_config = self.basic_valid_app_config.copy()
dict_loader = DictLoader({})
app_config.update({"jinja2": {"loader": dict_loader,
"use_webassets": True}})
webassets_env = Environment("/tmp", "/")
webassets_env.register("js", "dummy.js", "dummy2.js", output="dummy.js")
config = BlueberryPyConfiguration(app_config=app_config,
webassets_env=webassets_env)
self.assertEqual(config.jinja2_config, {"loader": dict_loader})
开发者ID:wyuenho,项目名称:blueberrypy,代码行数:11,代码来源:test_config.py
示例10: test_append_load_path
def test_append_load_path(self):
env = Environment()
assert env.load_path == []
env.append_path("foo", "/foo")
assert env.load_path == ["foo"]
assert env.url_mapping == {"foo": "/foo"}
# Works without path
env.append_path("bar")
assert env.load_path == ["foo", "bar"]
assert env.url_mapping == {"foo": "/foo"}
开发者ID:ThiefMaster,项目名称:webassets,代码行数:12,代码来源:test_environment.py
示例11: load_environment
def load_environment(self):
"""Load an ``Environment`` instance defined in the YAML file.
Expects the following format::
directory: ../static
url: /media
debug: True
updater: timestamp
config:
compass_bin: /opt/compass
another_custom_config_value: foo
bundles:
bundle-name:
filters: sass,cssutils
output: cache/default.css
contents:
- css/jquery.ui.calendar.css
- css/jquery.ui.slider.css
"""
f, filename = self._open()
try:
obj = self.yaml.load(f) or {}
env = Environment()
# Load environment settings
for setting in ('debug', 'cache', 'versions', 'url_expire',
'auto_build', 'url', 'directory',
# TODO: The deprecated values; remove at some point
'expire', 'updater'):
if setting in obj:
setattr(env, setting, obj[setting])
# Treat the 'directory' option special, make it relative to the
# path of the YAML file, if we know it.
if filename and 'directory' in env.config:
env.directory = path.normpath(
path.join(path.dirname(filename), env.directory))
# Load custom config options
if 'config' in obj:
env.config.update(obj['config'])
# Load bundles
bundles = self._get_bundles(obj.get('bundles', {}))
for name, bundle in bundles.iteritems():
env.register(name, bundle)
return env
finally:
f.close()
开发者ID:eadmundo,项目名称:webassets,代码行数:53,代码来源:loaders.py
示例12: WPConfModifChat
class WPConfModifChat(WPConferenceModifBase):
def __init__(self, rh, conf):
WPConferenceModifBase.__init__(self, rh, conf)
self._conf = conf
self._tabs = {} # list of Indico's Tab objects
self._tabNames = rh._tabs
self._activeTabName = rh._activeTabName
self._aw = rh.getAW()
self._tabCtrl = wcomponents.TabControl()
plugin_htdocs = os.path.join(os.path.dirname(__file__), 'htdocs')
self._plugin_asset_env = Environment(plugin_htdocs, '/InstantMessaging')
self._plugin_asset_env.register('instant_messaging', Bundle('js/InstantMessaging.js',
filters='jsmin',
output="InstantMessaging_%(version)s.min.js"))
def getJSFiles(self):
return WPConferenceModifBase.getJSFiles(self) + \
self._plugin_asset_env['instant_messaging'].urls()
def getCSSFiles(self):
return WPConferenceModifBase.getCSSFiles(self) + \
['InstantMessaging/im.css']
def _createTabCtrl(self):
for tabName in self._tabNames:
url = urlHandlers.UHConfModifChat.getURL(self._conf, tab = tabName)
self._tabs[tabName] = self._tabCtrl.newTab(tabName, tabName, url)
self._setActiveTab()
def _setActiveSideMenuItem(self):
if self._pluginsDictMenuItem.has_key('Instant Messaging'):
self._pluginsDictMenuItem['Instant Messaging'].setActive(True)
def _setActiveTab(self):
self._tabs[self._activeTabName].setActive()
def _getTitle(self):
return WPConferenceModifBase._getTitle(self) + " - " + _("Chat management")
def _getPageContent(self, params):
if len(self._tabNames) > 0:
self._createTabCtrl()
wc = WConfModifChat.forModule(InstantMessaging, self._conf,
self._activeTabName, self._tabNames, self._aw)
return wcomponents.WTabControl(self._tabCtrl, self._getAW()).getHTML(wc.getHTML({}))
else:
return _("No available plugins, or no active plugins")
开发者ID:bubbas,项目名称:indico,代码行数:52,代码来源:pages.py
示例13: create_and_register_bundles
def create_and_register_bundles(section, filter, DEPLOY):
environment = Environment('.')
for option in config.options(section):
deps = [v.strip() for v in config.get(section, option).split(',')]
log.info("%s.%s has dependencies: %s", option, section, deps)
bndl = Bundle(*deps, filters=filter,
output=concat_string([DEPLOY, '/', option, '.', section]))
environment.register(option, bndl)
bndlgz = Bundle(*deps, filters=concat_string([filter, ', gzip']),
output=concat_string([DEPLOY, '/', option, '.', section, '.gz']))
environment.register(concat_string([option, 'gz']), bndlgz)
bndl.build()
bndlgz.build()
开发者ID:outcastgeek,项目名称:python-static-assets-management,代码行数:13,代码来源:static_assets.py
示例14: register_assets
def register_assets(settings):
"""
Initialize webassets environment and its bundles.
Arguments:
settings (conf.model.SettingsModel): Settings registry instance.
Returns:
webassets.Environment: New configured Webasset environment.
"""
logger = logging.getLogger('optimus')
if not settings.ENABLED_BUNDLES:
logger.warning(("Asset registering skipped as there are no enabled "
"bundle"))
return None
logger.info("Starting asset registering")
# Assets bundles
AVAILABLE_BUNDLES = getattr(settings, 'BUNDLES', {})
# Initialize webassets environment
assets_env = AssetsEnvironment()
assets_env.debug = settings.DEBUG
assets_env.url = settings.STATIC_URL
assets_env.directory = settings.STATIC_DIR
assets_env.load_path = [settings.SOURCES_DIR]
assets_env.cache = settings.WEBASSETS_CACHE
assets_env.url_expire = settings.WEBASSETS_URLEXPIRE
#
assets_env.optimus_registry = AssetRegistry()
# Register enabled assets bundles
for bundle_name in settings.ENABLED_BUNDLES:
logger.debug("Registering bundle: {}".format(bundle_name))
assets_env.register(bundle_name, AVAILABLE_BUNDLES[bundle_name])
assets_env.optimus_registry.add_bundle(bundle_name,
AVAILABLE_BUNDLES[bundle_name])
# When after bundle has been registered we can resolve it
for bundle_name in settings.ENABLED_BUNDLES:
logger.info(" Processing: {}".format(
assets_env[bundle_name].resolve_output()
))
# Avoid to loop on every bundle part if we are not in debug logger
if logger.getEffectiveLevel() == logging.DEBUG:
for url in assets_env[bundle_name].urls():
logger.debug(" - {}".format(url))
return assets_env
开发者ID:sveetch,项目名称:Optimus,代码行数:51,代码来源:registry.py
示例15: _setup_env
def _setup_env(app='', debug=True, cache=True):
"""Setup the webassets environment."""
if app:
app_path = path.join('..', '..', app, 'static')
env = Environment(
path.join(INPUT_FILES, '..', '..', 'skel', 'assets'),
path.join(BASE_LOCATION, '..'))
else:
app_path = path.join('..', 'static')
env = Environment(
path.join(INPUT_FILES, '..', '..', 'skel', 'assets'),
path.join(BASE_LOCATION))
# We use underscore's templates by default.
env.config['JST_COMPILER'] = '_.template'
if debug:
env.config['CLOSURE_COMPRESSOR_OPTIMIZATION'] = 'WHITESPACE_ONLY'
env.manifest = False
else:
env.config['CLOSURE_COMPRESSOR_OPTIMIZATION'] = 'ADVANCED_OPTIMIZATIONS'
env.debug = False
env.cache = cache
#javascript
_bundle_app_coffee(app_path, env, debug)
_bundle_3rd_party_js(app_path, env, debug)
#css
_bundle_3rd_party_css(app_path, env, debug)
#images
_bundle_images(app, env, is_skel=True)
return env
开发者ID:johnwlockwood,项目名称:gae-skeleton,代码行数:35,代码来源:skel_assets.py
示例16: test_getconfig_os_env_types
def test_getconfig_os_env_types(self):
"""Test type conversion for values read from the environment.
"""
m = Environment(None, None)
f = Filter()
f.set_environment(m)
get_config = f.get_config
with os_environ_sandbox():
os.environ['foo'] = 'one,two\,three'
assert get_config(env='foo', type=list) == ['one', 'two,three']
# Make sure the split is not applied to env config values
m.config['foo'] = 'one,two\,three'
assert get_config(setting='foo', type=list) == 'one,two\,three'
开发者ID:cnu,项目名称:webassets,代码行数:15,代码来源:test_filters.py
示例17: test_getconfig_os_env_types
def test_getconfig_os_env_types(self):
"""Test type conversion for values read from the environment.
"""
m = Environment(None, None)
f = Filter()
f.set_environment(m)
get_config = f.get_config
with os_environ_sandbox():
os.environ["foo"] = "one,two\,three"
assert list(get_config(env="foo", type=list)) == ["one", "two,three"]
# Make sure the split is not applied to env config values
m.config["foo"] = "one,two\,three"
assert get_config(setting="foo", type=list) == "one,two\,three"
开发者ID:rawberg,项目名称:webassets,代码行数:15,代码来源:test_filters.py
示例18: __init__
def __init__(self, rh, templateClass):
WPAdminPlugins.__init__(self, rh, 'livesync', '')
self._templateClass = templateClass
self._plugin_asset_env = Environment(RHLiveSyncHtdocs._local_path, '/livesync')
self._plugin_asset_env.register('livesync', Bundle('js/livesync.js',
filters='jsmin',
output="InstantMessaging__%(version)s.min.js"))
开发者ID:bubbas,项目名称:indico,代码行数:8,代码来源:chrome.py
示例19: __init__
def __init__(self, rh, templateClass):
WPAdminPlugins.__init__(self, rh, "livesync", "")
self._templateClass = templateClass
self._plugin_asset_env = Environment(RHLiveSyncHtdocs._local_path, "/livesync")
self._plugin_asset_env.register(
"livesync", Bundle("js/livesync.js", filters="jsmin", output="InstantMessaging__%(version)s.min.js")
)
开发者ID:aninhalacerda,项目名称:indico,代码行数:8,代码来源:chrome.py
示例20: _setup_env
def _setup_env(debug=True, cache=True):
"""Setup the webassets environment."""
env = Environment(INPUT_FILES, OUTPUT_FILES)
# We use underscore's templates by default.
env.config['JST_COMPILER'] = '_.template'
if debug:
env.config['CLOSURE_COMPRESSOR_OPTIMIZATION'] = 'WHITESPACE_ONLY'
env.manifest = False
else:
env.config['CLOSURE_COMPRESSOR_OPTIMIZATION'] = 'ADVANCED_OPTIMIZATIONS'
env.debug = False
env.cache = cache
#javascript
_bundle_app_jsts(env, debug)
_bundle_app_coffee(env, debug)
_bundle_3rd_party_js(env, debug)
#css
_bundle_app_less(env, debug)
_bundle_3rd_party_css(env, debug)
#images
_bundle_images(env)
return env
开发者ID:Workiva,项目名称:gae-financials,代码行数:27,代码来源:assets.py
注:本文中的webassets.Environment类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论