{% from 'macros.html' import apply_dattrs, apply_classes %} {%- macro bs3_dictlist_group(data, filterkeys=[], filtervals=[], data_attrs=[], asdict=False) %} {# Makes a bootstrap list group from a set of dictionaries Usage: {{ bs3_dictlist_group({'foo': 'bar'}) }} Output:

foo

bar

#} {% if asdict %}{% set data = data._asdict() %}{% endif %}
{% for k, v in data.items() %} {% if k not in filterkeys and v not in filtervals %}

{{ k }}

{{ v }}

{% endif %} {% endfor %}
{% endmacro -%} {%- macro bs3_list_group(data, type='ul') %} {# OL/UL based bootstrap list group Usage: {{ bs3_list_group(['foo', 'bar']) }} Output: #} <{{ type }} class="list-group"> {% for val in data %}
  • {{ val }}
  • {% endfor %} {% endmacro -%} {%- macro bs3_label(value, label_map) -%} {# Convert a dict of values with corresponding label types given a value, to the appropriate label. Usage: {{ bs3_label('PROD', {'dev': 'info', 'stage': 'warning', 'prod': 'danger'}) }} Output: PROD #} {{ value }} {% endmacro -%} {%- macro bs3_panel(items, paneltype='default') -%} {# Generate bs3 panels for a dict of titles/body content. Usage: {{ bs3_panel({'Heading 1': 'Some body text... etc...', 'Heading 2': 'Some body text...'}, paneltype='info') }} Output:

    Heading 1

    Some body text... etc...

    Heading 2

    Some body text...
    #} {% for title, body in items.items() %}

    {{ title }}

    {{ body }}
    {% endfor %} {% endmacro -%} {%- macro bs3_breadcrumb(bcrumbs) %} {# Generate bs3 style breadcrumbs using a dynamic breadcrumbs object. (Most likely from something like flask-breadcrumbs.) Usage: {{ bs3_breadcrumb(breadcrumbs) }} #} {% if bcrumbs %} {% endif %} {% endmacro -%} {%- macro dict2labels(data, filterkeys=[], filtervals=[], aslist=False) %} {# Makes a dict of `name`:`label` into bootstrap labels Usage: {{ dict2labels({'foo': 'danger'}) }} foo {{ dict2labels({'foo': 'danger'}, aslist=False) }} foo Or wrap it in an html list by specifying `aslist`: {{ dict2labels({'foo': 'danger'}, aslist=True) }} #} {% if aslist %}{% endif %} {% endmacro -%} {%- macro dict2tabs(data, filterkeys=[], filtervals=[], asdict=False, id='', headings=False, heading_tag='h4', data_attrs=[], tab_links={}, active='', disabled=[], tab_classes=[], content_classes=[], tab_data_attrs=[], nav_tab_classes=[], tab_content_classes=[], content_data_attrs=[], classes=[]) %} {% if asdict %}{% set data = data._asdict() %}{% endif %} {# Make a dict into a bs3 tab group with tab content. Keys are tab labels, and values are tab content. Usage: {{ dict2tabs({"foo": "Some content rendered from html or macro"}) }} You can also customize styles, data-attrs, etc... see function signature for more info. You can even pass in content generated from other macros, such as the wtform_form macro: {{ dict2tabs({ "tab1": wtform_form(form1, action=url_for('app.page1')), "tab2": wtform_form(form2, action=url_for('app.page2')), id="MyCoolTabContainer", }) }} Note: unless active is specified, order will be determined by sorting the keys. If you need ordering to be specific to the dictionary key order, use `dictlist2tabs` instead. #}
    {% for label in data.keys()|sort %}
    {% if headings %}<{{ heading_tag }}>{{ label }}{% endif %} {{ data[label] }}
    {% endfor %}
    {% endmacro -%} {%- macro dictlist2tabs(data, filterkeys=[], filtervals=[], asdict=False, id='', headings=False, heading_tag='h4', data_attrs=[], tab_links={}, active='', disabled=[], tab_classes=[], content_classes=[], tab_data_attrs=[], nav_tab_classes=[], tab_content_classes=[], content_data_attrs=[], classes=[]) %} {# Make a list of dicts into a bs3 tab group with tab content. Keys are tab labels, and values are tab content. Usage: {{ dictlist2tabs([{"foo": "Some content rendered from html or macro"}]) }} You can also customize styles, data-attrs, etc... see function signature for more info. You can even pass in content generated from other macros, such as the wtform_form macro: {{ dictlist2tabs([ {"tab1": wtform_form(form1, action=url_for('app.page1'))}, {"tab2": wtform_form(form2, action=url_for('app.page2'))}, ], id="MyCoolTabContainer", }) }} Note: unless active is specified, order will be determined by sorting the keys. #}
    {% for item in data %} {% set label = item.keys()[0] %}
    {% if headings %}<{{ heading_tag }}>{{ label }}{% endif %} {{ item[label] }}
    {% endfor %}
    {% endmacro -%}