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

Feature: template and theme override #637

Merged

Conversation

maartenbreddels
Copy link
Member

Implements #635 Replaces #629, #201 and #258

This allow overriding the template and theme, e.g.:

http://localhost:8866/voila/render/basics.ipynb?voila-template=material&voila-theme=dark

Or via notebook metadata:

....
 "metadata": {
  "voila": {
    "template": "material",
    "theme": "dark"
  },
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
....

Configuration to disable this:

$ voila notebooks/ --VoilaConfiguration.allow_template_override=NO  # never allow this
$ voila notebooks/ --VoilaConfiguration.allow_template_override=NOTEBOOK  # only via notebook metadata
$ voila notebooks/ --VoilaConfiguration.allow_theme_override=NOTEBOOK  # similar for theme

@maartenbreddels maartenbreddels force-pushed the feat_template_override branch from e845be1 to deaee4f Compare June 24, 2020 10:13
@maartenbreddels
Copy link
Member Author

Note that this PR also changes the static URL to include a hash, like `voila.js?v=ae356' such that we don't get bitten by aggressive caching. This is a feature of tornado, that also the notebook uses, and we simply didn't make use of.

@maartenbreddels maartenbreddels force-pushed the feat_template_override branch 6 times, most recently from f068dea to 74b866a Compare June 24, 2020 14:36
Comment on lines +16 to +18
allow_template_override = Enum(['YES', 'NOTEBOOK', 'NO'], 'YES', help='''
Allow overriding the template (YES), or not (NO), or only from the notebook metadata.
''').tag(config=True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering whether something like ['url', 'notebook', 'all'] would sound more explicit?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My reasoning was that you probably don't want the combination of 'permit from URL', but not from notebook metadata. Or can you come up with te use case?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was mostly for users who want to set the option without reading the docs or the help string, to know what 'YES' and 'NO' mean in this case.

@jtpio
Copy link
Member

jtpio commented Jul 14, 2020

Nice, thanks @maartenbreddels 👍

We will probably want to add a quick word about this feature in the docs too.

@maartenbreddels maartenbreddels force-pushed the feat_template_override branch 2 times, most recently from 608a22b to e3ce714 Compare August 18, 2020 13:59
@maartenbreddels
Copy link
Member Author

Closes #105

cailiang9 and others added 6 commits September 7, 2020 14:50
example format: {"voila":{"template","default"}}
To implement this, we had to redo the static resources handling, which
is now using a path like:
voila/templates/<template_name>/static/path/to/file.js

Since we use the StaticFileHandler from tornado, we should have used
the ?v=<hash> feature, which is now always used, to avoid aggresive caching
by browsers.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants