Skip to content

Commit

Permalink
Fix classic tree template
Browse files Browse the repository at this point in the history
  • Loading branch information
trungleduc committed Sep 28, 2023
1 parent 86946d4 commit 4f54252
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
2 changes: 1 addition & 1 deletion ui-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"build:base": "yarn run clean && cd ../demo && voici build --contents notebooks --config jupyter-lite.json",
"build:default": "yarn run build:base --output-dir ../ui-tests/lite",
"build:material": "yarn run build:base --output-dir ../ui-tests/material --template material",
"build:material": "yarn run build:base --output-dir ../ui-tests/material --template material --classic-tree true",
"build": "yarn run clean:dist && yarn run build:default && yarn run build:material",
"clean": "rimraf ../demo/.jupyterlite.doit.db",
"clean:dist": "rimraf ./lite ./material",
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 10 additions & 12 deletions voici/tree_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from typing import Dict, List, Tuple

import jinja2
import markupsafe
from jupyter_server.utils import url_escape, url_path_join
from nbconvert.exporters.html import HTMLExporter
from voila.configuration import VoilaConfiguration
Expand Down Expand Up @@ -89,27 +88,28 @@ def patch_page_config(
return page_config_copy


def resources_include_css(env, name):
code = """<style type="text/css">\n%s</style>""" % (
env.loader.get_source(env, name)[0]
)
return markupsafe.Markup(code)


class VoiciTreeExporter(HTMLExporter):
def __init__(
self,
jinja2_env: jinja2.Environment,
voici_configuration: VoilaConfiguration,
**kwargs,
):
self.jinja2_env = jinja2_env
self.jinja2_env = self._environment_cached = jinja2_env
self.voici_configuration = voici_configuration

self.theme = voici_configuration.theme
self.template_name = voici_configuration.template

self.notebook_paths = []
self.resources = self._init_resources()

def _init_resources(self):
resources = super()._init_resources({})
resources["include_lab_theme"] = partial(include_lab_theme, None)
resources["theme"] = self.validate_theme(self.theme, False)

return resources

def allowed_content(self, content: Dict) -> bool:
return content["type"] == "notebook" or content["type"] == "directory"
Expand Down Expand Up @@ -157,9 +157,7 @@ def render_tree(page_config) -> StringIO:
breadcrumbs=breadcrumbs,
page_config=page_config,
base_url=page_config["baseUrl"],
include_css=partial(resources_include_css, self.jinja2_env),
include_lab_theme=partial(include_lab_theme, None),
theme=self.validate_theme(self.theme, False),
**self.resources,
)
)

Expand Down

0 comments on commit 4f54252

Please sign in to comment.