-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathskeleton.py
More file actions
151 lines (127 loc) · 3.85 KB
/
Copy pathskeleton.py
File metadata and controls
151 lines (127 loc) · 3.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import hyperpython as hp
# noinspection PyUnresolvedReferences
from hyperpython import *
RALEWAY = hp.link(
rel="stylesheet", href="//fonts.googleapis.com/css?family=Raleway:400,300,600"
)
NORMALIZE_CSS = hp.link(
rel="stylesheet", href="//cdn.rawgit.com/necolas/normalize.css/master/normalize.css"
)
SKELETON_CSS = hp.link(
rel="stylesheet",
href="//cdnjs.cloudflare.com/ajax/libs/skeleton/2.0.4/skeleton.min.css",
)
COLUMN_MAP = [
"one",
"two",
"three",
"four",
"five",
"six",
"seven",
"eight",
"nine",
"ten",
"eleven",
"twelve",
]
def cdn():
"""
Provides basic imports from a CDN for skeleton.css.
It adds Raleway font from Google Fonts, and Normalize.css and Miligram.css
from Rawgit.
"""
return hp.Block([RALEWAY, NORMALIZE_CSS, SKELETON_CSS])
#
# Forms and buttons
#
def button(
text, *, href=None, submit=False, reset=False, form=False, primary=False, **kwargs
):
"""
A styled button element.
Args:
text (str or HTML element):
Text content of the button.
href (str):
Optional hyperlink target. If given, the button is create as an
anchor tag.
submit (bool):
If True, renders element as an <input type='submit'> element.
reset (bool):
If True, renders element as an <input type='reset'> element.
form (bool):
If True, renders element as an <input type='button'> element.
primary (bool):
If True, renders a plain-text button with no background color or
outline.
``button`` also accepts additional HTML attributes as keyword arguments.
"""
classes = ["button"]
if primary:
classes.append("button-primary")
if href:
return hp.a(text, href=href, **kwargs).add_class(classes)
elif submit or reset or form:
if not isinstance(text, (str, int, float)):
raise ValueError("submit inputs do not accept rich element children.")
kind = "submit" if submit else "reset" if reset else "button"
return hp.input_(value=text, type=kind, **kwargs).add_class(classes)
else:
return hp.button(text, **kwargs).add_class(classes)
#
# Grid system
#
def container(*children, **kwargs):
"""
Container root of a grid-based layout. Children are passed as arguments.
"""
return hp.div(class_="container", children=children, **kwargs)
def row(*children, **kwargs):
"""
A row that contains several columns as children.
"""
return hp.div(class_="row", children=children, **kwargs)
def column(*children, size=12, offset=None, **kwargs):
"""
A single column inside a 12-columns based flexible row.
Args:
size (1 to 12):
Number of columns this cell spans. Each row has 12 columns, do the
math.
offset (int):
Column offset in the 12-column system.
``column`` also accepts additional HTML attributes as keyword arguments.
"""
classes = [COLUMN_MAP[size - 1], "columns"]
if offset is not None:
name = COLUMN_MAP[offset - 1]
classes.append(f"offset-by-{name}")
return hp.div(children, **kwargs).add_class(classes)
#
# Utilities
#
def full_width(elem):
"""
Renders element with 'width: 100%'
"""
return elem.add_class("u-full-width")
def full_max_width(elem):
"""
Renders element with 'max-width: 100%'
"""
return elem.add_class("u-max-full-width")
def floating(to, elem):
"""
Floats element to left, right or clear floating.
"""
if to == "left":
return elem.add_class("u-pull-left")
elif to == "right":
return elem.add_class("u-pull-right")
elif to == "clear":
return elem.add_class("u-cf")
elif to is None:
return elem
else:
raise ValueError("Invalid float direction")