Skip to content

Commit

Permalink
Adding first stab at a Markdown/Yaml email template
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlovelltroy committed Feb 18, 2014
1 parent 3a822bd commit f86c6d7
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions classy_mail/template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from django.template import Template, TemplateEncodingError
from markdown import markdown
import yaml
#from BeautifulSoup import BeautifulSoup


class MarkdownTemplate(Template):
def __init__(self, template_string, origin=None, name=None):
split_template = template_string.split("---\n")
if len(split_template) == 3:
context = yaml.load(split_template[1])
if isinstance(context, type({})):
template_string = split_template[2]
self.frontmatter = context
try:
template_string = markdown(template_string)
super(Template, self).__init__(
template_string,
origin=origin,
name=name
)
except UnicodeDecodeError:
raise TemplateEncodingError("Templates can only be constructed "
"from unicode or UTF-8 strings.")

0 comments on commit f86c6d7

Please # to comment.