class documentation

class TemplateLookup: (source)

Constructor: TemplateLookup(path)

View In Hierarchy

The TemplateLookup handles the HTML template files locations. A little bit like mako.lookup.TemplateLookup but more simple.

The location of the files depends wether the users set a template directory with the option --template-dir and/or with the option --theme, any files in a template directory will be loaded.

This object allow the customization of any templates.

For HTML templates, this can lead to warnings when upgrading pydoctor, then, please update your template from our repo.

See Also
Template, StaticTemplate, HtmlTemplate
Notes
The HTML templates versions are independent of the pydoctor version and are idependent from each other.
Template operations are case insensitive.
Method __init__ Loads all templates from the given path into the lookup.
Method add_template Add a template to the lookup. The custom template override the default.
Method add_templatedir Scan a directory and add all templates in the given directory to the lookup.
Method get_loader Lookup a HTML template loader based on its filename.
Method get_template Lookup a template based on its filename.
Property templates All templates that can be looked up. For each name, the custom template will be included if it exists, otherwise the default template.
Method _add_overriding_html_template Undocumented
Method _raise_if_overrides_directory Undocumented
Instance Variable _templates Undocumented
def __init__(self, path: Traversable | Path): (source)

Loads all templates from the given path into the lookup.

Parameters
path:Traversable | PathA Path or Traversable object pointing to a directory to load the default set of templates from.
def add_template(self, template: Template): (source)

Add a template to the lookup. The custom template override the default.

If the file doesn't already exist in the lookup, we assume it is additional data used by the custom template.

For HTML, compare the new Template version with the currently loaded template, issue warnings if template are outdated.

Raises
UnsupportedTemplateVersionIf the custom template is designed for a newer version of pydoctor.
OverrideTemplateNotAllowedIf this template path overrides a path of a different type (HTML/static/directory).
def add_templatedir(self, path: Path | Traversable): (source)

Scan a directory and add all templates in the given directory to the lookup.

def get_loader(self, filename: str) -> ITemplateLoader: (source)

Lookup a HTML template loader based on its filename.

Raises
ValueErrorIf the template is not an HTML file.
def get_template(self, filename: str) -> Template: (source)

Lookup a template based on its filename.

Return the custom template if provided, else the default template.

Parameters
filename:strFile name, (ie 'index.html')
Returns
TemplateThe Template object
Raises
KeyErrorIf no template file is found with the given name

All templates that can be looked up. For each name, the custom template will be included if it exists, otherwise the default template.

def _add_overriding_html_template(self, template: HtmlTemplate, current_template: HtmlTemplate): (source)

Undocumented

def _raise_if_overrides_directory(self, template_name: str): (source)

Undocumented