Just playing around a bit.

This commit is contained in:
Sebastian 2015-02-26 20:26:39 +01:00
commit b2b6a070d1
25 changed files with 172 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
virtenv

2
requirements.txt Normal file
View File

@ -0,0 +1,2 @@
Jinja2==2.7.3
MarkupSafe==0.23

View File

@ -0,0 +1,7 @@
<html>
<head>
<title>A cool new Page</title>
</head>
<body>
</body>
</html>

View File

@ -0,0 +1,7 @@
<html>
<head>
<title>An other cool Page</title>
</head>
<body>
</body>
</html>

View File

@ -0,0 +1,7 @@
<html>
<head>
<title>Yet an other cool Page</title>
</head>
<body>
</body>
</html>

View File

@ -0,0 +1,7 @@
<html>
<head>
<title>{{page_title}}</title>
</head>
<body>
</body>
</html>

28
test_input/testblog.py Normal file
View File

@ -0,0 +1,28 @@
#!/usr/bin/env python2
import sys
sys.path.append('../')
from verdandi.verdandi import Verdandi
from verdandi.modules.page import Page
class TestPage1(Page):
title = "A cool new Page"
class TestPage2(Page):
title = "An other cool Page"
url = "page2.html"
class TestPage3(Page):
title = "Yet an other cool Page"
url = "subdir/page3.html"
class TestBlog(Verdandi):
modules = [TestPage1(),
TestPage2(),
TestPage3()]
testblog = TestBlog()
testblog.run()

0
verdandi/__init__.py Normal file
View File

BIN
verdandi/__init__.pyc Normal file

Binary file not shown.

View File

Binary file not shown.

View File

@ -0,0 +1,18 @@
#!/usr/bin/env python2
class MenuItemMixin(object):
menu_title = "Menu title"
menu_label = None
menu_parent = None
url = "index.html"
def process_message(self, message):
if message == None:
return [{'type': 'menu_add_item',
'title' : self.menu_title,
'parent' : self.menu_parent,
'label' : self.menu_label,
'url' : self.url}]
return []

Binary file not shown.

View File

@ -0,0 +1,6 @@
#!/usr/bin/env python2
class MessageMixin(object):
def process_message(self, message):
return []

Binary file not shown.

View File

@ -0,0 +1,6 @@
#!/usr/bin/env python2
class RenderMixin(object):
def render(self, output_directory, jinja_env):
return None

View File

@ -0,0 +1,22 @@
#!/usr/bin/env python2
import os
class TemplateMixin(object):
template = "base.html"
url = "index.html"
context = {}
def get_context(self):
return self.context
def render(self, output_directory, jinja_env):
template = jinja_env.get_template(self.template)
html = template.render(self.get_context())
out_path = os.path.join(output_directory, self.url)
out_dir = os.path.dirname(out_path)
if not os.path.isdir(out_dir):
os.mkdir(out_dir)
out_file = open(out_path, "wb")
out_file.write(html)
out_file.close()

Binary file not shown.

BIN
verdandi/module.pyc Normal file

Binary file not shown.

View File

Binary file not shown.

17
verdandi/modules/page.py Normal file
View File

@ -0,0 +1,17 @@
#!/usr/bin/env python2
from verdandi.mixins.templatemixin import TemplateMixin
from verdandi.mixins.menuitemmixin import MenuItemMixin
class Page(TemplateMixin, MenuItemMixin):
title = 'Page Title'
def get_context(self):
context = super(Page,self).get_context()
context['page_title'] = self.title
return context

BIN
verdandi/modules/page.pyc Normal file

Binary file not shown.

44
verdandi/verdandi.py Normal file
View File

@ -0,0 +1,44 @@
#!/usr/bin/env python2
import os
from jinja2 import Environment, FileSystemLoader
class Verdandi(object):
template_dir = "templates"
output_directory = "rendered_root"
modules = []
def __init__(self):
self.jinja_env = Environment(loader=FileSystemLoader(self.template_dir))
def send_message(self, message):
results = []
for module in self.modules:
results += module.process_message(message)
return results
def pass_messages(self):
messages = self.send_message(None)
while len(messages) > 0:
message = messages.pop()
print message
messages = messages + self.send_message(message)
def render(self):
if not os.path.exists(self.output_directory):
os.mkdir(self.output_directory)
for module in self.modules:
module.render(self.output_directory, self.jinja_env)
def run(self):
self.pass_messages()
self.render()

BIN
verdandi/verdandi.pyc Normal file

Binary file not shown.