Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing custom resources to voila configuration #301

Merged
merged 10 commits into from Jul 24, 2019
10 changes: 9 additions & 1 deletion 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,6 +20,14 @@ class VoilaConfiguration(traitlets.config.Configurable):
'template name to be used by voila.'
)
)
resources = Dict(
allow_none=True,
help="""
extra resources used by templates;
example use with --template=reveal
--resources="{'reveal': {'transition': 'fade', 'scroll': True}}"
"""
).tag(config=True)
theme = Unicode('light').tag(config=True)
strip_sources = Bool(True, help='Strip sources from rendered html').tag(config=True)
enable_nbextensions = Bool(False, config=True, help=('Set to True for Voila to load notebook extensions'))
16 changes: 16 additions & 0 deletions voila/handler.py
Expand Up @@ -11,6 +11,7 @@
import tornado.web

from jupyter_server.base.handlers import JupyterHandler
from jupyter_server.config_manager import recursive_update

from .execute import executenb
from .exporter import VoilaExporter
Expand Down Expand Up @@ -67,6 +68,21 @@ def get(self, path=None):
'theme': self.voila_configuration.theme
}

# add extra resources (necessary for reveal template)
resources_reveal = {
'reveal': {
'theme': 'simple',
'transition': 'slide',
'scroll': False,
}
}
resources.update(resources_reveal)

# include potential extra resources
extra_resources = self.voila_configuration.resources
if extra_resources:
recursive_update(resources, extra_resources)

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