Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add template block prior to extra URL loaders #1049

Closed

Conversation

psychemedia
Copy link
Contributor

To handle packages that require Javascript state setting prior to loading a package (eg thebelab, provide a template block before the URLs are loaded.

To handle packages that require Javascript state setting prior to loading a package (eg [`thebelab`](https://thebelab.readthedocs.io/en/latest/examples/minimal_example.html), provide a template block before the URLs are loaded.
@codecov
Copy link

codecov bot commented Oct 25, 2020

Codecov Report

Merging #1049 into main will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #1049   +/-   ##
=======================================
  Coverage   84.72%   84.72%           
=======================================
  Files          28       28           
  Lines        3942     3942           
=======================================
  Hits         3340     3340           
  Misses        602      602           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 42f4851...50a743a. Read the comment docs.

@simonw
Copy link
Owner

simonw commented Oct 29, 2020

thebe is the first time I've seen a library that requires you to set up some global JavaScript configuration before loading the script itself.

I'm hesitant to add an extra template block just to cover that one case since it's such a rare pattern. But it's important that thebelab can be used with Datasette.

Would this pattern work for you instead?

{% block extra_head %}
<script type="text/x-thebe-config">
  {
    requestKernel: true,
    binderOptions: {
      repo: "binder-examples/requirements",
    },
  }
</script>
<script src="https://unpkg.com/thebelab@latest/lib/index.js"></script>
{% endblock %}

@simonw
Copy link
Owner

simonw commented Oct 29, 2020

You could use Datasette's new {{ urls.static_plugins(...) }} template option - see https://docs.datasette.io/en/latest/internals.html#internals-datasette-urls - to generate a link to code that was bundled with the plugin:

{% block extra_head %}
<script type="text/x-thebe-config">
  {
    requestKernel: true,
    binderOptions: {
      repo: "binder-examples/requirements",
    },
  }
</script>
<script src="{{ urls.static_plugins("datasette-thebelab-plugin", "thebelab-index.js")"></script>
{% endblock %}

@psychemedia
Copy link
Contributor Author

That workaround is probably fine. I was trying to work out whether there might be other situations where a pre-external package load might be useful but couldn't offhand bring any other examples to mind. The static plugins option also looks interesting.

@psychemedia psychemedia deleted the psychemedia-update_base_template branch October 29, 2020 09:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants