SalladShooter / phyal

Quickly build websites without the hassle of HTML
https://phyal.vercel.app/
MIT License
34 stars 3 forks source link

Keyword arguments as attributes for Tags #25

Closed Matt-DESTROYER closed 2 months ago

Matt-DESTROYER commented 2 months ago

Could keyword arguments be automatically used as attributes for Tags?

I'm thinking something like:

class Tag:
    def __init__(self: Self, **kwargs: str) -> None:
        self.attributes: dict[str, str] = {}
        for key, value in kwargs.items():
            self.attributes[key] = value
aatle commented 2 months ago

Improved:

class Tag:
    def __init__(self: Self, name: str, text: str = '', **attributes: str) -> None:
        self.name = name
        self.text = text
        self.attributes: dict[str, str] = attributes
        self.children: list[Tag] = []

I'd also recommend that the .attribute() and .id() methods be removed since they are not useful.

populated commented 2 months ago

Improved:

class Tag:
    def __init__(self: Self, name: str, text: str = '', **attributes: str) -> None:
        self.name = name
        self.text = text
        self.attributes: dict[str, str] = attributes
        self.children: list[Tag] = []

I'd also recommend that the .attribute() and .id() methods be removed since they are not useful.

Code would have to be remade to support the deprecation of these methods, since the class Tags has nested classes that inherit Tag, and then use .attribute().