{% macro social_login_btn(type, text, large=False) %} Sign in with Twitter {% endmacro %} {{ social_button(button='facebook', class="btn-lg", **{}) }} """ Flask-Pilot Macros Place your macros in here """ # ---- include_css_file() ------------------------------------------------------ {%- macro include_css_file(file) -%} {%- if file.startswith('http') or file.startswith('//') -%} {%- set src = file -%} {%- else -%} {% set src = url_for('static', filename=file) %} {%- endif -%} {%- endmacro -%} # ---- include_js_file() ------------------------------------------------------ {%- macro include_js_file(file) -%} {%- if file.startswith('http') or file.startswith('//') -%} {%- set src = file -%} {%- else -%} {%- set src = url_for('static', filename=file) -%} {%- endif -%} {%- endmacro -%} # ---- img_src() ------------------------------------------------------ {% macro img_src(file, attributes={}) %} {%- if file.startswith('http') or file.startswith('//') %} {% set src = file %} {% else %} {% set src = url_for('static', filename=file) %} {% endif -%} {% endmacro %} # ---- static_url() ------------------------------------------------------ {% macro static_url(url) %} {%- if not file.startswith('http') and not file.startswith('//') %} {% set url = url_for('static', filename=file) %} {% endif -%} {{ url | safe }} {% endmacro %} # ---- google_analytics() ------------------------------------------------------ {% macro google_analytics(code) %} {% endmacro %} #---- show_flashed_messages() ------------------------------------------------------- # Render the flashed messages set {% macro show_flashed_messages(dismissible=True) %} {% for category, message in get_flashed_messages(with_categories=True) %} {%endfor%} {% endmacro %} #---- alert_message() ---------------------------------------------------------- {% macro alert_message(message, category="info", dismissible=False) %} {% endmacro %} #---- show_pagination() -------------------------------------------------------- {% macro show_pagination(paginator, endpoint, kwargs={}) %} {% endmacro %} #---- {# == Form Helpers == Macros to create form input, select, radio, checkbox, textarea compatible to BS3 ::Input: @value {{ f.form_tag('input', 'name', value='John') }} -> {{ f.form_tag('input', 'fileSelect', type='file') }} -> ::Textarea: @value {{ f.form_tag('textarea', 'feedback', value='Irving') }} -> :: Button: @type, @value {{ f.form_tag('button', 'my_button', type='submit', value='Save')}} -> {{ f.form_tag('button', 'submit', type='submit')}} -> :: Checkbox: @options=[[k, v], [k, v]], @checked=[] {{ f.form_tag('checkbox', 'test', options=[[1,'Male'], [2,'Female']], checked=[1]) }}
:: Radio: @options=[[k, v], [k, v]], @checked=[] {{ f.form_tag('radio', 'test', options=[[1,'Male'], [2,'Female']], checked=[1]) }}
:: Select: @options=[[k, v], [k, v]], @selected {{ f.form_tag('select', 'gender', options=[['m', 'Male'], ['f', 'Female']], selected='f') }} #} {% macro form_tag(_tag, name) %} {% set _class = kwargs.pop('class', 'form-control') %} {# input #} {% if _tag == "input" %} {% set _type = kwargs.pop('type', 'text') %} {# textarea: @value #} {% elif _tag == "textarea" %} {% set value = kwargs.pop('value', '') %} {# button: @text=str, @type=str #} {% elif _tag == "button" %} {% set _type = kwargs.pop('type', 'button') %} {% set value = kwargs.pop('text', '') %} {# radio|checkbox: @checked=[], @options=[[k, v], [k,v]], @display_inline=bool #} {% elif _tag in ['radio', 'checkbox'] %} {% set checked = kwargs.pop('checked', []) %} {% set options = kwargs.pop('options', []) %} {% set display_inline = kwargs.pop('display_inline', False) %} {% for item in options %}
{% endfor %} {# select: @options=[[k, v], [k, v]], @selected=str #} {% elif _tag == "select" %} {% set selected = kwargs.pop('selected', '') %} {% set options = kwargs.pop('options', []) %} {% endif %} {% endmacro %} {#:: Form-Group Same as form_tag, except it wrap it in from-group #} {% macro form_group(_tag, name) %} {% set label = kwargs.pop('label', '') %}
{{ form_label(name, label) }} {{ form_tag(_tag, name, **kwargs) }}
{% endmacro %} {#:: Label {{ f.label('name', 'First name') }} -> {{ f.label('name') }} -> {{ f.label('name', class='label', id='name-label') }} -> #} {% macro form_label(for_name, title) %} {% endmacro %}