Skip to content

Commit 22b0eff

Browse files
committed
Retrolite directive: Show tree if no Notebook specified
1 parent 557c38c commit 22b0eff

File tree

2 files changed

+37
-15
lines changed

2 files changed

+37
-15
lines changed

docs/index.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,19 @@ It takes the name of the Notebook as argument:
6262
:width: 100%
6363
:height: 600px
6464

65+
Or you can simply show the filetree:
66+
67+
.. code-block:: rst
68+
69+
.. retrolite::
70+
:width: 100%
71+
:height: 600px
72+
73+
.. retrolite::
74+
:width: 100%
75+
:height: 600px
76+
77+
6578
JupyterLab and RetroLab deployed for you
6679
----------------------------------------
6780

src/jupyterlite_sphinx.py

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,14 @@ def __init__(
106106
def html(self):
107107
notebook = self["notebook"]
108108

109+
src = (
110+
f"{JUPYTERLITE_DIR}/retro/notebooks/?path={notebook}"
111+
if notebook is not None
112+
else f"{JUPYTERLITE_DIR}/retro"
113+
)
114+
109115
return (
110-
f'<iframe src="{JUPYTERLITE_DIR}/retro/notebooks/?path={notebook}"'
116+
f'<iframe src="{src}"'
111117
f'width="{self["width"]}" height="{self["height"]}" style="{IFRAME_STYLE}"></iframe>'
112118
)
113119

@@ -119,31 +125,34 @@ class RetroliteDirective(SphinxDirective):
119125
"""
120126

121127
has_content = False
122-
required_arguments = 1
128+
optional_arguments = 1
123129
option_spec = {
124130
"width": directives.unchanged,
125131
"height": directives.unchanged,
126132
}
127133

128134
def run(self):
129-
notebook = self.arguments[0]
135+
width = self.options.get("width", "100%")
136+
height = self.options.get("height", "1000px")
130137

131-
# If we didn't get an absolute path,
132-
# try to find the Notebook relatively to the source
133-
if not os.path.isabs(notebook):
134-
source_location = os.path.dirname(self.get_source_info()[0])
135-
notebook = os.path.join(source_location, notebook)
138+
if self.arguments:
139+
notebook = self.arguments[0]
136140

137-
notebook_name = os.path.basename(notebook)
141+
# If we didn't get an absolute path,
142+
# try to find the Notebook relatively to the source
143+
if not os.path.isabs(notebook):
144+
source_location = os.path.dirname(self.get_source_info()[0])
145+
notebook = os.path.join(source_location, notebook)
138146

139-
width = self.options.get("width", "100%")
140-
height = self.options.get("height", "1000px")
147+
notebook_name = os.path.basename(notebook)
141148

142-
notebooks_dir = Path(self.env.app.srcdir) / CONTENT_DIR / notebook_name
149+
notebooks_dir = Path(self.env.app.srcdir) / CONTENT_DIR / notebook_name
143150

144-
# Copy the Notebook for RetroLite to find
145-
os.makedirs(os.path.dirname(notebooks_dir), exist_ok=True)
146-
shutil.copyfile(notebook, str(notebooks_dir))
151+
# Copy the Notebook for RetroLite to find
152+
os.makedirs(os.path.dirname(notebooks_dir), exist_ok=True)
153+
shutil.copyfile(notebook, str(notebooks_dir))
154+
else:
155+
notebook_name = None
147156

148157
return [RetroliteIframe(notebook=notebook_name, width=width, height=height)]
149158

0 commit comments

Comments
 (0)