Skip to content

Commit

Permalink
Pass extra resources to the frontend as a Dict
Browse files Browse the repository at this point in the history
  • Loading branch information
mkcor committed Jul 14, 2019
1 parent c210116 commit 4144ed6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 30 deletions.
33 changes: 6 additions & 27 deletions voila/configuration.py
Expand Up @@ -7,7 +7,7 @@
#############################################################################

import traitlets.config
from traitlets import Unicode, Bool
from traitlets import Unicode, Bool, Dict


class VoilaConfiguration(traitlets.config.Configurable):
Expand All @@ -20,34 +20,13 @@ class VoilaConfiguration(traitlets.config.Configurable):
'template name to be used by voila.'
)
)
reveal_theme = Unicode(
'simple',
extra_resources = Dict(
{},
allow_none=True,
help="""
Used only with template reveal, ignored otherwise.
Name of the reveal.js theme to use.
We look for a file with this name under
``reveal_url_prefix``/css/theme/``reveal_theme``.css.
https://github.com/hakimel/reveal.js/tree/master/css/theme has
list of themes that ship by default with reveal.js.
"""
).tag(config=True)
reveal_transition = Unicode(
'slide',
allow_none=True,
help="""
Used only with template reveal, ignored otherwise.
Name of the reveal.js transition to use.
The list of transitions that ships by default with reveal.js are:
none, fade, slide, convex, concave and zoom.
"""
).tag(config=True)
reveal_scroll = Bool(
False,
allow_none=True,
help="""
Used only with template reveal, ignored otherwise.
If True, enable scrolling within each slide
extra resources used by templates;
example use with --template=reveal
--extra_resources="{'reveal': {'transition': 'fade', 'scroll': True}}"
"""
).tag(config=True)
theme = Unicode('light').tag(config=True)
Expand Down
22 changes: 19 additions & 3 deletions voila/handler.py
Expand Up @@ -72,13 +72,29 @@ def get(self, path=None):
# add extra resources (necessary for reveal template)
resources_reveal = {
'reveal': {
'theme': self.voila_configuration.reveal_theme,
'transition': self.voila_configuration.reveal_transition,
'scroll': self.voila_configuration.reveal_scroll,
'theme': 'simple',
'transition': 'slide',
'scroll': False,
}
}
resources.update(resources_reveal)

# include potential extra resources
extra_resources = self.voila_configuration.extra_resources
if extra_resources:
for k in extra_resources.keys():
if k in resources.keys():
if isinstance(extra_resources[k], dict):
for kk in extra_resources[k].keys():
# update or add depth-2 resources
resources[k][kk] = extra_resources[k][kk]
else:
# update depth-1 (top-level) resources
resources[k] = extra_resources[k]
else:
# add depth-1 (top-level) resources
resources[k] = extra_resources[k]

exporter = VoilaExporter(
template_path=self.nbconvert_template_paths,
config=self.exporter_config,
Expand Down

0 comments on commit 4144ed6

Please sign in to comment.