Skip to content

Commit 5ca6fb4

Browse files
committed
can use underscored in params
1 parent 77da060 commit 5ca6fb4

File tree

5 files changed

+56
-6
lines changed

5 files changed

+56
-6
lines changed

Pipfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[[source]]
2+
name = "pypi"
3+
url = "https://pypi.org/simple"
4+
verify_ssl = true
5+
6+
[dev-packages]
7+
8+
[packages]
9+
10+
[requires]
11+
python_version = "3.6"

beam/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from .tag import (_del, _input, a, abbr, address, article, aside, audio,
1919
blockquote, body, br, button, caption, cite, dd, dfn, div,
2020
dl, dt, em, fieldset, figcaption, figure, footer, form, h1,
21-
h2, h3, h4, h5, h6, head, header, hr, html, img, ins, kbd,
21+
h2, h3, h4, h5, h6, head, header, hr, html, i, img, ins, kbd,
2222
label, legend, li, link, mark, meta, nav, ol, optgroup,
2323
option, p, pre, progress, q, script, section, select, source,
2424
span, strong, style, sub, sup, table, tbody, td, textarea,
@@ -34,8 +34,8 @@
3434
# Structure
3535
'abbr', 'blockquote', 'cite', 'q', 'sup', 'sub', 'strong', 'em', 'mark',
3636
'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'img', 'figure', 'figcaption', 'audio',
37-
'video', 'source', 'a', 'br', 'p', 'hr', 'address', '_del', 'ins', 'dfn',
38-
'kbd', 'pre', 'progress', 'time',
37+
'video', 'source', 'a', 'br', 'p', 'hr', 'i', 'address', '_del', 'ins',
38+
'dfn', 'kbd', 'pre', 'progress', 'time',
3939

4040
# List
4141
'ul', 'ol', 'li', 'dl', 'dt', 'dd',

beam/tag.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ def render(self):
3939

4040
for key in self.param:
4141
# ex: href="https://{site}"
42-
key_param = key.replace("_", "")
42+
if key.startswith("_"):
43+
key_param = key.replace("_", "", 1)
44+
else:
45+
key_param = key.replace("_", "-")
4346
value_param = self.param[key]
4447

4548
result = f'{key_param}="{value_param}"'
@@ -261,6 +264,10 @@ class hr(SingleElement):
261264
pass
262265

263266

267+
class i(Element):
268+
pass
269+
270+
264271
class address(Element):
265272
pass
266273

bootstrap.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from beam import button, div
2+
from beam.utils import classing
3+
4+
5+
def container(*args, breakpoint=''):
6+
if breakpoint:
7+
breakpoint = '-' + breakpoint
8+
9+
return div(*args, _class=f"container{breakpoint}")
10+
11+
12+
def alert(*args):
13+
return div(*args, _class=["alert", "alert-primary"], role="alert")
14+
15+
16+
def btn(*args, color="primary", block=False, **kwargs):
17+
_class = kwargs.pop('_class', [])
18+
19+
c = ["btn", f"btn-{color}"]
20+
21+
if block:
22+
c.append("btn-block")
23+
24+
c = classing(_class, c)
25+
26+
return button(*args, _class=c, **kwargs)

tests/test_tag.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33

44
def test_main():
5-
component = div(h1("Title"), hr(), _class="content",)
5+
component = div(h1("Title"), hr(), _class="content", _id="content")
66

77
assert component.render() == (
8-
'<div class="content"><h1>Title</h1><hr/></div>'
8+
'<div class="content" id="content"><h1>Title</h1><hr/></div>'
99
)
1010

1111

@@ -100,3 +100,9 @@ def test_reserved_name():
100100
component = _input()
101101

102102
assert component.render() == '<input/>'
103+
104+
105+
def test_underscore_attribute():
106+
component = a(data_attribute="value")
107+
108+
assert component.render() == '<a data-attribute="value"></a>'

0 commit comments

Comments
 (0)