extra_template_vars plugin hook (#542)

* extra_template_vars plugin hook

Closes #541

* Workaround for cwd bug

Based on https://github.com/pytest-dev/pytest/issues/1235#issuecomment-175295691
This commit is contained in:
Simon Willison 2019-07-05 17:05:56 -07:00
commit 42d6877784
9 changed files with 186 additions and 19 deletions

View file

@ -376,6 +376,16 @@ def render_cell(value, column, table, database, datasette):
table=table,
)
})
@hookimpl
def extra_template_vars(template, database, table, view_name, request, datasette):
return {
"extra_template_vars": json.dumps({
"template": template,
"scope_path": request.scope["path"]
}, default=lambda b: b.decode("utf8"))
}
"""
PLUGIN2 = """
@ -424,6 +434,19 @@ def render_cell(value, database):
)
@hookimpl
def extra_template_vars(template, database, table, view_name, request, datasette):
async def inner():
return {
"extra_template_vars_from_awaitable": json.dumps({
"template": template,
"scope_path": request.scope["path"],
"awaitable": True,
}, default=lambda b: b.decode("utf8"))
}
return inner
@hookimpl
def asgi_wrapper(datasette):
def wrap_with_databases_header(app):