Skip to content

Commit

Permalink
Update htag.txt
Browse files Browse the repository at this point in the history
fix tag open/closed and boolean attributs
  • Loading branch information
manatlan authored Apr 11, 2024
1 parent f26d443 commit 90e0069
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions brython/htag.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
#-------------------------------------------------------------------------------------------------------------------------------
# An "htag.Tag" implem for brython (see https://github.com/manatlan/htag/tree/main/brython)
#-------------------------------------------------------------------------------------------------------------------------------
# In html/head add:
# <script type="text/python" src="https://raw.githubusercontent.com/manatlan/htag/main/brython/htag.txt" id="htag"></script>
# In script/python add:
# from htag import Tag
#-------------------------------------------------------------------------------------------------------------------------------
from browser import html,document,window


def importStatics():
import __main__
if not document.hasOwnProperty("htagStaticsImported"):
Expand Down Expand Up @@ -57,11 +51,19 @@ class TAG:
# it's "open tag" (accept redef) (it should got a 'init( ..., **a)' )
# (because it tries call with "_var")
for k,v in attrs.items():
self.attrs[k]=v
if isinstance(v,bool):
if v: self.attrs[k]=""
else:
self.attrs[k]=v
for k,v in events.items():
self.bind(k,v)

constructor(*args,**props,**kargs) # to produce a typeerror if not "opened"
kargs={k:v for k,v in kargs.items() if k not in props}
try:
constructor(*args,**props,**kargs) # to produce a typeerror if not "opened"
except Exception as e:
print(f"***ERROR*** {self.__class__.__name__} constructor:",e)
raise e
else:
# it's "closed tag" (refuse redef)
constructor(*args,**kargs)
Expand Down Expand Up @@ -91,7 +93,10 @@ class TAG:
self <= content

for k,v in attrs.items():
self.attrs[k]=v
if isinstance(v,bool):
if v: self.attrs[k]=""
else:
self.attrs[k]=v
for k,v in events.items():
self.bind(k,v)
for k,v in props.items():
Expand Down

0 comments on commit 90e0069

Please sign in to comment.