mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Add support for templated static files.
This commit is contained in:
parent
67242fd375
commit
2f18cc9885
@ -350,7 +350,14 @@ class TemplateBridge(object):
|
|||||||
|
|
||||||
def render(self, template, context):
|
def render(self, template, context):
|
||||||
"""
|
"""
|
||||||
Called by the builder to render a *template* with a specified
|
Called by the builder to render a template given as a filename with a
|
||||||
context (a Python dictionary).
|
specified context (a Python dictionary).
|
||||||
|
"""
|
||||||
|
raise NotImplementedError('must be implemented in subclasses')
|
||||||
|
|
||||||
|
def render_string(self, template, context):
|
||||||
|
"""
|
||||||
|
Called by the builder to render a template given as a string with a
|
||||||
|
specified context (a Python dictionary).
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError('must be implemented in subclasses')
|
raise NotImplementedError('must be implemented in subclasses')
|
||||||
|
@ -460,7 +460,16 @@ class StandaloneHTMLBuilder(Builder):
|
|||||||
fullname = path.join(staticdirname, filename)
|
fullname = path.join(staticdirname, filename)
|
||||||
targetname = path.join(self.outdir, '_static', filename)
|
targetname = path.join(self.outdir, '_static', filename)
|
||||||
if path.isfile(fullname):
|
if path.isfile(fullname):
|
||||||
shutil.copyfile(fullname, targetname)
|
if fullname.lower().endswith('_t'):
|
||||||
|
# templated!
|
||||||
|
fsrc = open(fullname, 'rb')
|
||||||
|
fdst = open(targetname[:-2], 'wb')
|
||||||
|
fdst.write(self.templates.render_string(
|
||||||
|
fsrc.read(), self.globalcontext))
|
||||||
|
fsrc.close()
|
||||||
|
fdst.close()
|
||||||
|
else:
|
||||||
|
shutil.copyfile(fullname, targetname)
|
||||||
elif path.isdir(fullname):
|
elif path.isdir(fullname):
|
||||||
if filename in self.config.exclude_dirnames:
|
if filename in self.config.exclude_dirnames:
|
||||||
continue
|
continue
|
||||||
|
@ -44,6 +44,7 @@ class BuiltinTemplateLoader(TemplateBridge, jinja2.BaseLoader):
|
|||||||
chain[0:0] = [path.join(builder.confdir, tp)
|
chain[0:0] = [path.join(builder.confdir, tp)
|
||||||
for tp in builder.config.templates_path]
|
for tp in builder.config.templates_path]
|
||||||
|
|
||||||
|
# store it for use in newest_template_mtime
|
||||||
self.pathchain = chain
|
self.pathchain = chain
|
||||||
|
|
||||||
# make the paths into loaders
|
# make the paths into loaders
|
||||||
@ -60,6 +61,9 @@ class BuiltinTemplateLoader(TemplateBridge, jinja2.BaseLoader):
|
|||||||
def render(self, template, context):
|
def render(self, template, context):
|
||||||
return self.environment.get_template(template).render(context)
|
return self.environment.get_template(template).render(context)
|
||||||
|
|
||||||
|
def render_string(self, source, context):
|
||||||
|
return self.environment.from_string(source).render(context)
|
||||||
|
|
||||||
def newest_template_mtime(self):
|
def newest_template_mtime(self):
|
||||||
return max(mtimes_of_files(self.pathchain, '.html'))
|
return max(mtimes_of_files(self.pathchain, '.html'))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user