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()