From e16e971a877939333bee8a8d316fc70caf9e3fab Mon Sep 17 00:00:00 2001 From: Thomas FORGIONE Date: Mon, 13 Apr 2015 12:06:27 +0200 Subject: [PATCH] Improved thing (may be usefull... later) --- index.py | 18 +----------------- webtools/Web.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/index.py b/index.py index 117f8db..7257e93 100755 --- a/index.py +++ b/index.py @@ -4,20 +4,4 @@ import sys from webtools import Web -def main(): - print('Content-type: text/html') - print() - - page = Web.Element(Web.ROOT_DIR + 'templates/page.html') - head = Web.Element(Web.ROOT_DIR + 'templates/head.html') - body = Web.Element(Web.ROOT_DIR + 'templates/body.html') - content = Web.Element('index.html') - - page.add_child(head) - page.add_child(body) - body.add_child(content) - - page.print() - -if __name__ == '__main__': - main() +Web.render('index.html') diff --git a/webtools/Web.py b/webtools/Web.py index 68af04d..c60a750 100755 --- a/webtools/Web.py +++ b/webtools/Web.py @@ -44,3 +44,18 @@ class Element: for i in self.children: i.print(format) self.close(format) + +def render(filename): + print('Content-type: text/html') + print() + + page = Element(ROOT_DIR + 'templates/page.html') + head = Element(ROOT_DIR + 'templates/head.html') + body = Element(ROOT_DIR + 'templates/body.html') + content = Element(filename) + + page.add_child(head) + page.add_child(body) + body.add_child(content) + + page.print()