Skip to content

Commit

Permalink
config: add config-variable for setting menus
Browse files Browse the repository at this point in the history
  • Loading branch information
martinobersteiner committed Apr 9, 2024
1 parent 9fce2f8 commit 4a885b4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
13 changes: 13 additions & 0 deletions flask_menu/config.py
Original file line number Diff line number Diff line change
@@ -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."
7 changes: 7 additions & 0 deletions flask_menu/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

from flask import current_app, g

from . import config
from .menu import MenuNode


Expand All @@ -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()})
Expand All @@ -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."""
Expand Down

0 comments on commit 4a885b4

Please sign in to comment.