Blueprints of BlueprintPlugins now also get instantiated with defined template and static folder, plugins may override this via get_blueprint_kwargs

This commit is contained in:
Gina Häußge 2015-01-30 22:22:08 +01:00
parent 2f5e955367
commit 17d0b17a86

View file

@ -466,7 +466,8 @@ class BlueprintPlugin(Plugin):
"""
import flask
blueprint = flask.Blueprint("plugin." + self._identifier, self._identifier)
kwargs = self.get_blueprint_kwargs()
blueprint = flask.Blueprint("plugin." + self._identifier, self._identifier, **kwargs)
for member in [member for member in dir(self) if not member.startswith("_")]:
f = getattr(self, member)
if hasattr(f, "_blueprint_rules") and member in f._blueprint_rules:
@ -475,6 +476,20 @@ class BlueprintPlugin(Plugin):
blueprint.add_url_rule(rule, options.pop("endpoint", f.__name__), view_func=f, **options)
return blueprint
def get_blueprint_kwargs(self):
"""
Override this if you want your blueprint constructed with additional options such as ``static_folder``,
``template_folder``, etc.
Defaults to the blueprint's ``static_folder`` and ``template_folder`` to be set to the plugin's basefolder
plus ``/static`` or respectively ``/templates``.
"""
import os
return dict(
static_folder=os.path.join(self._basefolder, "static"),
template_folder=os.path.join(self._basefolder, "templates")
)
def is_blueprint_protected(self):
"""
Whether a valid API key is needed to access the blueprint (the default) or not.