Permalink
Browse files

Doc rendering like I wanted; Directory walking remains

  • Loading branch information...
dash1291 committed Apr 1, 2012
1 parent 0e8c304 commit e5054c8eef877c8dd630d2b96fa1623ad5b3b55f
Showing with 14 additions and 5 deletions.
  1. +14 −5 build.py
View
@@ -1,13 +1,17 @@
import re
+import os.path
-from jinja2 import Template
+from jinja2 import Template, FileSystemLoader, Environment
import markdown
# Walk through the directories
# Convert .md's to .html's
# Build homepage links
# Build archive page
+templates_path = os.path.join(os.path.dirname(__file__), 'templates')
+env = Environment(loader=FileSystemLoader(templates_path))
+
def build_options(doc_string):
# build a json object of doc options for easy access
opt_start = re.search('-+\n', doc_string).end()
@@ -17,14 +21,19 @@ def build_options(doc_string):
return options
def strip_options(doc_string):
- # coz I don't need those options to render as HTML
+ # coz I don't want those options to render as HTML
opt_end = re.search('\n-+', doc_string).start()
return doc_string[opt_end:]
def build_page(doc_path):
- doc_string = doc_path.read()
+ doc_string = open(doc_path).read()
options = build_options(doc_string)
doc_string = strip_options(doc_string)
- html = markdown.markdown(doc_string)
+ doc_html = markdown.markdown(doc_string)
+ page_title = options['title']
+ template_name = options['layout'] + '.html'
+ template = env.get_template(template_name)
+ rendered = template.render(title=page_title, content=doc_html)
+ return rendered
- # build further with jinja2
+build_page("doc.md")

0 comments on commit e5054c8

Please sign in to comment.