qmsk/web/html.py
changeset 102 611787305686
parent 92 e5799432071c
equal deleted inserted replaced
101:18c461237630 102:611787305686
     1 from qmsk.utils import flatten, merge
     1 from qmsk.utils import flatten, merge
     2 from html import escape
     2 from html import escape
     3 
     3 
     4 import qmsk.web
     4 import qmsk.web.application
     5 
     5 
     6 class Tag :
     6 class Tag :
     7     def __init__ (self, _name=None, *_contents,
     7     def __init__ (self, _name=None, *_contents,
     8             _selfclosing=True,
     8             _selfclosing=True,
     9             _whitespace_sensitive=False,
     9             _whitespace_sensitive=False,
   103     span    = Tag('span', _selfclosing=False)
   103     span    = Tag('span', _selfclosing=False)
   104     script  = Tag('script', _selfclosing=False)
   104     script  = Tag('script', _selfclosing=False)
   105 
   105 
   106 html5   = HTML5()
   106 html5   = HTML5()
   107 
   107 
   108 class HTMLHandler (qmsk.web.Handler):
   108 class HTMLMixin:
   109     """
   109     """
   110         A handler that renders a full HTML page.
   110         A handler that renders a full HTML page.
   111     """
   111     """
   112 
   112 
   113     # HTML5
   113     # HTML5
   140             Render HTML <html> tag.
   140             Render HTML <html> tag.
   141         """
   141         """
   142 
   142 
   143         html = self.html
   143         html = self.html
   144 
   144 
       
   145         title = self.title()
       
   146 
       
   147         assert title
       
   148 
   145         return html.html(
   149         return html.html(
   146             html.head(
   150             html.head(
   147                 html.title(self.title()),
   151                 html.title(title),
   148                 (
   152                 (
   149                     html.link(rel='Stylesheet', type="text/css", href=src) for src in self.CSS
   153                     html.link(rel='Stylesheet', type="text/css", href=src) for src in self.CSS
   150                 ), 
   154                 ), 
   151                 (
   155                 (
   152                     html.script(src=src, type='text/javascript', _selfclosing=False) for src in self.JS
   156                     html.script(src=src, type='text/javascript', _selfclosing=False) for src in self.JS
   184             html.pre(repr(
   188             html.pre(repr(
   185                 html.a(href="/foo")("Foo!")
   189                 html.a(href="/foo")("Foo!")
   186             ))
   190             ))
   187         ),
   191         ),
   188     ))
   192     ))
       
   193 
       
   194 class HTMLHandler (HTMLMixin, qmsk.web.application.Handler):
       
   195     pass
       
   196