Support `.jinja` for theme static templates (#11916)

Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
This commit is contained in:
James Addison
2024-04-23 10:40:24 +01:00
committed by GitHub
parent 5a55856dd1
commit 0806a00f05
11 changed files with 77 additions and 14 deletions

View File

@@ -0,0 +1 @@
AU REVOIR, KANIGGETS

View File

@@ -0,0 +1,2 @@
<!-- testing legacy _t static templates -->
<html><project>{{ project | lower | escape }}</project></html>

View File

@@ -1391,6 +1391,7 @@ def test_latex_table_custom_template_caseA(app, status, warning):
app.build(force_all=True)
result = (app.outdir / 'python.tex').read_text(encoding='utf8')
assert 'SALUT LES COPAINS' in result
assert 'AU REVOIR, KANIGGETS' in result
@pytest.mark.sphinx('latex', testroot='latex-table',

View File

@@ -109,6 +109,11 @@ def test_nested_zipped_theme(app, status, warning):
@pytest.mark.sphinx(testroot='theming', confoverrides={'html_theme': 'staticfiles'})
def test_staticfiles(app, status, warning):
app.build()
assert (app.outdir / '_static' / 'legacytmpl.html').exists()
assert (app.outdir / '_static' / 'legacytmpl.html').read_text(encoding='utf8') == (
'<!-- testing legacy _t static templates -->\n'
'<html><project>python</project></html>'
)
assert (app.outdir / '_static' / 'staticimg.png').exists()
assert (app.outdir / '_static' / 'statictmpl.html').exists()
assert (app.outdir / '_static' / 'statictmpl.html').read_text(encoding='utf8') == (

View File

@@ -3,7 +3,7 @@
from unittest import mock
from sphinx.jinja2glue import BuiltinTemplateLoader
from sphinx.util.fileutil import copy_asset, copy_asset_file
from sphinx.util.fileutil import _template_basename, copy_asset, copy_asset_file
class DummyTemplateLoader(BuiltinTemplateLoader):
@@ -101,3 +101,13 @@ def test_copy_asset(tmp_path):
assert not (destdir / '_static' / 'basic.css').exists()
assert (destdir / '_templates' / 'layout.html').exists()
assert not (destdir / '_templates' / 'sidebar.html').exists()
def test_template_basename():
assert _template_basename('asset.txt') is None
assert _template_basename('asset.txt.jinja') == 'asset.txt'
assert _template_basename('sidebar.html.jinja') == 'sidebar.html'
def test_legacy_template_basename():
assert _template_basename('asset.txt_t') == 'asset.txt'