return out
-def render(config, template: str, page, env: jinja2.Environment):
+def render(*, config, template: str, url: str, filename: str, env: jinja2.Environment, **kwargs):
template = env.get_template(template)
- rendered = template.render(page=page,
- URL=page.url,
- SEARCHDATA_FORMAT_VERSION=searchdata_format_version, **config)
- with open(os.path.join(config['OUTPUT'], page.filename), 'wb') as f:
+ rendered = template.render(URL=url,
+ SEARCHDATA_FORMAT_VERSION=searchdata_format_version,
+ **config, **kwargs)
+ with open(os.path.join(config['OUTPUT'], filename), 'wb') as f:
f.write(rendered.encode('utf-8'))
# Add back a trailing newline so we don't need to bother with
# patching test files to include a trailing newline to make Git
result.name = path[-1]
state.search += [result]
- render(state.config, 'module.html', page, env)
+ render(config=state.config,
+ template='module.html',
+ filename=page.filename,
+ url=page.url,
+ env=env,
+ page=page)
# Call all scope exit hooks last
for hook in state.hooks_post_scope:
result.name = path[-1]
state.search += [result]
- render(state.config, 'class.html', page, env)
+ render(config=state.config,
+ template='class.html',
+ filename=page.filename,
+ url=page.url,
+ env=env,
+ page=page)
# Call all scope exit hooks last
for hook in state.hooks_post_scope:
result.name = path[-1]
state.search += [result]
- render(state.config, 'page.html', page, env)
+ render(config=state.config,
+ template='page.html',
+ filename=page.filename,
+ url=page.url,
+ env=env,
+ page=page)
def is_html_safe(string):
return '<' not in string and '>' not in string and '&' not in string and '"' not in string and '\'' not in string
index.classes = class_index
index.pages = page_index
for file in special_pages[1:]: # exclude index
- template = env.get_template(file + '.html')
filename, url = config['URL_FORMATTER'](EntryType.SPECIAL, [file])
- rendered = template.render(index=index, URL=url, **config)
- with open(os.path.join(config['OUTPUT'], filename), 'wb') as f:
- f.write(rendered.encode('utf-8'))
- # Add back a trailing newline so we don't need to bother with
- # patching test files to include a trailing newline to make Git
- # happy. Can't use keep_trailing_newline because that'd add it
- # also for nested templates :(
- f.write(b'\n')
+ render(config=config,
+ template=file + '.html',
+ filename=filename,
+ url=url,
+ env=env,
+ index=index)
# Create index.html if it was not provided by the user
if 'index.rst' not in [os.path.basename(i) for i in config['INPUT_PAGES']]:
page.filename = filename
page.url = url
page.breadcrumb = [(config['PROJECT_TITLE'], url)]
- render(config, 'page.html', page, env)
+ render(config=config,
+ template='page.html',
+ filename=page.filename,
+ url=page.url,
+ env=env,
+ page=page)
if not state.config['SEARCH_DISABLED']:
logging.debug("building search data for {} symbols".format(len(state.search)))