Skip to content

Commit

Permalink
Add template priority
Browse files Browse the repository at this point in the history
  • Loading branch information
jtpio committed Jun 7, 2019
1 parent 93aa2be commit 45462c5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
12 changes: 8 additions & 4 deletions voila/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ def get(self, path=None):

# Fetch kernel name from the notebook metadata
kernel_name = notebook.metadata.get('kernelspec', {}).get('name', self.kernel_manager.default_kernel_name)
template_name = notebook.metadata.get('voila', {}).get('template', 'default')

# override with query parameter is it exists
template_name = self.get_query_argument('template', '') or template_name

# Launch kernel and execute notebook
cwd = os.path.dirname(notebook_path)
Expand All @@ -70,6 +66,14 @@ def get(self, path=None):
'theme': self.voila_configuration.theme
}

# choose the template
template_name = (
self.get_query_argument('template', '') or
notebook.metadata.get('voila', {}).get('template', '') or
self.voila_configuration.template or
'default'
)

# prioritize paths based on the template name
templates = sorted(self.nbconvert_template_paths, key=lambda p: -(template_name in p))

Expand Down
3 changes: 1 addition & 2 deletions voila/server_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ def load_jupyter_server_extension(server_app):
collect_template_paths(
nbconvert_template_paths,
static_paths,
template_paths,
voila_configuration.template
template_paths
)

jenv_opt = {"autoescape": True}
Expand Down

0 comments on commit 45462c5

Please sign in to comment.