mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
New plugin hook: extra_body_script
This commit is contained in:
parent
0a14a4846b
commit
5cf0c6c91c
6 changed files with 88 additions and 0 deletions
|
|
@ -25,6 +25,11 @@ def extra_js_urls():
|
|||
"Extra JavaScript URLs added by this plugin"
|
||||
|
||||
|
||||
@hookspec
|
||||
def extra_body_script(template, database, table, datasette):
|
||||
"Extra JavaScript code to be included in <script> at bottom of body"
|
||||
|
||||
|
||||
@hookspec
|
||||
def publish_subcommand(publish):
|
||||
"Subcommands for 'datasette publish'"
|
||||
|
|
|
|||
|
|
@ -35,6 +35,11 @@
|
|||
{% endif %}
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
{% for body_script in body_scripts %}
|
||||
<script>{{ body_script }}</script>
|
||||
{% endfor %}
|
||||
|
||||
{% if select_templates %}<!-- Templates considered: {{ select_templates|join(", ") }} -->{% endif %}
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -52,6 +52,14 @@ class RenderMixin(HTTPMethodView):
|
|||
"{}{}".format("*" if template_name == template.name else "", template_name)
|
||||
for template_name in templates
|
||||
]
|
||||
body_scripts = []
|
||||
for script in pm.hook.extra_body_script(
|
||||
template=template.name,
|
||||
database=context.get("database"),
|
||||
table=context.get("table"),
|
||||
datasette=self.ds
|
||||
):
|
||||
body_scripts.append(jinja2.Markup(script))
|
||||
return response.html(
|
||||
template.render(
|
||||
{
|
||||
|
|
@ -60,6 +68,7 @@ class RenderMixin(HTTPMethodView):
|
|||
"app_css_hash": self.ds.app_css_hash(),
|
||||
"select_templates": select_templates,
|
||||
"zip": zip,
|
||||
"body_scripts": body_scripts,
|
||||
}
|
||||
}
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue