Skip to content

Commit

Permalink
Merge pull request #1057 from martinRenou/add_macros
Browse files Browse the repository at this point in the history
Add more Jinja macros
  • Loading branch information
martinRenou authored Jan 18, 2022
2 parents 63e0f91 + dbed9ac commit 45d4d86
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 45d4d86

Please sign in to comment.