Markdown content for pages works
This commit is contained in:
parent
ec5df7816c
commit
76c928e93b
|
@ -1 +1,5 @@
|
|||
test_input/rendered_root
|
||||
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>
|
||||
</head>
|
||||
<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>
|
||||
</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):
|
||||
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()
|
||||
|
|
|
@ -1,17 +1,36 @@
|
|||
#!/usr/bin/env python2
|
||||
import os
|
||||
from datetime import datetime
|
||||
|
||||
import markdown
|
||||
|
||||
from verdandi.mixins.templatemixin import TemplateMixin
|
||||
from verdandi.mixins.menuitemmixin import MenuItemMixin
|
||||
|
||||
from verdandi.constants import CONTENT_DIRECTORY
|
||||
|
||||
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):
|
||||
context = super(Page,self).get_context()
|
||||
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
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -3,15 +3,17 @@
|
|||
import os
|
||||
from jinja2 import Environment, FileSystemLoader
|
||||
|
||||
from constants import OUTPUT_DIRECTORY, TEMPLATE_DIRECTORY
|
||||
|
||||
class Verdandi(object):
|
||||
|
||||
template_dir = "templates"
|
||||
output_directory = "rendered_root"
|
||||
template_directory = TEMPLATE_DIRECTORY
|
||||
output_directory = OUTPUT_DIRECTORY
|
||||
modules = []
|
||||
|
||||
|
||||
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):
|
||||
|
@ -28,7 +30,6 @@ class Verdandi(object):
|
|||
|
||||
while len(messages) > 0:
|
||||
message = messages.pop()
|
||||
print message
|
||||
messages = messages + self.send_message(message)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue