mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
prepare_jinja2_environment(datasette) argument, refs #1809
This commit is contained in:
parent
610425460b
commit
b40872f5e5
5 changed files with 14 additions and 7 deletions
|
|
@ -142,8 +142,9 @@ def extra_template_vars(
|
|||
|
||||
|
||||
@hookimpl
|
||||
def prepare_jinja2_environment(env):
|
||||
def prepare_jinja2_environment(env, datasette):
|
||||
env.filters["format_numeric"] = lambda s: f"{float(s):,.0f}"
|
||||
env.filters["to_hello"] = lambda s: datasette._HELLO
|
||||
|
||||
|
||||
@hookimpl
|
||||
|
|
|
|||
|
|
@ -545,11 +545,12 @@ def test_hook_register_output_renderer_can_render(app_client):
|
|||
|
||||
@pytest.mark.asyncio
|
||||
async def test_hook_prepare_jinja2_environment(app_client):
|
||||
app_client.ds._HELLO = "HI"
|
||||
template = app_client.ds.jinja_env.from_string(
|
||||
"Hello there, {{ a|format_numeric }}", {"a": 3412341}
|
||||
"Hello there, {{ a|format_numeric }}, {{ a|to_hello }}", {"a": 3412341}
|
||||
)
|
||||
rendered = await app_client.ds.render_template(template)
|
||||
assert "Hello there, 3,412,341" == rendered
|
||||
assert "Hello there, 3,412,341, HI" == rendered
|
||||
|
||||
|
||||
def test_hook_publish_subcommand():
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue