Skip to content

Commit 337001b

Browse files
authored
Merge pull request #2 from python-ellar/svg_components
Extra SVG Component
2 parents 06ac2ba + 65143bf commit 337001b

File tree

4 files changed

+237
-4
lines changed

4 files changed

+237
-4
lines changed

README.md

+23-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ Although there are Jinja and Mako in this space, I don't intend to make this lib
99

1010
**This is just an experiment.**
1111

12+
## Installation
13+
```shell
14+
pip install py-htmlbuilder
15+
```
16+
1217
## Quick Bootstrap Example
1318

1419
```python
@@ -37,7 +42,24 @@ def template():
3742
el.header(
3843
class_name="pb-3 mb-4 border-bottom",
3944
*(
40-
el.a(href="/", class_name="d-flex align-items-center text-dark text-decoration-none"),
45+
el.a(href="/", class_name="d-flex align-items-center text-dark text-decoration-none", *(
46+
el.svg(width=40, height=32, class_name="me-2", viewBox="0 0 118 94", *(
47+
el.path(fill_rule="evenodd", clip_rule="evenodd", fill="currentColor", d=(
48+
"""
49+
M24.509 0c-6.733 0-11.715 5.893-11.492 12.284.214 6.14-.064 14.092-2.066 20.577C8.943
50+
39.365 5.547 43.485 0 44.014v5.972c5.547.529 8.943 4.649 10.951 11.153 2.002 6.485 2.28
51+
14.437 2.066 20.577C12.794 88.106 17.776 94 24.51 94H93.5c6.733 0 11.714-5.893
52+
11.491-12.284-.214-6.14.064-14.092 2.066-20.577 2.009-6.504 5.396-10.624
53+
10.943-11.153v-5.972c-5.547-.529-8.934-4.649-10.943-11.153-2.002-6.484-2.28-14.437-2.066-20.577C105.214
54+
5.894 100.233 0 93.5 0H24.508zM80 57.863C80 66.663 73.436 72 62.543 72H44a2
55+
2 0 01-2-2V24a2 2 0 012-2h18.437c9.083 0 15.044 4.92 15.044 12.474 0 5.302-4.01
56+
10.049-9.119 10.88v.277C75.317 46.394 80 51.21 80 57.863zM60.521 28.34H49.948v14.934h8.905c6.884
57+
0 10.68-2.772 10.68-7.727 0-4.643-3.264-7.207-9.012-7.207zM49.948 49.2v16.458H60.91c7.167
58+
0 10.964-2.876 10.964-8.281 0-5.406-3.903-8.178-11.425-8.178H49.948z
59+
"""
60+
)),
61+
)),
62+
)),
4163
el.span("Jumbotron example", class_name="fs-4")
4264
)
4365
),

py_html/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
"""PyHTML is HTML in python objects"""
1+
"""PyHTMLBuilder is HTML in python objects"""
22

3-
__version__ = "0.1.0"
3+
__version__ = "0.1.1"

py_html/el/__init__.py

+36
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,15 @@
183183
from .elements.images import (
184184
Canvas as canvas,
185185
)
186+
from .elements.images import (
187+
Circle as circle,
188+
)
189+
from .elements.images import (
190+
Defs as defs,
191+
)
192+
from .elements.images import (
193+
Ellipse as ellipse,
194+
)
186195
from .elements.images import (
187196
FigCaption as figcaption,
188197
)
@@ -192,15 +201,33 @@
192201
from .elements.images import (
193202
Image as img,
194203
)
204+
from .elements.images import (
205+
LinearGradient as linearGradient,
206+
)
195207
from .elements.images import (
196208
Map as map,
197209
)
210+
from .elements.images import (
211+
Path as path,
212+
)
198213
from .elements.images import (
199214
Picture as picture,
200215
)
216+
from .elements.images import (
217+
Polygon as polygon,
218+
)
219+
from .elements.images import (
220+
Rect as rect,
221+
)
222+
from .elements.images import (
223+
Stop as stop,
224+
)
201225
from .elements.images import (
202226
Svg as svg,
203227
)
228+
from .elements.images import (
229+
Text as text,
230+
)
204231
from .elements.images import (
205232
Use as use,
206233
)
@@ -433,6 +460,15 @@
433460
"video",
434461
"track",
435462
"source",
463+
"circle",
464+
"rect",
465+
"polygon",
466+
"defs",
467+
"linearGradient",
468+
"stop",
469+
"ellipse",
470+
"text",
471+
"path",
436472
"BaseElement",
437473
"BaseHTML",
438474
"Element",

py_html/el/elements/images.py

+176-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import typing as t
22

3-
from py_html.el.base import BaseHTML
3+
from py_html.el.base import BaseElement, BaseHTML
44

55

66
class Image(BaseHTML):
@@ -164,11 +164,17 @@ def __init__(
164164
self,
165165
height: t.Optional[t.Any] = None,
166166
width: t.Optional[t.Any] = None,
167+
xmlns: str = "http://www.w3.org/2000/svg",
168+
viewBox: t.Optional[str] = None,
169+
role: str = "img",
167170
**attrs,
168171
) -> None:
169172
super().__init__(
170173
height=height,
171174
width=width,
175+
xmlns=xmlns,
176+
role=role,
177+
viewBox=viewBox,
172178
**attrs,
173179
)
174180

@@ -200,3 +206,172 @@ def __init__(
200206

201207
def render_tag(self, attrs: str, inner_html: str) -> str:
202208
return f"<{self.tag} {attrs}/>"
209+
210+
211+
class Circle(BaseElement):
212+
tag = "circle"
213+
214+
def __init__(
215+
self,
216+
*content: t.Any,
217+
cx: t.Optional[int] = None,
218+
cy: t.Optional[int] = None,
219+
r: t.Optional[int] = None,
220+
stroke: t.Optional[str] = None,
221+
stroke_width: t.Optional[str] = None,
222+
fill: t.Optional[str] = None,
223+
**attrs,
224+
):
225+
super().__init__(
226+
*content,
227+
cx=cx,
228+
cy=cy,
229+
r=r,
230+
stroke=stroke,
231+
stroke_width=stroke_width,
232+
fill=fill,
233+
**attrs,
234+
)
235+
236+
237+
class Rect(BaseElement):
238+
tag = "rect"
239+
240+
def __init__(
241+
self,
242+
*content: t.Any,
243+
x: t.Optional[int] = None,
244+
y: t.Optional[int] = None,
245+
width: t.Optional[int] = None,
246+
height: t.Optional[int] = None,
247+
stroke: t.Optional[str] = None,
248+
stroke_width: t.Optional[str] = None,
249+
fill: t.Optional[str] = None,
250+
**attrs,
251+
):
252+
super().__init__(
253+
*content,
254+
x=x,
255+
y=y,
256+
width=width,
257+
height=height,
258+
stroke=stroke,
259+
stroke_width=stroke_width,
260+
fill=fill,
261+
**attrs,
262+
)
263+
264+
265+
class Polygon(BaseElement):
266+
tag = "polygon"
267+
268+
def __init__(
269+
self,
270+
*content: t.Any,
271+
points: t.Optional[str] = None,
272+
stroke: t.Optional[str] = None,
273+
stroke_width: t.Optional[str] = None,
274+
fill: t.Optional[str] = None,
275+
**attrs,
276+
):
277+
super().__init__(
278+
*content,
279+
points=points,
280+
stroke=stroke,
281+
stroke_width=stroke_width,
282+
fill=fill,
283+
**attrs,
284+
)
285+
286+
287+
class Defs(BaseElement):
288+
tag = "defs"
289+
290+
291+
class LinearGradient(BaseElement):
292+
tag = "linearGradient"
293+
294+
295+
class Stop(BaseElement):
296+
tag = "stop"
297+
298+
def __init__(self, *content: t.Any, stop_color: t.Optional[str] = None, **attrs):
299+
super().__init__(*content, stop_color=stop_color, **attrs)
300+
301+
302+
class Ellipse(BaseElement):
303+
tag = "ellipse"
304+
305+
def __init__(
306+
self,
307+
*content: t.Any,
308+
cx: t.Optional[int] = None,
309+
cy: t.Optional[int] = None,
310+
r: t.Optional[int] = None,
311+
rx: t.Optional[int] = None,
312+
ry: t.Optional[int] = None,
313+
stroke: t.Optional[str] = None,
314+
stroke_width: t.Optional[str] = None,
315+
fill: t.Optional[str] = None,
316+
**attrs,
317+
):
318+
super().__init__(
319+
*content,
320+
cx=cx,
321+
cy=cy,
322+
r=r,
323+
rx=rx,
324+
ry=ry,
325+
stroke=stroke,
326+
stroke_width=stroke_width,
327+
fill=fill,
328+
**attrs,
329+
)
330+
331+
332+
class Text(BaseElement):
333+
tag = "text"
334+
335+
def __init__(
336+
self,
337+
*content: t.Any,
338+
font_size: t.Optional[int] = None,
339+
font_family: t.Optional[str] = None,
340+
x: t.Optional[str] = None,
341+
y: t.Optional[str] = None,
342+
fill: t.Optional[str] = None,
343+
**attrs,
344+
):
345+
super().__init__(
346+
*content,
347+
font_size=font_size,
348+
font_family=font_family,
349+
x=x,
350+
y=y,
351+
fill=fill,
352+
**attrs,
353+
)
354+
355+
356+
class Path(BaseElement):
357+
tag = "path"
358+
359+
def __init__(
360+
self,
361+
*content: t.Any,
362+
d: t.Optional[str] = None,
363+
fill_rule: t.Optional[str] = None,
364+
clip_rule: t.Optional[str] = None,
365+
stroke: t.Optional[str] = None,
366+
fill: t.Optional[str] = None,
367+
**attrs,
368+
):
369+
super().__init__(
370+
*content,
371+
d=d,
372+
fill_rule=fill_rule,
373+
clip_rule=clip_rule,
374+
stroke=stroke,
375+
fill=fill,
376+
**attrs,
377+
)

0 commit comments

Comments
 (0)