def create_library(name, path): """Create WebAssets library(set of Bundles). """ config_path = os.path.join(path, u'webassets.yml') if not os.path.exists(config_path): return library = YAMLLoader(config_path).load_bundles() bundles = { u'/'.join([name, key]): bundle for key, bundle in library.items() } # Unfortunately, you'll get an error attempting to register bundle # with the same name twice. For now, let's just pop existing # bundle and avoid name-conflicts # TODO: make PR into webassets with preferable solution # Issue: https://github.com/miracle2k/webassets/issues/519 for name, bundle in bundles.items(): env._named_bundles.pop(name, None) env.register(name, bundle) env.append_path(path)
def create_library(name, path): """Create WebAssets library(set of Bundles). """ config_path = os.path.join(path, u'webassets.yml') if not os.path.exists(config_path): return library = YAMLLoader(config_path).load_bundles() bundles = { u'/'.join([name, key]): bundle for key, bundle in library.items() } # Unfortunately, you'll get an error attempting to register bundle # with the same name twice. For now, let's just pop existing # bundle and avoid name-conflicts # TODO: make PR into webassets with preferable solution # Issue: https://github.com/miracle2k/webassets/issues/519 for name, bundle in bundles.items(): env._named_bundles.pop(name, None) env.register(name, bundle) env.append_path(path)
# load configs app.config.from_pyfile('config/default.cfg') # dev config will override anything set on line above if os.getenv('DEV_CONFIGURATION'): app.config.from_envvar('DEV_CONFIGURATION') # attach assets assets = Environment(app) assets.versions = 'hash' assets.url = app.static_url_path manifest_path = os.path.realpath( os.path.join(os.path.dirname(__file__), '.static-manifest')) assets.manifest = 'file://%s' % manifest_path bundles = YAMLLoader(os.path.realpath( os.path.join(os.path.dirname(__file__), 'assets.yml'))).load_bundles() for bundle_name, bundle in bundles.items(): assets.register(bundle_name, bundle) # set up logging if not app.debug: log_format = logging.Formatter(""" --- Message type: %(levelname)s Location: %(pathname)s:%(lineno)d Module: %(module)s Time: %(asctime)s %(message)s """) stream_handler = logging.StreamHandler()
if os.getenv('SPAMSUB_CONFIGURATION'): app.config.from_envvar('SPAMSUB_CONFIGURATION') # attach assets assets = Environment(app) assets.versions = 'hash' manifest_path = os.path.realpath( os.path.join(os.path.dirname(__file__), '.static-manifest')) assets.manifest = 'file://%s' % manifest_path bundles = YAMLLoader(os.path.realpath( os.path.join(os.path.dirname(__file__), 'assets.yml'))).load_bundles() for bundle_name, bundle in bundles.items(): assets.register(bundle_name, bundle) ## import our own blueprints here if necessary # from apps.foo.views import foo_app # attach any blueprints # app.register_blueprint(foo_app, url_prefix='/foo') # Error handling @app.errorhandler(404) def page_not_found(error): """ 404 handler """ return render_template( 'errors/404.jinja'), 404