diff --git a/examples/bootstrap5/app.py b/examples/bootstrap5/app.py index acb85b23..5e7441d5 100644 --- a/examples/bootstrap5/app.py +++ b/examples/bootstrap5/app.py @@ -287,6 +287,11 @@ def new_message(): return 'Here is the new message page. Return to table.' +@app.route('/image') +def test_image(): + return render_template('image.html') + + @app.route('/icon') def test_icon(): return render_template('icon.html') diff --git a/examples/bootstrap5/static/rectangle-256x64.png b/examples/bootstrap5/static/rectangle-256x64.png new file mode 100644 index 00000000..5a2763de Binary files /dev/null and b/examples/bootstrap5/static/rectangle-256x64.png differ diff --git a/examples/bootstrap5/static/rectangle-256x64.svg b/examples/bootstrap5/static/rectangle-256x64.svg new file mode 100644 index 00000000..ea2403f0 --- /dev/null +++ b/examples/bootstrap5/static/rectangle-256x64.svg @@ -0,0 +1,63 @@ + + + + + + + + + 256 × 64 px + + diff --git a/examples/bootstrap5/templates/image.html b/examples/bootstrap5/templates/image.html new file mode 100644 index 00000000..da6c5551 --- /dev/null +++ b/examples/bootstrap5/templates/image.html @@ -0,0 +1,44 @@ +{% extends 'base.html' %} +{% from 'bootstrap5/utils.html' import render_image, render_figure %} + +{% block content %} +See also https://getbootstrap.com/docs/5.3/content/images/ +and https://getbootstrap.com/docs/5.3/content/figures/. + +

Image

+
{% raw %}{{ render_image(url_for('static', filename='rectangle-256x64.png'), alt='url_for') }}{% endraw %}
+Output: {{ render_image(url_for('static', filename='rectangle-256x64.png'), alt='url_for') }} + +

Thumbnail

+
{% raw %}{{ render_image('static/rectangle-256x64.png', alt='thumb', corner='thumbnail') }}{% endraw %}
+Output: {{ render_image('static/rectangle-256x64.png', alt='thumb', corner='thumbnail') }} + +

Image fluid

+
{% raw %}{{ render_image('static/rectangle-256x64.png', alt='fluid', fluid=True) }}{% endraw %}
+Output: {{ render_image('static/rectangle-256x64.png', alt='fluid', fluid=True) }} + +

Aligned image

+
{% raw %}{{ render_image('static/rectangle-256x64.png', alt='center', text_align='center') }}{% endraw %}
+Output: {{ render_image('static/rectangle-256x64.png', alt='center', text_align='center') }} +
{% raw %}{{ render_image('static/rectangle-256x64.png', alt='end', text_align='end') }}{% endraw %}
+Output: {{ render_image('static/rectangle-256x64.png', alt='end', text_align='end') }} +
{% raw %}{{ render_image('static/rectangle-256x64.png', alt='mx-auto', mx_auto=True) }}{% endraw %}
+Output: {{ render_image('static/rectangle-256x64.png', alt='mx-auto', mx_auto=True) }} + +

Rounded image

+
{% raw %}{{ render_image('static/rectangle-256x64.png', alt='rounded', corner='rounded') }}{% endraw %}
+Output: {{ render_image('static/rectangle-256x64.png', alt='rounded', corner='rounded') }} + +

Float image

+
{% raw %}{{ render_image('static/rectangle-256x64.png', alt='float-start', float='start') }}
+{{ render_image('static/rectangle-256x64.png', alt='float-end', float='end') }}{% endraw %}
+Output: {{ render_image('static/rectangle-256x64.png', alt='float-start', float='start') }}{{ render_image('static/rectangle-256x64.png', alt='float-end', float='end') }} + +

Figure

+
{% raw %}{{ render_figure('static/rectangle-256x64.png', alt='rounded', caption='A caption for the above image.', corner='rounded') }}{% endraw %}
+Output: {{ render_figure('static/rectangle-256x64.png', alt='rounded', caption='A caption for the above image.', corner='rounded') }} +
{% raw %}{{ render_figure('static/rectangle-256x64.png', alt='thumb', caption='A caption for the above image.', corner='thumbnail') }}{% endraw %}
+Output: {{ render_figure('static/rectangle-256x64.png', alt='thumb', caption='A caption for the above image.', corner='thumbnail') }} +
{% raw %}{{ render_figure('static/rectangle-256x64.png', alt='end', caption='A caption for the above image.', text_align='end') }}{% endraw %}
+Output: {{ render_figure('static/rectangle-256x64.png', alt='end', caption='A caption for the above image.', text_align='end') }} +{% endblock %} diff --git a/examples/bootstrap5/templates/index.html b/examples/bootstrap5/templates/index.html index f179ed36..2be8d0bc 100644 --- a/examples/bootstrap5/templates/index.html +++ b/examples/bootstrap5/templates/index.html @@ -10,6 +10,7 @@

Bootstrap-Flask Demo Application

  • Pagination
  • Flash Messages
  • Table
  • +
  • Image
  • Icon
  • Icons
  • diff --git a/flask_bootstrap/templates/bootstrap5/utils.html b/flask_bootstrap/templates/bootstrap5/utils.html index 98aab6bf..8c49f7f9 100644 --- a/flask_bootstrap/templates/bootstrap5/utils.html +++ b/flask_bootstrap/templates/bootstrap5/utils.html @@ -38,3 +38,31 @@ {% endif -%} {% endwith -%} {% endmacro -%} + + +{% macro render_image(src, alt, fluid=False, corner=None, text_align=None, + float=None, mx_auto=False) -%} + {%- if text_align -%} +
    + {%- endif -%} + {{ alt }} + {%- if text_align -%} +
    + {%- endif -%} +{%- endmacro -%} + +{% macro render_figure(src, alt, caption, corner=None, text_align=None) -%} +
    + {{ alt }} +
    {{ caption }}
    +
    +{%- endmacro -%}