Skip to content

Commit 3f53f2b

Browse files
Make input tag specify formmethod when formaction is given
1 parent 477d5ae commit 3f53f2b

File tree

12 files changed

+1084
-988
lines changed

12 files changed

+1084
-988
lines changed

meta/scrape_tags.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ class TagsYmlItem(TypedDict):
121121
"""
122122
A tag which has suggested keys
123123
"""
124+
skip: NotRequired[bool]
125+
"""Whether to skip this tag when generating tags"""
126+
124127
attributes: NotRequired[dict[str, Union[str, AttrYmlItem]]]
125128
"""Mapping of attributes used by the tag (name: description)"""
126129

@@ -418,6 +421,16 @@ def get_tag_base_class(tags: TagsYaml, tag_name: str) -> str:
418421
return tag['base']
419422

420423

424+
def get_tag_skip(tags: TagsYaml, tag_name: str) -> bool:
425+
"""
426+
Return whether to skip this tag
427+
"""
428+
if tag_name not in tags:
429+
return False
430+
tag = tags[tag_name]
431+
return tag.get('skip', False)
432+
433+
421434
def make_mdn_link(tag: str) -> str:
422435
"""Generate an MDN docs link for the given tag"""
423436
return f"{MDN_ELEMENT_PAGE}/{tag}"
@@ -433,6 +446,10 @@ def elements_to_element_structs(
433446
output = []
434447

435448
for name, description in mdn_data:
449+
# Skip tag if specified
450+
if get_tag_skip(tag_attrs, name):
451+
continue
452+
436453
output.append(TagInfo(
437454
name=get_tag_rename(tag_attrs, name),
438455
description=description,

meta/tags.yml

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,22 +43,7 @@ form:
4343
action: The URL to request to when submitting this form. By default, requests will be sent to the same URL as the current page.
4444

4545
input:
46-
base: SelfClosingTag
47-
attributes:
48-
type: Kind of input control to use (checkbox, radio, date, password, text, etc)
49-
name: Name of the field. Submitted with the form as part of a name/value pair
50-
value: Initial value of the control
51-
placeholder: Placeholder text to use for text inputs. If the field is empty, the placeholder is shown.
52-
readonly:
53-
doc: Include if field is read-only
54-
type: bool
55-
default: "False"
56-
required:
57-
doc: Include if field is required
58-
type: bool
59-
default: "False"
60-
formmethod: The HTTP request method to use on click if this input is a submit button. Generally, it is preferred to set the `method` attribute on the `<form>` element instead of this.
61-
formaction: The URL to request to on click if this input is a submit button. Generally, it is preferred to set the `action` attribute on the `<form>` element instead of this.
46+
skip: true
6247

6348
button:
6449
base: StylableTag

meta/templates/class_attrs_SelfClosingTag.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,5 @@ def __call__(
4242
}
4343
return super().__call__(**attributes)
4444

45-
def _get_default_attributes(self) -> dict[str, Any]:
45+
def _get_default_attributes(self, given: dict[str, Any]) -> dict[str, Any]:
4646
return {default_attrs}

meta/templates/class_attrs_StylableTag.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,5 @@ def __call__(
5454
}
5555
return super().__call__(*children, **attributes)
5656

57-
def _get_default_attributes(self) -> dict[str, Any]:
57+
def _get_default_attributes(self, given: dict[str, Any]) -> dict[str, Any]:
5858
return {default_attrs}

meta/templates/class_attrs_Tag.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,5 @@ def __call__(
4242
}
4343
return super().__call__(*children, **attributes)
4444

45-
def _get_default_attributes(self) -> dict[str, Any]:
45+
def _get_default_attributes(self, given: dict[str, Any]) -> dict[str, Any]:
4646
return {default_attrs}

pyhtml/__tag_base.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,10 @@ def _get_tag_name(self) -> str:
5656
"""
5757
return type(self).__name__.removesuffix('_')
5858

59-
def _get_default_attributes(self) -> dict[str, Any]:
59+
def _get_default_attributes(self, given: dict[str, Any]) -> dict[str, Any]:
6060
"""
61-
Returns the default attributes for the tag
61+
Returns the default attributes for the tag given the specified
62+
attributes.
6263
6364
This is overridden by child classes to return a dictionary of default
6465
attributes that are applied to the class.
@@ -71,7 +72,7 @@ def _render(self) -> list[str]:
7172
a single line of output
7273
"""
7374
attributes = util.filter_attributes(util.dict_union(
74-
self._get_default_attributes(),
75+
self._get_default_attributes(self.attributes),
7576
self.attributes,
7677
))
7778

@@ -170,7 +171,7 @@ def _render(self) -> list[str]:
170171
a single line of output
171172
"""
172173
attributes = util.filter_attributes(util.dict_union(
173-
self._get_default_attributes(),
174+
self._get_default_attributes(self.attributes),
174175
self.attributes,
175176
))
176177
if len(attributes):

pyhtml/__tags/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,16 @@
55
"""
66
# Re-export renamed versions of tags
77
from .renames import input_, object_
8+
from .input import input
89

910
# Copy this into pyhtml/__tags/__init__.py
1011
__all__ = [
12+
# This one is generated by hand
13+
'input',
14+
# These two are renamed
1115
'input_',
1216
'object_',
17+
# These are generated
1318
'html',
1419
'base',
1520
'head',
@@ -225,7 +230,6 @@
225230
datalist,
226231
fieldset,
227232
form,
228-
input,
229233
label,
230234
legend,
231235
meter,

0 commit comments

Comments
 (0)