-
-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #365 from helloflask/fix-badge
Fix the badge classes in `render_nav_item` macro for Bootstrap 5
- Loading branch information
Showing
6 changed files
with
68 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,11 @@ | ||
{% extends 'base/nav.html' %} | ||
|
||
{% macro render_nav_item(endpoint, text, _badge='', _use_li=False, _badge_classes='badge badge-light') %} | ||
{% set active = True if request.endpoint and request.endpoint == endpoint else False %} | ||
{% if _use_li %}<li class="nav-item">{% endif %} | ||
<a class="{% if not _use_li %}nav-item {% endif %}nav-link{% if active %} active" aria-current="page{% endif %}" | ||
href="{{ url_for(endpoint, **kwargs) }}"> | ||
{{ text }} {% if _badge %}<span class="{{ _badge_classes }}">{{ _badge }}</span>{% endif %} | ||
</a> | ||
{% if _use_li %}</li>{% endif %} | ||
{% endmacro %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,11 @@ | ||
{% extends 'base/nav.html' %} | ||
|
||
{% macro render_nav_item(endpoint, text, _badge='', _use_li=False, _badge_classes='badge text-bg-light') %} | ||
{% set active = True if request.endpoint and request.endpoint == endpoint else False %} | ||
{% if _use_li %}<li class="nav-item">{% endif %} | ||
<a class="{% if not _use_li %}nav-item {% endif %}nav-link{% if active %} active" aria-current="page{% endif %}" | ||
href="{{ url_for(endpoint, **kwargs) }}"> | ||
{{ text }} {% if _badge %}<span class="{{ _badge_classes }}">{{ _badge }}</span>{% endif %} | ||
</a> | ||
{% if _use_li %}</li>{% endif %} | ||
{% endmacro %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from flask import render_template_string | ||
|
||
|
||
def test_render_nav_item(app, client): | ||
@app.route('/hello') | ||
def hello(): | ||
return 'Hello' | ||
|
||
@app.route('/nav_item/4') | ||
def test_bootstrap4(): | ||
return render_template_string(''' | ||
{% from 'bootstrap4/nav.html' import render_nav_item %} | ||
{{ render_nav_item('hello', 'Hello Nav', _badge='beta') }} | ||
''') | ||
|
||
@app.route('/nav_item/5') | ||
def test_bootstrap5(): | ||
return render_template_string(''' | ||
{% from 'bootstrap5/nav.html' import render_nav_item %} | ||
{{ render_nav_item('hello', 'Hello Nav', _badge='beta', _use_li=True) }} | ||
''') | ||
|
||
response = client.get('/nav_item/4') | ||
data = response.get_data(as_text=True) | ||
assert 'href="/hello">' in data | ||
assert 'span class="badge badge-light"' in data | ||
assert 'beta' in data | ||
assert '<li class="nav-item">' not in data | ||
assert '</li>' not in data | ||
|
||
response = client.get('/nav_item/5') | ||
data = response.get_data(as_text=True) | ||
assert 'href="/hello">' in data | ||
assert 'span class="badge text-bg-light"' in data | ||
assert 'beta' in data | ||
assert '<li class="nav-item">' in data | ||
assert '</li>' in data |