Skip to content

Commit

Permalink
Merge pull request openedx#452 from MITx/feature/bridger/new_wiki
Browse files Browse the repository at this point in the history
Feature/bridger/new wiki
  • Loading branch information
David Ormsbee committed Aug 19, 2012
2 parents cf20839 + c4512fa commit 2a250fd
Show file tree
Hide file tree
Showing 37 changed files with 2,500 additions and 207 deletions.
25 changes: 20 additions & 5 deletions common/djangoapps/mitxmako/makoloader.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import logging

from django.conf import settings
from django.template.base import TemplateDoesNotExist
from django.template.loader import make_origin, get_template_from_string
from django.template.loaders.filesystem import Loader as FilesystemLoader
from django.template.loaders.app_directories import Loader as AppDirectoriesLoader

from mitxmako.template import Template
import mitxmako.middleware


log = logging.getLogger(__name__)

class MakoLoader(object):
"""
Expand All @@ -18,20 +24,29 @@ class MakoLoader(object):
def __init__(self, base_loader):
# base_loader is an instance of a BaseLoader subclass
self.base_loader = base_loader


module_directory = getattr(settings, 'MAKO_MODULE_DIR', None)

if module_directory is None:
log.warning("For more caching of mako templates, set the MAKO_MODULE_DIR in settings!")
module_directory = tempfile.mkdtemp()

self.module_directory = module_directory


def __call__(self, template_name, template_dirs=None):
return self.load_template(template_name, template_dirs)

def load_template(self, template_name, template_dirs=None):
source, display_name = self.load_template_source(template_name, template_dirs)
source, file_path = self.load_template_source(template_name, template_dirs)

if source.startswith("## mako\n"):
# This is a mako template
template = Template(text=source, uri=template_name)
template = Template(filename=file_path, module_directory=self.module_directory, uri=template_name)
return template, None
else:
# This is a regular template
origin = make_origin(display_name, self.load_template_source, template_name, template_dirs)
origin = make_origin(file_path, self.load_template_source, template_name, template_dirs)
try:
template = get_template_from_string(source, origin, template_name)
return template, None
Expand All @@ -40,7 +55,7 @@ def load_template(self, template_name, template_dirs=None):
# returning the source and display name for the template we were asked to load.
# This allows for correct identification (later) of the actual template that does
# not exist.
return source, display_name
return source, file_path

def load_template_source(self, template_name, template_dirs=None):
# Just having this makes the template load as an instance, instead of a class.
Expand Down
3 changes: 1 addition & 2 deletions common/djangoapps/mitxmako/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@

from mitxmako import middleware

django_variables = ['lookup', 'output_encoding',
'module_directory', 'encoding_errors']
django_variables = ['lookup', 'output_encoding', 'encoding_errors']

# TODO: We should make this a Django Template subclass that simply has the MakoTemplate inside of it? (Intead of inheriting from MakoTemplate)
class Template(MakoTemplate):
Expand Down
Loading

0 comments on commit 2a250fd

Please sign in to comment.