diff --git a/utils/html/tag.py b/utils/html/tag.py
index 4a849c1..25ef93d 100644
--- a/utils/html/tag.py
+++ b/utils/html/tag.py
@@ -1,16 +1,5 @@
from utils import export, str_t
-def parse_options(kwargs):
- if "klass" in kwargs:
- kwargs["class"] = kwargs.pop("klass")
-
- return " ".join(
- "%s=%s" % (key, val)
- if val is not True
- else "%s" % key
- for key, val in kwargs.items()
- )
-
class BaseTag(object):
__slots__ = (
"options",
@@ -19,6 +8,19 @@ class BaseTag(object):
def __init__(self, *args, **kwargs):
self.options = kwargs
+ def parse_options(self):
+ opts = self.options
+
+ if "klass" in opts:
+ opts["class"] = opts.pop("klass")
+
+ return " ".join(
+ "%s=%s" % (key, val)
+ if val is not True
+ else "%s" % key
+ for key, val in opts.items()
+ )
+
class Tag(BaseTag):
__slots__ = (
@@ -34,7 +36,7 @@ def render(self):
name = self.__class__.__name__
return "<%s %s>%s%s>" % (
- name, parse_options(self.options),
+ name, self.parse_options(),
self.render_children(), name
)
@@ -51,7 +53,7 @@ class SelfClosingTag(BaseTag):
def render(self):
return "<%s %s>" % (
self.__class__.__name__,
- self.options
+ self.parse_options()
)
diff --git a/utils/html/test.py b/utils/html/test.py
index f8b7b84..e6020b5 100644
--- a/utils/html/test.py
+++ b/utils/html/test.py
@@ -2,7 +2,7 @@
def main():
- t = div(p("a"), p("b"), controls=True, src="a/b")
+ t = div(p("a", klass="klass"), p("b"), controls=True, src="a/b")
print(t.render())