Moved default markdown extensions to constatns
Added render_files method to allow reusing code without regenerating the context
This commit is contained in:
parent
501f27cc4f
commit
d233b7ae5a
|
@ -3,5 +3,8 @@
|
||||||
OUTPUT_DIRECTORY = "rendered_root"
|
OUTPUT_DIRECTORY = "rendered_root"
|
||||||
TEMPLATE_DIRECTORY = "templates"
|
TEMPLATE_DIRECTORY = "templates"
|
||||||
CONTENT_DIRECTORY = "content"
|
CONTENT_DIRECTORY = "content"
|
||||||
|
MARKDOWN_EXTENSIONS = ['markdown.extensions.sane_lists',
|
||||||
|
'markdown.extensions.tables']
|
||||||
|
|
||||||
|
|
||||||
SERVE_PORT = 8000
|
SERVE_PORT = 8000
|
||||||
|
|
|
@ -11,14 +11,22 @@ class TemplateMixin(object):
|
||||||
return self.context
|
return self.context
|
||||||
|
|
||||||
def render(self, output_directory, jinja_env):
|
def render(self, output_directory, jinja_env):
|
||||||
template = jinja_env.get_template(self.template)
|
context = self.get_context()
|
||||||
html = template.render(self.get_context())
|
self.render_files(context, output_directory, jinja_env)
|
||||||
|
|
||||||
out_path = os.path.join(output_directory, self.url)
|
def render_files(self, context, output_directory, jinja_env):
|
||||||
|
self.render_to_file(self.template, self.url, context, output_directory, jinja_env)
|
||||||
|
|
||||||
|
|
||||||
|
def render_to_file(self, template, url, context, output_directory, jinja_env):
|
||||||
|
template = jinja_env.get_template(template)
|
||||||
|
result = template.render(context)
|
||||||
|
|
||||||
|
out_path = os.path.join(output_directory, 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(result)
|
||||||
out_file.close()
|
out_file.close()
|
||||||
|
|
|
@ -7,7 +7,7 @@ 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.mixins.assetsmixin import AssetsMixin
|
from verdandi.mixins.assetsmixin import AssetsMixin
|
||||||
from verdandi.constants import CONTENT_DIRECTORY
|
from verdandi.constants import CONTENT_DIRECTORY, MARKDOWN_EXTENSIONS
|
||||||
|
|
||||||
class Page(MenuItemMixin, TemplateMixin, AssetsMixin):
|
class Page(MenuItemMixin, TemplateMixin, AssetsMixin):
|
||||||
|
|
||||||
|
@ -15,8 +15,8 @@ class Page(MenuItemMixin, TemplateMixin, AssetsMixin):
|
||||||
content_file = "content.md"
|
content_file = "content.md"
|
||||||
content_directory = CONTENT_DIRECTORY
|
content_directory = CONTENT_DIRECTORY
|
||||||
|
|
||||||
markdown_extensions = ['markdown.extensions.sane_lists',
|
markdown_extensions = MARKDOWN_EXTENSIONS
|
||||||
'markdown.extensions.tables']
|
|
||||||
|
|
||||||
def get_context(self):
|
def get_context(self):
|
||||||
context = super(Page,self).get_context()
|
context = super(Page,self).get_context()
|
||||||
|
|
Loading…
Reference in New Issue