{# NAV It builds nav menu from the decorator @nav_menu The menu can be accessed in the __.__NAV_MENU__. __.__NAV_MENU__ is an sorted list of all the menu items Structures: [ (index, name, enpoint or sub_items, kwargs), ... ] index: int - The position of the item name: str - The name to place in the menu |- endpoint: str endpoint #or |- sub_items: list of [ (index, name, endpoint, kwargs), ... ] kwargs: - active - endpoint_kwargs - has_submenu - index - visible: #} {# -------------------------------------------------------------------------- #} {%- macro _format_key(val, def) -%} {{- val | default(def, true) | slug -}} {%- endmacro -%} {# Create a bootstrap navbar :brand: The brand of the site, can include anything. It can be used to add image, ie: brand="" :url: The url when the brand is clicked on :text: A text to use :fluid: If true it will expand menu all across :fixed: If true it will place the menu on top in a fixed position :fixed_padding_top: When fixed, specify the top padding in px :menu_id: if there are more that one menu, to make them unique :groups: (list) - list of menu groups to accept :exclude_groups: (list) - list of menu groups to exclude :show_menus: (bool) - to hide/show menu. Usually for admin when user is not authenticated. per menu show/hide, use [visible] #} {% macro top_nav(brand="", url="/", navbar_text="", navbar_text_align_right=False, fluid=True, fixed=True, fixed_padding_top="70px", menu_id=1, groups=[], exclude_groups=[], show_menus=True) %} {% if fixed %} {% endif %} {% endmacro %} {% macro _navbar_sub_list(nav) %} {% if nav[3]["visible"] %} {% if nav[3]["has_submenu"] and nav[2] %} {% set nav_title = nav[1] %} {% set nav_items = nav[2] %} {% set nav_kwargs = nav[3] %} {% if nav_title %} {% endif %} {% else %} {{ _navbar_nav_item(nav) }} {% endif %} {% endif %} {% endmacro %} {% macro _navbar_nav_item(item) %} {% if item[3]["visible"] %} {% set item_name = item[1] %} {% set item_endpoint = item[2] %} {% set item_kwargs = item[3] %} {% set item_endpoint_kwargs = item_kwargs["endpoint_kwargs"] %} {% if "url" in item_kwargs %} {% set item_url = item_kwargs["url"] %} {% else %} {% set item_url = url_for(item_endpoint, **item_endpoint_kwargs) %} {% endif %}
  • {% if item_kwargs["fa_icon"] %}{% endif %} {{ item_name | safe }}
  • {% endif %} {% endmacro %} {% macro _navbar_list_content(nav, allow_pull=False, align_right=False) %} {% if allow_pull %} {% if align_right %} {% if nav[3]["align_right"] %} {{ _navbar_sub_list(nav) }} {% endif %} {% elif not nav[3]["align_right"] %} {{ _navbar_sub_list(nav) }} {% endif %} {% else %} {{ _navbar_sub_list(nav) }} {% endif %} {% endmacro %} {% macro _navbar_list(allow_pull=true, align_right=false, groups=None, exclude_groups=None) %} {% endmacro %} {# -------------------------------------------------------------------------- #} {# :: Help extract the main title and the sub title for the active menu navigation Useful to quickly bootstrap an admin :: #} {# :: Extract the main menu of the navigation :: #} {% macro current_title() %} {% for nav in __.__NAV_MENU__ %} {% set nav_title = nav[1] %} {% set nav_items = nav[2] %} {% set nav_kwargs = nav[3] %} {% if nav_kwargs["active"] %} {{ nav_title }} {% endif %} {% endfor %} {% endmacro %} {# :: Extract the sub menu of the current endpoint navigation :: #} {% macro current_sub_title(separator=None) %} {% for nav in __.__NAV_MENU__ %} {% set nav_title = nav[1] %} {% set nav_items = nav[2] %} {% set nav_kwargs = nav[3] %} {% if nav_kwargs["active"] %} {% for item in nav_items %} {% set item_name = item[1] %} {% set item_endpoint = item[2] %} {% if item_endpoint == request.endpoint %} {{ separator}} {{ item_name }} {% endif %} {% endfor %} {% endif %} {% endfor %} {% endmacro %} {# -------------------------------------------------------------------------- #} {# BREADCRUM #} {% macro breadcrum(key) %} {% endmacro %} {# -------------------------------------------------------------------------- #} {# panel_list To create custom nav list panel @title: the title of the menu @items: list of tuples of the menu [ (Title, endpoint, **kwargs), (Title, endpoint, **kwargs), ] @panel: type of panel menu @class: custom class #} {% macro panel_list(title, items, panel="default", class="", active=False) %}
    {% endmacro %} {# :: Panel @params key: str - The key name of the menu, to display only this set @params title: str - If you don't want to use the menu @param use_active: bool - When True, it will select the active menu and buil the menu on it @param panel: str - with bootstrap 3, it can be use to change the panel @param class: str - A class name to add to the menu :: #} {% macro panel(key=None, title=None, use_active=False, panel="default", class="") %}
    {% if use_active %} {% for nav in __.__NAV_MENU__ %} {% set nav_title = nav[1] %} {% set nav_items = nav[2] %} {% set nav_kwargs = nav[3] %} {% if nav_kwargs["active"] %} {% if nav_items %} {{ _panel_sub_menu(nav, title) }} {% endif %} {% endif %} {% endfor %} {% elif key %} {% for nav in __.__NAV_MENU__ %} {% set nav_title = nav[1] %} {% set nav_items = nav[2] %} {% set nav_kwargs = nav[3] %} {% if nav_kwargs["key"] == key %} {% if nav_items %} {{ _panel_sub_menu(nav, title) }} {% endif %} {% endif %} {% endfor %} {% else %} {% for nav in __.__NAV_MENU__ %} {% set nav_title = nav[1] %} {% set nav_items = nav[2] %} {% set nav_kwargs = nav[3] %} {% if nav_items %} {{ _panel_sub_menu(nav, title) }} {% endif %} {% endfor %} {% endif %}
    {% endmacro %} {% macro _panel_sub_menu(nav, title=None) %} {% set nav_title = title or nav[1] %} {% set nav_items = nav[2] %} {% set nav_kwargs = nav[3] %} {% endmacro %} {% macro _panel_listgroup(nav_items) %} {% endmacro %}