本文整理汇总了Python中flask_assets.Environment类的典型用法代码示例。如果您正苦于以下问题:Python Environment类的具体用法?Python Environment怎么用?Python Environment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Environment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_app
def create_app(object_name='bosphorus.settings', env='dev'):
app = create_barebones_app(object_name, env)
# Import and register the different asset bundles
assets_env = Environment()
assets_env.init_app(app)
assets_loader = PythonAssetsLoader(assets)
for name, bundle in assets_loader.load_bundles().iteritems():
assets_env.register(name, bundle)
# register our blueprints
from controllers.main import main
from controllers.user import user
from controllers.studies import studies
from controllers.person import person
from controllers.protocol import protocol
from utils import proxy
app.register_blueprint(main)
app.register_blueprint(user)
app.register_blueprint(person)
app.register_blueprint(studies)
app.register_blueprint(protocol)
app.register_blueprint(proxy)
return app
示例2: init_app
def init_app(app):
assets = Environment(app)
assets.register("css_vendor", css_vendor)
assets.register("js_vendor", js_vendor)
assets.register("css_linkedlist", css_linkedlist)
assets.manifest = 'cache' if not app.debug else False
assets.cache = not app.debug
assets.debug = app.debug
示例3: init_app
def init_app(app):
webassets = Environment(app)
webassets.register('css_all', css_all)
webassets.register('js_vendor', js_vendor)
webassets.register('js_main', js_main)
webassets.manifest = 'cache' if not app.debug else False
webassets.cache = not app.debug
webassets.debug = app.debug
示例4: InvenioAssets
class InvenioAssets(object):
"""Invenio asset extension."""
def __init__(self, app=None, **kwargs):
r"""Extension initialization.
:param app: An instance of :class:`~flask.Flask`.
:param \**kwargs: Keyword arguments are passed to ``init_app`` method.
"""
self.env = Environment()
self.collect = Collect()
if app:
self.init_app(app, **kwargs)
def init_app(self, app, entry_point_group='invenio_assets.bundles',
**kwargs):
"""Initialize application object.
:param app: An instance of :class:`~flask.Flask`.
:param entry_point_group: A name of entry point group used to load
``webassets`` bundles.
.. versionchanged:: 1.0.0b2
The *entrypoint* has been renamed to *entry_point_group*.
"""
self.init_config(app)
self.env.init_app(app)
self.collect.init_app(app)
if entry_point_group:
self.load_entrypoint(entry_point_group)
app.extensions['invenio-assets'] = self
def init_config(self, app):
"""Initialize configuration.
:param app: An instance of :class:`~flask.Flask`.
"""
app.config.setdefault('REQUIREJS_BASEURL', app.static_folder)
app.config.setdefault('COLLECT_STATIC_ROOT', app.static_folder)
app.config.setdefault('COLLECT_STORAGE', 'flask_collect.storage.link')
app.config.setdefault(
'COLLECT_FILTER', partial(collect_staticroot_removal, app))
def load_entrypoint(self, entry_point_group):
"""Load entrypoint.
:param entry_point_group: A name of entry point group used to load
``webassets`` bundles.
.. versionchanged:: 1.0.0b2
The *entrypoint* has been renamed to *entry_point_group*.
"""
for ep in pkg_resources.iter_entry_points(entry_point_group):
self.env.register(ep.name, ep.load())
示例5: init_app
def init_app(self, app):
env = Environment(app)
env.url_expire = True
env.register('css_app', css_app)
env.register('js_app', js_app)
env.manifest = 'cache' if not app.debug else False
env.cache = not app.debug
env.debug = app.debug
示例6: init
def init(app):
assets = Environment(app)
js = Bundle(*app.config['JS_ASSETS'],
output=app.config['JS_ASSETS_OUTPUT'],
filters=app.config['JS_ASSETS_FILTERS'])
css = Bundle(*app.config['CSS_ASSETS'],
output=app.config['CSS_ASSETS_OUTPUT'],
filters=app.config['CSS_ASSETS_FILTERS'])
assets.register('js_all', js)
assets.register('css_all', css)
示例7: init_app
def init_app(app):
webassets = Environment(app)
webassets.url = app.static_url_path
webassets.register('js_lodjers', js_lodjers)
webassets.register('js_mixpanel', js_mixpanel)
webassets.register('css_lodjers', css_lodjers)
webassets.manifest = 'cache' if not app.debug else False
webassets.cache = not app.debug
webassets.debug = app.debug
示例8: register_assets
def register_assets(app):
"""Register Webassets in the app"""
_create_code_css(app)
assets = Environment(app)
bundle = Bundle('style/main.less', 'style/code.css',
filters='less,cleancss',
output='css/main.%(version)s.css')
assets.register('css', bundle)
app.add_url_rule(
'/static/fonts/bootstrap/<path:filename>',
'bootstrap_fonts',
bootstrap_fonts)
示例9: init_app
def init_app(app, allow_auto_build=True):
assets = Environment(app)
# on google app engine put manifest file beside code
# static folders are stored separately and there is no access to them in production
folder = os.path.abspath(os.path.dirname(__file__)) if "APPENGINE_RUNTIME" in os.environ else ""
assets.directory = os.path.join(app.static_folder, "compressed")
assets.manifest = "json:{}/manifest.json".format(assets.directory)
assets.url = app.static_url_path + "/compressed"
compress = not app.debug # and False
assets.debug = not compress
assets.auto_build = compress and allow_auto_build
assets.register('js', Bundle(*JS, filters='yui_js', output='script.%(version)s.js'))
assets.register('css', Bundle(*CSS, filters='yui_css', output='style.%(version)s.css'))
示例10: register_assets
def register_assets(app):
bundles = {
'home_js': Bundle('style/js/jquery.min.js',
'style/js/bootstrap.min.js',
'style/honmaple.js',
output='style/assets/home.js',
filters='jsmin'),
'home_css': Bundle('style/css/bootstrap.min.css',
'style/honmaple.css',
output='style/assets/home.css',
filters='cssmin')
}
assets = Environment(app)
assets.register(bundles)
示例11: setup
class TestConfigNoAppBound:
"""The application is not bound to a specific app.
"""
def setup(self):
self.env = Environment()
def test_no_app_available(self):
"""Without an application bound, we can't do much."""
assert_raises(RuntimeError, setattr, self.env, 'debug', True)
assert_raises(RuntimeError, self.env.config.get, 'debug')
def test_global_defaults(self):
"""We may set defaults even without an application, however."""
self.env.config.setdefault('FOO', 'BAR')
with Flask(__name__).test_request_context():
assert self.env.config['FOO'] == 'BAR'
def test_multiple_separate_apps(self):
"""Each app has it's own separate configuration.
"""
app1 = Flask(__name__)
self.env.init_app(app1)
# With no app yet available...
assert_raises(RuntimeError, getattr, self.env, 'url')
# ...set a default
self.env.config.setdefault('FOO', 'BAR')
# When an app is available, the default is used
with app1.test_request_context():
assert self.env.config['FOO'] == 'BAR'
# If the default is overridden for this application, it
# is still valid for other apps.
self.env.config['FOO'] = '42'
assert self.env.config['FOO'] == '42'
app2 = Flask(__name__)
with app2.test_request_context():
assert self.env.config['FOO'] == 'BAR'
def test_key_error(self):
"""KeyError is raised if a config value doesn't exist.
"""
with Flask(__name__).test_request_context():
assert_raises(KeyError, self.env.config.__getitem__, 'YADDAYADDA')
# The get() helper, on the other hand, simply returns None
assert self.env.config.get('YADDAYADDA') == None
示例12: register_assets
def register_assets(app):
bundles = {
'home_js': Bundle(
'style/js/jquery.min.js', #这里直接写static目录的子目录 ,如static/bootstrap是错误的
'style/js/bootstrap.min.js',
output='style/assets/home.js',
filters='jsmin'),
'home_css': Bundle(
'style/css/bootstrap.min.css',
output='style/assets/home.css',
filters='cssmin')
}
assets = Environment(app)
assets.register(bundles)
示例13: register_assets
def register_assets(app):
assets = Environment(app)
assets.debug = app.debug
assets.auto_build = True
assets.url = app.static_url_path
css_blog = Bundle(*BLOG_ASSETS, filters='cssmin', output='css/blog.min.css')
css_welcome = Bundle(*INDEX_ASSETS, filters='cssmin', output='css/welcome.min.css')
js_all = Bundle(*JS_ASSETS, filters='rjsmin', output='js/all.min.js')
assets.register('css_blog', css_blog)
assets.register('css_welcome', css_welcome)
assets.register('js_all', js_all)
app.logger.info("Registered assets...")
return assets
示例14: __init__
def __init__(self, app=None, entrypoint="invenio_assets.bundles", **kwargs):
"""Extension initialization."""
self.env = Environment()
self.collect = Collect()
self.entrypoint = entrypoint
if app:
self.init_app(app, **kwargs)
示例15: register_assets
def register_assets(app):
assets = Environment(app)
assets.url = app.static_url_path
assets.directory = app.static_folder
assets.append_path('assets')
scss = Bundle('scss/main.scss', filters='pyscss', output='main.css', depends=('scss/*.scss'))
assets.register('scss_all', scss)