Skip to content

Commit

Permalink
Add more macros
Browse files Browse the repository at this point in the history
This makes it easier to inherit from the template and reuse some logic
  • Loading branch information
martinRenou committed Jan 18, 2022
1 parent c2ffd55 commit dbed9ac
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
21 changes: 20 additions & 1 deletion share/jupyter/voila/templates/base/voila_setup.macro.html.j2
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{%- macro voila_setup(base_url, nbextensions) -%}
{# Macro for loading the notebook extensions #}
{%- macro voila_setup_nbextensions(base_url, nbextensions) -%}
<script>
requirejs.config({ baseUrl: '{{base_url}}voila/', waitSeconds: 30});
window.voila_js_url = "{{ static_url('voila.js')}}";
Expand All @@ -17,3 +18,21 @@
{% endfor %}
</script>
{%- endmacro %}

{# For backward compatibility #}
{%- macro voila_setup(base_url, nbextensions) -%}
{{ voila_setup_nbextensions(base_url, nbextensions) }}
{%- endmacro %}

{# Helper functions for updating the loading text #}
{%- macro voila_setup_helper_functions() -%}
<script>
var voila_process = function(cell_index, cell_count) {
var el = document.getElementById("loading_text");
el.innerHTML = `Executing ${cell_index} of ${cell_count}`;
}
var voila_heartbeat = function() {
console.log('Ok, voila is still executing...');
}
</script>
{%- endmacro %}
14 changes: 3 additions & 11 deletions share/jupyter/voila/templates/lab/index.html.j2
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{%- extends 'nbconvert/templates/lab/index.html.j2' -%}
{% import "spinner.macro.html.j2" as spinner %}
{% import "log.macro.html.j2" as log %}
{% from 'voila_setup.macro.html.j2' import voila_setup with context %}
{% from 'voila_setup.macro.html.j2' import voila_setup_helper_functions, voila_setup_nbextensions with context %}

{%- block html_head_js -%}
{%- block html_head_js_requirejs -%}
Expand Down Expand Up @@ -40,15 +40,7 @@
<body class="jp-Notebook theme-light" data-base-url="{{resources.base_url}}voila/" data-jp-theme-light="true" data-jp-theme-name="JupyterLab Light">
{% endif %}
{{ spinner.html() }}
<script>
var voila_process = function(cell_index, cell_count) {
var el = document.getElementById("loading_text")
el.innerHTML = `Executing ${cell_index} of ${cell_count}`
}
var voila_heartbeat = function() {
console.log('Ok, voila is still executing...')
}
</script>
{{ voila_setup_helper_functions() }}
<div id="rendered_cells" style="display: none">
{%- endblock body_header -%}

Expand Down Expand Up @@ -92,7 +84,7 @@ var voila_heartbeat = function() {
el.style.display = 'unset'
})();
</script>
{{ voila_setup(resources.base_url, resources.nbextensions) }}
{{ voila_setup_nbextensions(resources.base_url, resources.nbextensions) }}
{{ super() }}
{%- endblock body_footer -%}

Expand Down

0 comments on commit dbed9ac

Please sign in to comment.