Skip to content

Commit e976533

Browse files
Move comment ag
1 parent 5fa158c commit e976533

File tree

5 files changed

+66
-56
lines changed

5 files changed

+66
-56
lines changed

pyhtml/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,13 +249,13 @@
249249
"""
250250
# Disable Flake8, since it really doesn't like our docstring above
251251
# flake8: noqa
252-
from .__tag_base import Tag, Comment
252+
from .__tag_base import Tag
253253

254254
from .__tags import input_, object_
255255

256256
__all__ = [
257-
'DangerousRawHtml',
258257
'Tag',
258+
'DangerousRawHtml',
259259
'Comment',
260260
'input_',
261261
'object_',
@@ -377,6 +377,7 @@
377377

378378
from .__tags import (
379379
DangerousRawHtml,
380+
Comment,
380381
html,
381382
base,
382383
head,

pyhtml/__tag_base.py

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -116,57 +116,6 @@ def __repr__(self) -> str:
116116
return self.render()
117117

118118

119-
class Comment(Tag):
120-
"""
121-
An HTML comment.
122-
123-
Renders as:
124-
125-
```html
126-
<!-- [comment text] -->
127-
```
128-
129-
Note that this does not render as a `<comment>` tag
130-
"""
131-
def __init__(self, text: str) -> None:
132-
"""
133-
An HTML comment.
134-
135-
Renders as:
136-
137-
```html
138-
<!-- [comment text] -->
139-
```
140-
141-
Note that this does not render as a `<comment>` tag
142-
"""
143-
self.comment_data = text
144-
super().__init__()
145-
146-
def __call__(self):
147-
raise TypeError('Comment tags are not callable')
148-
149-
def _get_tag_name(self) -> str:
150-
# Ignore coverage since this is only implemented to satisfy inheritance
151-
# and is never used since we override _render
152-
return '!--' # pragma: no cover
153-
154-
def _render(self) -> list[str]:
155-
"""
156-
Override of render, to render comments
157-
"""
158-
159-
return [
160-
'<!--',
161-
*util.increase_indent(
162-
util.escape_string(self.comment_data).splitlines(),
163-
# FIXME: Yucky magic number
164-
2,
165-
),
166-
'-->'
167-
]
168-
169-
170119
class SelfClosingTag(Tag):
171120
"""
172121
Self-closing tags don't contain child elements

pyhtml/__tags/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@
77
from .renames import input_, object_
88
from .input import input
99
from .dangerous_raw_html import DangerousRawHtml
10+
from .comment import Comment
1011

1112
# Copy this into pyhtml/__tags/__init__.py
1213
__all__ = [
1314
# This one is generated by hand
1415
'input',
1516
# These are extra features of PyHTML enhanced
1617
'DangerousRawHtml',
18+
'Comment',
1719
# These two are renamed
1820
'input_',
1921
'object_',

pyhtml/__tags/comment.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
"""
2+
# PyHTML Enhanced / Tags / Comment
3+
4+
Definition for the comment tag.
5+
"""
6+
from ..__tag_base import Tag
7+
from .. import __util as util
8+
9+
10+
class Comment(Tag):
11+
"""
12+
An HTML comment.
13+
14+
Renders as:
15+
16+
```html
17+
<!-- [comment text] -->
18+
```
19+
20+
Note that this does not render as a `<comment>` tag
21+
"""
22+
def __init__(self, text: str) -> None:
23+
"""
24+
An HTML comment.
25+
26+
Renders as:
27+
28+
```html
29+
<!-- [comment text] -->
30+
```
31+
32+
Note that this does not render as a `<comment>` tag
33+
"""
34+
self.comment_data = text
35+
super().__init__()
36+
37+
def __call__(self):
38+
raise TypeError('Comment tags are not callable')
39+
40+
def _get_tag_name(self) -> str:
41+
# Ignore coverage since this is only implemented to satisfy inheritance
42+
# and is never used since we override _render
43+
return '!--' # pragma: no cover
44+
45+
def _render(self) -> list[str]:
46+
"""
47+
Override of render, to render comments
48+
"""
49+
50+
return [
51+
'<!--',
52+
*util.increase_indent(
53+
util.escape_string(self.comment_data).splitlines(),
54+
# FIXME: Yucky magic number
55+
2,
56+
),
57+
'-->'
58+
]

tests/code_gen_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"""
88
import pytest
99
import pyhtml
10-
from pyhtml import Tag, Comment
10+
from pyhtml import Tag, Comment, DangerousRawHtml
1111

1212

1313
all_tags = [
@@ -20,8 +20,8 @@
2020
and type(getattr(pyhtml, i)) == type
2121
# That are a kind of Tag
2222
and issubclass(getattr(pyhtml, i), Tag)
23-
# And aren't a comment (since comments require named args)
24-
and not issubclass(getattr(pyhtml, i), Comment)
23+
# And aren't a PyHTML feature (since comments require named args)
24+
and not issubclass(getattr(pyhtml, i), (Comment, DangerousRawHtml))
2525
)
2626
]
2727

0 commit comments

Comments
 (0)