From 4a885b460c810ee9b259e8452224bbb6b3c4a217 Mon Sep 17 00:00:00 2001 From: Martin Obersteiner Date: Tue, 9 Apr 2024 10:26:31 +0200 Subject: [PATCH] config: add config-variable for setting menus --- flask_menu/config.py | 13 +++++++++++++ flask_menu/ext.py | 7 +++++++ 2 files changed, 20 insertions(+) create mode 100644 flask_menu/config.py diff --git a/flask_menu/config.py b/flask_menu/config.py new file mode 100644 index 0000000..0f840bb --- /dev/null +++ b/flask_menu/config.py @@ -0,0 +1,13 @@ +# -*- coding: utf-8 -*- +# +# This file is part of Flask-Menu +# Copyright (C) 2024 Graz University of Technology. +# +# Flask-Menu is free software; you can redistribute it and/or modify +# it under the terms of the Revised BSD License; see LICENSE file for +# more details. + +"""Default configuration for Flask-Menu.""" + +FLASK_MENU = {} +"Make menus setable via config." diff --git a/flask_menu/ext.py b/flask_menu/ext.py index 9767ed6..0c4a85c 100644 --- a/flask_menu/ext.py +++ b/flask_menu/ext.py @@ -13,6 +13,7 @@ from flask import current_app, g +from . import config from .menu import MenuNode @@ -34,6 +35,8 @@ def init_app(self, app): if "menu" in app.extensions: raise RuntimeError("Flask application is already initialized.") + self.init_config(app) + app.extensions["menu"] = self app.context_processor(lambda: {"current_menu": Menu.root()}) @@ -44,6 +47,10 @@ def url_preprocessor(route, args): g._menu_kwargs = args g._menu_route = route + def init_config(self, app): + "Initialize configuration." + app.config["FLASK_MENU"] = config.FLASK_MENU + @staticmethod def root(): """Return a root entry of current application's menu."""