{% from 'utils.html' import apply_dattrs, apply_classes %} {% macro progress(percent, animated=False, classes=[], context=None, min=0, max=100, striped=False, show_percent=True ) %} {# Create a bootstrap progress bar with lots of options. Usage: {{ progress(30) }} {{ progress(100, animated=True, striped=True) }} {{ progress(89, context='success') }} {{ progress(89, context='danger') }} {{ progress(89, context='warning') }} {{ progress(89, context='info') }} #}
{{ percent }}%
{% endmacro %} {% macro modal(id, content, classes=[], close_btns=True, fade=True, footer=None, include_btn=False, include_btn_text='Trigger Modal', title=None ) %} {# Makes a bootstrap modal Usage: {{ modal('someId', 'Some html or text...', title='My Modal') }} #} {% if include_btn %} {{ include_btn_text }} {% endif %} {% endmacro %} {% macro dict2carousel(id, items, active=0, classes=[], data_attrs=[], show_arrows=True ) %} {# Makes a bootstrap carousel Usage: {{ dict2carousel( 'someId', [ {'content': 'foo1', 'caption': 'foo'}, {'content': 'foo2', 'caption': 'bar'}, {'content': 'foo3', 'caption': 'baz'}, ], active=2) }} #}
{% if show_arrows %} {% endif %}
{% endmacro %} {%- macro bs3_dictlist_group(data, classes=[], 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, classes=[], type='ul') %} {# OL/UL based bootstrap list group Usage: {{ bs3_list_group(['foo', 'bar']) }} Output: #} <{{ type }} class="{{ apply_classes(classes + ['list-group']) }}"> {% for val in data %}
  • {{ val }}
  • {% endfor %} {% endmacro -%} {%- macro dictlist_group_badged(data, classes=[], type='ul', align='right') %} {# OL/UL based bootstrap list group with badge labels on the right (default). From: http://getbootstrap.com/components/#list-group-badges Usage: {{ dictlist_group_badged({'Messages': 20, 'Unread': 10, 'Read': 100, 'Starred': 34}) }} Output: #} <{{ type }} class="{{ apply_classes(classes + ['list-group']) }}"> {% for val, label in data.items() %}
  • {% if align == 'left' %} {{ label }} {% endif %} {{ val }} {% if align == 'right' %} {{ label }} {% endif %}
  • {% endfor %} {% endmacro -%} {%- macro bs3_label(value, label_map, text=None) -%} {# 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 #} {{ text if text else 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', heading_macros={}, 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 -%}