Skip to content

Commit dbed9ac

Browse files
committed
Add more macros
This makes it easier to inherit from the template and reuse some logic
1 parent c2ffd55 commit dbed9ac

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

share/jupyter/voila/templates/base/voila_setup.macro.html.j2

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
{%- macro voila_setup(base_url, nbextensions) -%}
1+
{# Macro for loading the notebook extensions #}
2+
{%- macro voila_setup_nbextensions(base_url, nbextensions) -%}
23
<script>
34
requirejs.config({ baseUrl: '{{base_url}}voila/', waitSeconds: 30});
45
window.voila_js_url = "{{ static_url('voila.js')}}";
@@ -17,3 +18,21 @@
1718
{% endfor %}
1819
</script>
1920
{%- endmacro %}
21+
22+
{# For backward compatibility #}
23+
{%- macro voila_setup(base_url, nbextensions) -%}
24+
{{ voila_setup_nbextensions(base_url, nbextensions) }}
25+
{%- endmacro %}
26+
27+
{# Helper functions for updating the loading text #}
28+
{%- macro voila_setup_helper_functions() -%}
29+
<script>
30+
var voila_process = function(cell_index, cell_count) {
31+
var el = document.getElementById("loading_text");
32+
el.innerHTML = `Executing ${cell_index} of ${cell_count}`;
33+
}
34+
var voila_heartbeat = function() {
35+
console.log('Ok, voila is still executing...');
36+
}
37+
</script>
38+
{%- endmacro %}

share/jupyter/voila/templates/lab/index.html.j2

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{%- extends 'nbconvert/templates/lab/index.html.j2' -%}
22
{% import "spinner.macro.html.j2" as spinner %}
33
{% import "log.macro.html.j2" as log %}
4-
{% from 'voila_setup.macro.html.j2' import voila_setup with context %}
4+
{% from 'voila_setup.macro.html.j2' import voila_setup_helper_functions, voila_setup_nbextensions with context %}
55

66
{%- block html_head_js -%}
77
{%- block html_head_js_requirejs -%}
@@ -40,15 +40,7 @@
4040
<body class="jp-Notebook theme-light" data-base-url="{{resources.base_url}}voila/" data-jp-theme-light="true" data-jp-theme-name="JupyterLab Light">
4141
{% endif %}
4242
{{ spinner.html() }}
43-
<script>
44-
var voila_process = function(cell_index, cell_count) {
45-
var el = document.getElementById("loading_text")
46-
el.innerHTML = `Executing ${cell_index} of ${cell_count}`
47-
}
48-
var voila_heartbeat = function() {
49-
console.log('Ok, voila is still executing...')
50-
}
51-
</script>
43+
{{ voila_setup_helper_functions() }}
5244
<div id="rendered_cells" style="display: none">
5345
{%- endblock body_header -%}
5446

@@ -92,7 +84,7 @@ var voila_heartbeat = function() {
9284
el.style.display = 'unset'
9385
})();
9486
</script>
95-
{{ voila_setup(resources.base_url, resources.nbextensions) }}
87+
{{ voila_setup_nbextensions(resources.base_url, resources.nbextensions) }}
9688
{{ super() }}
9789
{%- endblock body_footer -%}
9890

0 commit comments

Comments
 (0)