From 17d0b17a86d975e2e7b1ab3352458e7a7ff01d5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Fri, 30 Jan 2015 22:22:08 +0100 Subject: [PATCH] Blueprints of BlueprintPlugins now also get instantiated with defined template and static folder, plugins may override this via get_blueprint_kwargs --- src/octoprint/plugin/types.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/octoprint/plugin/types.py b/src/octoprint/plugin/types.py index cc6a8b52..d3cc6743 100644 --- a/src/octoprint/plugin/types.py +++ b/src/octoprint/plugin/types.py @@ -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.