Markdown content for pages works
This commit is contained in:
parent
ec5df7816c
commit
76c928e93b
|
@ -1 +1,5 @@
|
||||||
|
test_input/rendered_root
|
||||||
virtenv
|
virtenv
|
||||||
|
|
||||||
|
*.pyc
|
||||||
|
*.swp
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
Test
|
||||||
|
----
|
||||||
|
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum.
|
||||||
|
|
||||||
|
Foo | Rofl | Lol
|
||||||
|
----|------|-----
|
||||||
|
A | B | C
|
||||||
|
D | E | F
|
||||||
|
|
||||||
|
|
||||||
|
Stet clita
|
||||||
|
==========
|
||||||
|
kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus
|
||||||
|
|
||||||
|
* est
|
||||||
|
* Lorem
|
||||||
|
* ipsum
|
||||||
|
* <strike>dolor</strike>
|
||||||
|
* *sit*
|
||||||
|
* **amet**.
|
||||||
|
|
||||||
|
1. Lol
|
||||||
|
2. No
|
||||||
|
3. Nope
|
|
@ -3,5 +3,9 @@
|
||||||
<title>{{page_title}}</title>
|
<title>{{page_title}}</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
{{content}}
|
||||||
|
<br/>
|
||||||
|
Created: {{content_creation_time.strftime('%d.%m.%Y %H:%M:%S')}}</br>
|
||||||
|
Edit: {{content_edit_time.strftime('%d.%m.%Y %H:%M:%S')}}</br>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
#!/usr/bin/env python2
|
||||||
|
|
||||||
|
OUTPUT_DIRECTORY = "rendered_root"
|
||||||
|
TEMPLATE_DIRECTORY = "templates"
|
||||||
|
CONTENT_DIRECTORY = "content"
|
|
@ -13,10 +13,12 @@ class TemplateMixin(object):
|
||||||
def render(self, output_directory, jinja_env):
|
def render(self, output_directory, jinja_env):
|
||||||
template = jinja_env.get_template(self.template)
|
template = jinja_env.get_template(self.template)
|
||||||
html = template.render(self.get_context())
|
html = template.render(self.get_context())
|
||||||
|
|
||||||
out_path = os.path.join(output_directory, self.url)
|
out_path = os.path.join(output_directory, self.url)
|
||||||
out_dir = os.path.dirname(out_path)
|
out_dir = os.path.dirname(out_path)
|
||||||
if not os.path.isdir(out_dir):
|
if not os.path.isdir(out_dir):
|
||||||
os.mkdir(out_dir)
|
os.mkdir(out_dir)
|
||||||
|
|
||||||
out_file = open(out_path, "wb")
|
out_file = open(out_path, "wb")
|
||||||
out_file.write(html)
|
out_file.write(html)
|
||||||
out_file.close()
|
out_file.close()
|
||||||
|
|
|
@ -1,17 +1,36 @@
|
||||||
#!/usr/bin/env python2
|
#!/usr/bin/env python2
|
||||||
|
import os
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
import markdown
|
||||||
|
|
||||||
from verdandi.mixins.templatemixin import TemplateMixin
|
from verdandi.mixins.templatemixin import TemplateMixin
|
||||||
from verdandi.mixins.menuitemmixin import MenuItemMixin
|
from verdandi.mixins.menuitemmixin import MenuItemMixin
|
||||||
|
from verdandi.constants import CONTENT_DIRECTORY
|
||||||
|
|
||||||
class Page(TemplateMixin, MenuItemMixin):
|
class Page(TemplateMixin, MenuItemMixin):
|
||||||
title = 'Page Title'
|
|
||||||
|
title = "Page Title"
|
||||||
|
content_file = "content.md"
|
||||||
|
content_directory = CONTENT_DIRECTORY
|
||||||
|
|
||||||
|
markdown_extensions = ['markdown.extensions.sane_lists',
|
||||||
|
'markdown.extensions.tables']
|
||||||
|
|
||||||
def get_context(self):
|
def get_context(self):
|
||||||
context = super(Page,self).get_context()
|
context = super(Page,self).get_context()
|
||||||
context['page_title'] = self.title
|
context['page_title'] = self.title
|
||||||
|
|
||||||
|
full_path = os.path.join(self.content_directory, self.content_file)
|
||||||
|
markdown_converter = markdown.Markdown(extensions = self.markdown_extensions)
|
||||||
|
|
||||||
|
ctime = os.path.getctime(full_path)
|
||||||
|
context['content_creation_time'] = datetime.fromtimestamp(ctime)
|
||||||
|
|
||||||
|
mtime = os.path.getmtime(full_path)
|
||||||
|
context['content_edit_time'] = datetime.fromtimestamp(mtime)
|
||||||
|
|
||||||
|
markdown_source = open(full_path, 'r').read()
|
||||||
|
context['content'] = markdown_converter.convert(markdown_source)
|
||||||
|
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,15 +3,17 @@
|
||||||
import os
|
import os
|
||||||
from jinja2 import Environment, FileSystemLoader
|
from jinja2 import Environment, FileSystemLoader
|
||||||
|
|
||||||
|
from constants import OUTPUT_DIRECTORY, TEMPLATE_DIRECTORY
|
||||||
|
|
||||||
class Verdandi(object):
|
class Verdandi(object):
|
||||||
|
|
||||||
template_dir = "templates"
|
template_directory = TEMPLATE_DIRECTORY
|
||||||
output_directory = "rendered_root"
|
output_directory = OUTPUT_DIRECTORY
|
||||||
modules = []
|
modules = []
|
||||||
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.jinja_env = Environment(loader=FileSystemLoader(self.template_dir))
|
self.jinja_env = Environment(loader=FileSystemLoader(self.template_directory))
|
||||||
|
|
||||||
|
|
||||||
def send_message(self, message):
|
def send_message(self, message):
|
||||||
|
@ -19,22 +21,21 @@ class Verdandi(object):
|
||||||
|
|
||||||
for module in self.modules:
|
for module in self.modules:
|
||||||
results += module.process_message(message)
|
results += module.process_message(message)
|
||||||
|
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
|
||||||
def pass_messages(self):
|
def pass_messages(self):
|
||||||
messages = self.send_message(None)
|
messages = self.send_message(None)
|
||||||
|
|
||||||
while len(messages) > 0:
|
while len(messages) > 0:
|
||||||
message = messages.pop()
|
message = messages.pop()
|
||||||
print message
|
|
||||||
messages = messages + self.send_message(message)
|
messages = messages + self.send_message(message)
|
||||||
|
|
||||||
|
|
||||||
def render(self):
|
def render(self):
|
||||||
if not os.path.exists(self.output_directory):
|
if not os.path.exists(self.output_directory):
|
||||||
os.mkdir(self.output_directory)
|
os.mkdir(self.output_directory)
|
||||||
for module in self.modules:
|
for module in self.modules:
|
||||||
module.render(self.output_directory, self.jinja_env)
|
module.render(self.output_directory, self.jinja_env)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue