Skip to content

Instantly share code, notes, and snippets.

@ErisianArchitect
Created August 12, 2015 12:21
Show Gist options
  • Save ErisianArchitect/024b1c4d3be9da3bc9d0 to your computer and use it in GitHub Desktop.
Save ErisianArchitect/024b1c4d3be9da3bc9d0 to your computer and use it in GitHub Desktop.
#html.py
#Joins strings a and b if b is not None
def join(a,b=None):
if b != None:
return str.format("{}{}",a,b)
return ''.join(a)
def attribjoin(attribs):
if type(attribs) == dict:
return ''.join([str.format(" {0}=\"{1}\"",c,v) for c, v in attribs.items()])
return ''
def comment(text='Comment'):
return str.format("<!--{}-->",text)
#tag is a string, body is a string, attribs is a dictionary
def maketag(tag,body,attribs):
if not body == None:
return str.format("<{0}{1}>{2}</{0}>",tag,attribjoin(attribs),body)
else:
return str.format("<{0}{1}/>",tag,attribjoin(attribs))
class tag_class_meta:
_cache = {}
def __getattr__(self,name):
if not name in self._cache:
self._cache[name] = lambda body = None, **attribs: maketag(name,body,attribs)
return self._cache[name]
tag = tag_class_meta()
if __name__ == "__main__":
print("Script complete")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment