Skip to content

Commit 04732d3

Browse files
committed
Add <video> element
1 parent 5fd2f02 commit 04732d3

File tree

7 files changed

+82
-0
lines changed

7 files changed

+82
-0
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## API Additions
44

5+
* Add `Video` element.
56
* Add `Button.disabled`.
67
* Add `autocomplete` attribute to `Input`, `TextArea`, `Select`, and `Form`.
78
* Add `enum_attribute`.

elements.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,4 @@ htmlgen currently supports the following HTML elements:
6161
* <title> - Title
6262
* <tr> - TableRow
6363
* <ul> - UnorderedList
64+
* <video> - Video

htmlgen/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,4 @@
9696
Column,
9797
)
9898
from .time import Time
99+
from .video import Preload, Video

htmlgen/__init__.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ from .list import *
1111
from .structure import *
1212
from .table import *
1313
from .time import *
14+
from .video import *

htmlgen/video.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from enum import Enum
2+
3+
from .attribute import boolean_html_attribute, html_attribute, enum_attribute
4+
from .element import Element
5+
6+
7+
class Preload(Enum):
8+
NONE = "none"
9+
METADATA = "metadata"
10+
AUTO = "auto"
11+
12+
13+
class Video(Element):
14+
controls = boolean_html_attribute("controls")
15+
poster = html_attribute("poster")
16+
preload = enum_attribute("preload", Preload)
17+
18+
def __init__(self, src: str) -> None:
19+
super().__init__("video")
20+
self.set_attribute("src", src)

htmlgen/video.pyi

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from enum import Enum
2+
from typing import Optional
3+
4+
from htmlgen import Element
5+
6+
class Preload(Enum):
7+
NONE: str
8+
METADATA: str
9+
AUTO: str
10+
11+
12+
class Video(Element):
13+
controls: bool
14+
poster: Optional[str]
15+
preload: Optional[Preload]
16+
def __init__(self, src: str) -> None: ...

test_htmlgen/video.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
from unittest import TestCase
2+
3+
from asserts import assert_equal, assert_true, assert_is_none, assert_false
4+
5+
from htmlgen import Video, Preload
6+
7+
8+
class VideoTest(TestCase):
9+
def test_src_only(self):
10+
video = Video("foo.mp4")
11+
assert_equal(
12+
[b'<video src="foo.mp4">', b"</video>"], list(iter(video)),
13+
)
14+
15+
def test_controls(self):
16+
video = Video("foo.mp4")
17+
assert_false(video.controls)
18+
video.controls = True
19+
assert_true(video.controls)
20+
assert_equal(
21+
[b'<video controls="controls" src="foo.mp4">', b"</video>"],
22+
list(iter(video)),
23+
)
24+
25+
def test_poster(self):
26+
video = Video("foo.mp4")
27+
assert_is_none(video.poster)
28+
video.poster = "poster.png"
29+
assert_equal("poster.png", video.poster)
30+
assert_equal(
31+
[b'<video poster="poster.png" src="foo.mp4">', b"</video>"],
32+
list(iter(video)),
33+
)
34+
35+
def test_preload(self):
36+
video = Video("foo.mp4")
37+
assert_is_none(video.preload)
38+
video.preload = Preload.NONE
39+
assert_equal(
40+
[b'<video preload="none" src="foo.mp4">', b"</video>"],
41+
list(iter(video)),
42+
)

0 commit comments

Comments
 (0)