Skip to content

Commit

Permalink
simplified html tag class generation
Browse files Browse the repository at this point in the history
  • Loading branch information
István Bozsó committed Feb 21, 2020
1 parent 9eafbf1 commit 39f768c
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 23 deletions.
2 changes: 1 addition & 1 deletion utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .utils import *
from .base import *
from .path import *
from .enforce import *
from .cli import *
Expand Down
7 changes: 6 additions & 1 deletion utils/utils.py → utils/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ def compose(*functions):
return ft.reduce(compose2, functions)

def namespace(**kwargs):
return type("namespace", (object,), kwargs)
name, inh = (
kwargs.pop("_name_", "namespace"),
kwargs.pop("_inherit_", (object,))
)

return type(name, inh, kwargs)


class Enum(object):
Expand Down
2 changes: 1 addition & 1 deletion utils/html/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import base64
import os.path as path

from utils.utils import export
from utils.base import export
from utils.simpledoc import SimpleDoc, _attributes

class Encoder(object):
Expand Down
2 changes: 1 addition & 1 deletion utils/html/jslibs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from utils import namespace, export
from .html import Library
from utils.utils import namespace, export

__all__ = [
"libs", "plotly",
Expand Down
10 changes: 5 additions & 5 deletions utils/html/tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ def render(self):
"ul", "var", "video", "wbr",
}

tags |= {"h%d" % ii for ii in range(7)}
tags |= {"h%d" % ii for ii in range(1, 7)}


tags = type("Tags", (object,),
{
tags = namespace(_name_="Tags",
**{
key: type(key, (Tag,), {})
for key in tags
}
Expand All @@ -103,8 +103,8 @@ def render(self):

}

stags = type("SelfClosingTags", (object,),
{
stags = namespace(_name_="SelfClosingTags",
**{
key: type(key, (Tag,), {})
for key in stags
}
Expand Down
31 changes: 17 additions & 14 deletions utils/html/test.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
from utils.html.tag import *
from utils.html import *


def main():
d = \
t.div(
t.p("a", klass="klass"),
t.p("b"),
t.html(
t.h1("h"),
t.div(
t.p("c"),
),


t.ul(
t.li("1"),
t.li("2"),
),

controls=True, src="a/b"
t.p("a", klass="klass"),
t.p("b"),
t.div(
t.p("c"),
),

st.source(src="a.py"),
t.ul(
t.li("1"),
t.li("2"),
),

controls=True, src="a/b"
)
)

print(d.render())
Expand Down

0 comments on commit 39f768c

Please sign in to comment.