def _setup_blueprint(self, module_name, module_ref):
root_dir = os.path.dirname(inspect.getabsfile(module_ref))
kwargs = {}
# Register templates
template_folder = os.path.join(root_dir, 'templates')
if os.path.isdir(template_folder):
kwargs.update({'template_folder': 'templates'})
# Register static files, if any
static_folder = os.path.join(root_dir, 'static')
if os.path.isdir(static_folder):
kwargs.update({
'static_folder': 'static',
'static_url_path': '/static/plugins/{}'.format(module_name)
})
# Generate blueprint
blueprint = flask.Blueprint(module_name, module_name, **kwargs)
# Add the plugin_static() helper function to the
# template context
@blueprint.context_processor
def static_processor():
def plugin_static(filename):
return flask.url_for('{}.static'.format(module_name), filename=filename)
return dict(plugin_static=plugin_static)
# Blueprint done, return it
return blueprint
评论列表
文章目录