2
0
Fork 0
textout/textoutpc/Tags/__base__.py

74 lines
1.6 KiB
Python
Raw Normal View History

2018-01-02 18:57:04 +01:00
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from html import escape as _htmlescape
__all__ = ["_htmlescape", "TextoutTag", "TextoutBlockTag", "TextoutInlineTag"]
# ---
# Main base tag class.
# ---
2018-01-02 18:57:04 +01:00
class TextoutTag:
""" The textout tag base class.
Is initialized with these values:
[<name>=<value>]<content>[/<name>] """
def __init__(self, name, value):
""" Initialize the textout tag with the documented members. """
self.name = name
self.value = value
self.content = None
self.eval = False
self._prepare()
def _prepare(self):
""" If the tag needs to prepare things when the name and value are set,
supplant this. By default, this method checks that there is
no value set. """
if self.value != None:
2018-01-02 18:57:04 +01:00
raise Exception
def _set(self):
""" If the tag needs to prepare things after the content is set,
supplant this. By default, this method does nothing.
"""
pass
def begin_text(self):
""" The text output beginning method. """
return "[{}{}]".format(self.name,
'=' + self.value if self.value != None else "")
def end_text(self):
""" The text output beginning method. """
return self.content + "[/{}]".format(self.name)
def begin_html(self):
""" The HTML beginning method. """
return _htmlescape("[{}{}]".format,
'=' + self.value if self.value != None else "")
def end_html(self):
""" The HTML ending method. """
return _htmlescape(self.content + "[/{}]".format(self.name))
# ---
# Role-specific base tag classes.
# ---
class TextoutBlockTag(TextoutTag):
pass
class TextoutInlineTag(TextoutTag):
pass
2018-01-02 18:57:04 +01:00
# End of file.