Skip to content

Commit

Permalink
use dictloader and add back affects_environment tag to raw_template
Browse files Browse the repository at this point in the history
  • Loading branch information
mpacer committed Sep 16, 2017
1 parent 2975c1b commit 03f4dbf
Showing 1 changed file with 5 additions and 17 deletions.
22 changes: 5 additions & 17 deletions nbconvert/exporters/templateexporter.py
Expand Up @@ -17,7 +17,7 @@
from ipython_genutils import py3compat
from jinja2 import (
TemplateNotFound, Environment, ChoiceLoader, FileSystemLoader, BaseLoader,
FunctionLoader
DictLoader
)

from nbconvert import filters
Expand Down Expand Up @@ -58,19 +58,6 @@
'json_dumps': json.dumps,
}

class ExplicitFunctionLoader(FunctionLoader):
def __init__(self, load_func, template_list=None):
super(ExplicitFunctionLoader, self).__init__(load_func)
if isinstance(template_list, list):
self.template_list = template_list
else:
self.template_list = None

def list_templates(self):
if self.template_list:
return sorted(self.template_list)
else:
super(ExplicitFunctionLoader, self).list_templates()

class ExtensionTolerantLoader(BaseLoader):
"""A template loader which optionally adds a given extension when searching.
Expand Down Expand Up @@ -154,7 +141,7 @@ def default_config(self):
help="Name of the template file to use"
).tag(config=True, affects_template=True)

raw_template = Unicode('', help="raw template string")
raw_template = Unicode('', help="raw template string").tag(affects_environment=True)

_last_template_file = ""
raw_template_key = Unicode("<memory>",
Expand Down Expand Up @@ -419,8 +406,9 @@ def _create_environment(self):

loaders = self.extra_loaders + [
ExtensionTolerantLoader(FileSystemLoader(paths), self.template_extension),
ExplicitFunctionLoader(self._load_raw_template,
template_list=[self.raw_template_key])
# ExplicitFunctionLoader(self._load_raw_template,
# template_list=[self.raw_template_key])
DictLoader({self.raw_template_key: self.raw_template})
]
environment = Environment(
loader=ChoiceLoader(loaders),
Expand Down

0 comments on commit 03f4dbf

Please sign in to comment.