Skip to content

Commit f9a95eb

Browse files
committed
added voila template
1 parent 8f349be commit f9a95eb

File tree

8 files changed

+15103
-7
lines changed

8 files changed

+15103
-7
lines changed

setup.py

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,38 @@
11
"""
22
jupyterlab-interactive-dashboard-editor setup
33
"""
4+
import sys
45
import json
5-
from os import path
6+
import os
67

78
from jupyter_packaging import (
89
create_cmdclass, install_npm, ensure_targets,
910
combine_commands, skip_if_exists
1011
)
1112

13+
try:
14+
import jupyter_core.paths as jupyter_core_paths
15+
except:
16+
jupyter_core_paths = None
17+
1218
import setuptools
1319

14-
HERE = path.abspath(path.dirname(__file__))
20+
HERE = os.path.abspath(os.path.dirname(__file__))
1521

1622
# The name of the project
1723
name = "jupyterlab-interactive-dashboard-editor"
1824
module = "jupyterlab_interactive_dashboard_editor"
1925
labext_name = "jupyterlab-interactive-dashboard-editor"
2026

2127
# Get our version
22-
with open(path.join(HERE, 'package.json')) as f:
28+
with open(os.path.join(HERE, 'package.json')) as f:
2329
version = json.load(f)['version']
2430

25-
lab_path = path.join(HERE, module, "labextension")
31+
lab_path = os.path.join(HERE, module, "labextension")
2632

2733
# Representative files that should exist after a successful build
2834
jstargets = [
29-
path.join(lab_path, "package.json"),
35+
os.path.join(lab_path, "package.json"),
3036
]
3137

3238
package_data_spec = {
@@ -51,12 +57,44 @@
5157
path=HERE,
5258
npm=["jlpm"],
5359
build_cmd="build:labextension",
54-
build_dir=path.join(HERE, 'dist'),
55-
source_dir=path.join(HERE, 'src')
60+
build_dir=os.path.join(HERE, 'dist'),
61+
source_dir=os.path.join(HERE, 'src')
5662
),
5763
ensure_targets(jstargets),
5864
)
5965

66+
base_develop_cmd = cmdclass["develop"]
67+
68+
class DevelopCmd(base_develop_cmd):
69+
prefix_targets = [
70+
("nbconvert/templates", 'presto'),
71+
("voila/templates", 'presto')
72+
]
73+
74+
def run(self):
75+
target_dir = os.path.join(sys.prefix, "share", "jupyter")
76+
if "--user" in sys.prefix:
77+
target_dir = jupyter_core_paths.user_dir()
78+
target_dir = os.path.join(target_dir)
79+
80+
for prefix_target, name in self.prefix_targets:
81+
source = os.path.join("share", "jupyter", prefix_target, name)
82+
target = os.path.join(target_dir, prefix_target, name)
83+
target_subdir = os.path.dirname(target)
84+
if not os.path.exists(target_subdir):
85+
os.makedirs(target_subdir)
86+
rel_source = os.path.relpath(os.path.abspath(source), os.path.abspath(target_subdir))
87+
try:
88+
os.remove(target)
89+
except:
90+
pass
91+
print(rel_source, "->", target)
92+
os.symlink(rel_source, target)
93+
94+
super(DevelopCmd, self).run()
95+
96+
cmdclass['develop'] = DevelopCmd if jupyter_core_paths else base_develop_cmd
97+
6098
with open("README.md", "r") as fh:
6199
long_description = fh.read()
62100

