Skip to content

Commit

Permalink
Merge pull request #13 from MohammadrezaAmani/inui-0.9.1-bootstrap
Browse files Browse the repository at this point in the history
feat(bootstrap): add bootstrap5 support to project.
  • Loading branch information
MohammadrezaAmani authored Oct 27, 2024
2 parents acd2a16 + c4f5ded commit 7504818
Show file tree
Hide file tree
Showing 9 changed files with 5,409 additions and 4 deletions.
23 changes: 21 additions & 2 deletions inui/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from typing import Any, Dict, List, NamedTuple, Tuple, Type, Union

from inui.config.replaces import replace


class Attributes:
def __init__(self, **kwargs: Any) -> None:
Expand All @@ -14,7 +16,7 @@ def __getattribute__(self, __name: str) -> Any:

def __str__(self) -> str:
return " ".join(
f'{name}="{value}"'
f'{replace(name)}="{value}"'
for name, value in self.attrs.items()
if value is not None
)
Expand Down Expand Up @@ -154,13 +156,30 @@ def __len__(self):
def __getitem__(self, item):
return self.render()[item]

def _str(self, data):
try:
if isinstance(data, type):
if isinstance(data(), Base):
data = data()
except Exception as _:
pass
return str(data)


class BaseElement(Base): ...


class BaseVoidElement(BaseElement):
def render(self, prettify: bool = False):
return f"""<{self.start_tag}{' ' if len(self.attributes) > 0 else ''}{str(self.attributes)}>"""
return f"""<{self.start_tag}{' ' if len(self.attributes) > 0 else ''}{str(self.attributes)}> """


class BaseSvgElement(Base): ...


class Class(Base):
def __init__(self, *args) -> None:
self.args = args

def render(self, prettify: bool = False) -> str:
return " ".join(list(map(self._str, self.args)))
Loading

0 comments on commit 7504818

Please sign in to comment.