Skip to content

Commit 524ba95

Browse files
committed
fix infinite recursion on fab_icon
1 parent c5a26b8 commit 524ba95

File tree

4 files changed

+23
-9
lines changed

4 files changed

+23
-9
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ matrix:
77
include:
88
- env: TOXENV=py36
99
python: 3.6
10-
- env: TOXENV=py37
11-
python: 3.7
10+
# - env: TOXENV=py37
11+
# python: 3.7
1212
- env: TOXENV=flake8
1313
python: 3.6
1414

MANIFEST.in

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
include INSTALL.rst
22
include README.rst
33
include LICENSE
4-
include VERSION
54
include requirements.txt
6-
include tasks.py
7-
recursive-include src/bricks/ *.js

src/hyperpython/components/icons.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def icon(icon, href=None, icon_class=lambda x: x, **kwargs):
99
If an href attribute is passed, it wraps the results into a anchor link.
1010
"""
1111
if href:
12-
return a(_icon(icon, href=href, **kwargs))
12+
return a(_icon(icon, **kwargs), href=href)
1313
return i(**kwargs).add_class(icon_class(icon))
1414

1515

@@ -19,14 +19,16 @@ def fa_icon(icon, href=None, collection=None, **kwargs):
1919
"""
2020
if collection is None:
2121
collection = FA_COLLECTIONS.get(icon, 'fa')
22+
if href:
23+
return a(fa_icon(icon, collection=collection, **kwargs), href=href)
2224
return _icon(icon, href, lambda x: [collection, f'fa-{icon}'], **kwargs)
2325

2426

2527
def fab_icon(icon, href=None, **kwargs):
2628
"""
2729
Font awesome brands icon.
2830
"""
29-
return fab_icon(icon, href, collection='fab', **kwargs)
31+
return fa_icon(icon, href, collection='fab', **kwargs)
3032

3133

3234
_icon = icon

tests/test_components.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import pytest
22

33
from hyperpython import Text
4-
from hyperpython.components import hyperlink, render_html, render, html_table, html_list, html_map
5-
from hyperpython.components.hyperlinks import split_link, a_or_p, a_or_span
4+
from hyperpython.components import (
5+
hyperlink, render_html, render, html_table, html_list, html_map, a_or_p,
6+
a_or_span, fab_icon, fa_icon,
7+
)
8+
from hyperpython.components.hyperlinks import split_link
69

710

811
class CustomType:
@@ -91,3 +94,15 @@ def test_render_html_list(self):
9194
def test_render_html_map(self):
9295
assert (html_map({'foo': 'bar'}, class_='foo').__html__()
9396
== '<dl class="foo"><dt>foo</dt><dd>bar</dd></dl>')
97+
98+
99+
class TestIcons:
100+
def test_render_font_awesome_icons(self):
101+
assert str(fa_icon('user')) == '<i class="fa fa-user"></i>'
102+
assert str(fa_icon('github')) == '<i class="fab fa-github"></i>'
103+
assert str(fab_icon('github')) == '<i class="fab fa-github"></i>'
104+
105+
def test_render_icon_with_link(self):
106+
assert str(fa_icon('user', href='#')) == '<a href="#"><i class="fa fa-user"></i></a>'
107+
assert str(fa_icon('github', href='#')) == '<a href="#"><i class="fab fa-github"></i></a>'
108+
assert str(fab_icon('github', href='#')) == '<a href="#"><i class="fab fa-github"></i></a>'

0 commit comments

Comments
 (0)