Lines changed: 270 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,270 @@
1+
{%- extends 'display_priority.j2' -%}
2+
{% from 'celltags.j2' import celltags %}
3+
4+
{% block codecell %}
5+
{%- if not cell.outputs -%}
6+
{%- set no_output_class="jp-mod-noOutputs" -%}
7+
{%- endif -%}
8+
{%- if not resources.global_content_filter.include_input -%}
9+
{%- set no_input_class="jp-mod-noInput" -%}
10+
{%- endif -%}
11+
<div class="jp-Cell jp-CodeCell jp-Notebook-cell {{ no_output_class }} {{ no_input_class }} {{ celltags(cell) }}">
12+
{{ super() }}
13+
</div>
14+
{%- endblock codecell %}
15+
16+
{% block input_group -%}
17+
<div class="jp-Cell-inputWrapper">
18+
<div class="jp-InputArea jp-Cell-inputArea">
19+
{{ super() }}
20+
</div>
21+
</div>
22+
{% endblock input_group %}
23+
24+
{% block input %}
25+
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
26+
<div class="CodeMirror cm-s-jupyter">
27+
{{ cell.source | highlight_code(metadata=cell.metadata) }}
28+
</div>
29+
</div>
30+
{%- endblock input %}
31+
32+
{% block output_group %}
33+
<div class="jp-Cell-outputWrapper">
34+
{{ super() }}
35+
</div>
36+
{% endblock output_group %}
37+
38+
{% block outputs %}
39+
<div class="jp-OutputArea jp-Cell-outputArea">
40+
{{ super() }}
41+
</div>
42+
{% endblock outputs %}
43+
44+
{% block in_prompt -%}
45+
<div class="jp-InputPrompt jp-InputArea-prompt">
46+
{%- if cell.execution_count is defined -%}
47+
In&nbsp;[{{ cell.execution_count|replace(None, "&nbsp;") }}]:
48+
{%- else -%}
49+
In&nbsp;[&nbsp;]:
50+
{%- endif -%}
51+
</div>
52+
{%- endblock in_prompt %}
53+
54+
{% block empty_in_prompt -%}
55+
<div class="jp-InputPrompt jp-InputArea-prompt">
56+
</div>
57+
{%- endblock empty_in_prompt %}
58+
59+
{#
60+
output_prompt doesn't do anything in HTML,
61+
because there is a prompt div in each output area (see output block)
62+
#}
63+
{% block output_prompt %}
64+
{% endblock output_prompt %}
65+
66+
{% block output_area_prompt %}
67+
<div class="jp-OutputPrompt jp-OutputArea-prompt">
68+
{%- if output.output_type == 'execute_result' -%}
69+
{%- if cell.execution_count is defined -%}
70+
Out[{{ cell.execution_count|replace(None, "&nbsp;") }}]:
71+
{%- else -%}
72+
Out[&nbsp;]:
73+
{%- endif -%}
74+
{%- endif -%}
75+
</div>
76+
{% endblock output_area_prompt %}
77+
78+
{% block output %}
79+
<div class="jp-OutputArea-child">
80+
{% if resources.global_content_filter.include_output_prompt %}
81+
{{ self.output_area_prompt() }}
82+
{% endif %}
83+
{{ super() }}
84+
</div>
85+
{% endblock output %}
86+
87+
{% block markdowncell scoped %}
88+
<div class="jp-Cell-inputWrapper">
89+
{%- if resources.global_content_filter.include_input_prompt-%}
90+
{{ self.empty_in_prompt() }}
91+
{%- endif -%}
92+
<div class="jp-RenderedHTMLCommon jp-RenderedMarkdown jp-MarkdownOutput {{ celltags(cell) }}" data-mime-type="text/markdown">
93+
{{ cell.source | markdown2html | strip_files_prefix }}
94+
</div>
95+
</div>
96+
{%- endblock markdowncell %}
97+
98+
{% block unknowncell scoped %}
99+
unknown type {{ cell.type }}
100+
{% endblock unknowncell %}
101+
102+
{% block execute_result -%}
103+
{%- set extra_class="jp-OutputArea-executeResult" -%}
104+
{% block data_priority scoped %}
105+
{{ super() }}
106+
{% endblock data_priority %}
107+
{%- set extra_class="" -%}
108+
{%- endblock execute_result %}
109+
110+
{% block stream_stdout -%}
111+
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="text/plain">
112+
<pre>
113+
{{- output.text | ansi2html -}}
114+
</pre>
115+
</div>
116+
{%- endblock stream_stdout %}
117+
118+
{% block stream_stderr -%}
119+
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="application/vnd.jupyter.stderr">
120+
<pre>
121+
{{- output.text | ansi2html -}}
122+
</pre>
123+
</div>
124+
{%- endblock stream_stderr %}
125+
126+
{% block data_svg scoped -%}
127+
<div class="jp-RenderedSVG jp-OutputArea-output {{ extra_class }}" data-mime-type="image/svg+xml">
128+
{%- if output.svg_filename %}
129+
<img src="{{ output.svg_filename | posix_path }}">
130+
{%- else %}
131+
{{ output.data['image/svg+xml'] }}
132+
{%- endif %}
133+
</div>
134+
{%- endblock data_svg %}
135+
136+
{% block data_html scoped -%}
137+
<div class="jp-RenderedHTMLCommon jp-RenderedHTML jp-OutputArea-output {{ extra_class }}" data-mime-type="text/html">
138+
{{ output.data['text/html'] }}
139+
</div>
140+
{%- endblock data_html %}
141+
142+
{% block data_markdown scoped -%}
143+
<div class="jp-RenderedHTMLCommon jp-RenderedMarkdown jp-OutputArea-output {{ extra_class }}" data-mime-type="text/markdown">
144+
{{ output.data['text/markdown'] | markdown2html }}
145+
</div>
146+
{%- endblock data_markdown %}
147+
148+
{% block data_png scoped %}
149+
<div class="jp-RenderedImage jp-OutputArea-output {{ extra_class }}">
150+
{%- if 'image/png' in output.metadata.get('filenames', {}) %}
151+
<img src="{{ output.metadata.filenames['image/png'] | posix_path }}"
152+
{%- else %}
153+
<img src="data:image/png;base64,{{ output.data['image/png'] }}"
154+
{%- endif %}
155+
{%- set width=output | get_metadata('width', 'image/png') -%}
156+
{%- if width is not none %}
157+
width={{ width }}
158+
{%- endif %}
159+
{%- set height=output | get_metadata('height', 'image/png') -%}
160+
{%- if height is not none %}
161+
height={{ height }}
162+
{%- endif %}
163+
{%- if output | get_metadata('unconfined', 'image/png') %}
164+
class="unconfined"
165+
{%- endif %}
166+
>
167+
</div>
168+
{%- endblock data_png %}
169+
170+
{% block data_jpg scoped %}
171+
<div class="jp-RenderedImage jp-OutputArea-output {{ extra_class }}">
172+
{%- if 'image/jpeg' in output.metadata.get('filenames', {}) %}
173+
<img src="{{ output.metadata.filenames['image/jpeg'] | posix_path }}"
174+
{%- else %}
175+
<img src="data:image/jpeg;base64,{{ output.data['image/jpeg'] }}"
176+
{%- endif %}
177+
{%- set width=output | get_metadata('width', 'image/jpeg') -%}
178+
{%- if width is not none %}
179+
width={{ width }}
180+
{%- endif %}
181+
{%- set height=output | get_metadata('height', 'image/jpeg') -%}
182+
{%- if height is not none %}
183+
height={{ height }}
184+
{%- endif %}
185+
{%- if output | get_metadata('unconfined', 'image/jpeg') %}
186+
class="unconfined"
187+
{%- endif %}
188+
>
189+
</div>
190+
{%- endblock data_jpg %}
191+
192+
{% block data_latex scoped %}
193+
<div class="jp-RenderedLatex jp-OutputArea-output {{ extra_class }}" data-mime-type="text/latex">
194+
{{ output.data['text/latex'] | e }}
195+
</div>
196+
{%- endblock data_latex %}
197+
198+
{% block error -%}
199+
<div class="jp-RenderedText jp-OutputArea-output" data-mime-type="application/vnd.jupyter.stderr">
200+
<pre>
201+
{{- super() -}}
202+
</pre>
203+
</div>
204+
{%- endblock error %}
205+
206+
{%- block traceback_line %}
207+
{{ line | ansi2html }}
208+
{%- endblock traceback_line %}
209+
210+
{%- block data_text scoped %}
211+
<div class="jp-RenderedText jp-OutputArea-output {{ extra_class }}" data-mime-type="text/plain">
212+
<pre>
213+
{{- output.data['text/plain'] | ansi2html -}}
214+
</pre>
215+
</div>
216+
{%- endblock -%}
217+
218+
{#
219+
###############################################################################
220+
# TODO: how to better handle JavaScript repr? #
221+
###############################################################################
222+
#}
223+
224+
{% set div_id = uuid4() %}
225+
{%- block data_javascript scoped %}
226+
<div id="{{ div_id }}" class="jp-RenderedJavaScript jp-OutputArea-output {{ extra_class }}" data-mime-type="application/javascript">
227+
<script type="text/javascript">
228+
var element = document.getElementById('{{ div_id }}');
229+
{{ output.data['application/javascript'] }}
230+
</script>
231+
</div>
232+
{%- endblock -%}
233+
234+
{%- block data_widget_state scoped %}
235+
{% set div_id = uuid4() %}
236+
{% set datatype_list = output.data | filter_data_type %}
237+
{% set datatype = datatype_list[0]%}
238+
<div id="{{ div_id }}" class="output_subarea output_widget_state {{ extra_class }}">
239+
<script type="text/javascript">
240+
var element = document.getElementById('{{ div_id }}');
241+
</script>
242+
<script type="{{ datatype }}">
243+
{{ output.data[datatype] | json_dumps }}
244+
</script>
245+
</div>
246+
{%- endblock data_widget_state -%}
247+
248+
{%- block data_widget_view scoped %}
249+
{% set div_id = uuid4() %}
250+
{% set datatype_list = output.data | filter_data_type %}
251+
{% set datatype = datatype_list[0]%}
252+
<div id="{{ div_id }}" class="jupyter-widgets jp-OutputArea-output {{ extra_class }}">
253+
<script type="text/javascript">
254+
var element = document.getElementById('{{ div_id }}');
255+
</script>
256+
<script type="{{ datatype }}">
257+
{{ output.data[datatype] | json_dumps }}
258+
</script>
259+
</div>
260+
{%- endblock data_widget_view -%}
261+
262+
{%- block footer %}
263+
{% set mimetype = 'application/vnd.jupyter.widget-state+json'%}
264+
{% if mimetype in nb.metadata.get("widgets",{})%}
265+
<script type="{{ mimetype }}">
266+
{{ nb.metadata.widgets[mimetype] | json_dumps }}
267+
</script>
268+
{% endif %}
269+
{{ super() }}
270+
{%- endblock footer-%}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"base_template": "base",
3+
"mimetypes": {
4+
"text/html": true
5+
},
6+
"preprocessors": {
7+
"100-pygments": {
8+
"type": "nbconvert.preprocessors.CSSHTMLHeaderPreprocessor",
9+
"enabled": true
10+
}
11+
}
12+
}

0 commit comments

Comments
 (0)