inveniosoftware / flask-menu

Flask-Menu is a Flask extension that adds support for generating menus.
https://flask-menu.readthedocs.io
Other
53 stars 45 forks source link

global: check for extension initialization in "register_menu" #65

Open slint opened 6 years ago

slint commented 6 years ago

There are scenarios where some flask extension might want to provide Flask-Menu capabilities for its blueprints, but the user of the extension is not interested in this (e.g. if the application doesn't have any UI views, but only provides a REST API).

It should be possible to conditionally register the menu item, by checking if current_menu exists before performing the registration:

# inside register_menu
...
@before_first_request
def _register_menu_item():
    if current_menu:
        item = current_menu.submenu(str(path))
        item.register(...)
return f
...