pystache.locator module

This module provides a Locator class for finding template files.

class pystache.locator.Locator(extension=None)[source]

Bases: object

find_file(file_name, search_dirs)[source]

Return the path to a template with the given file name.

Arguments:

file_name: the file name of the template.

search_dirs: the list of directories in which to search.

find_name(template_name, search_dirs)[source]

Return the path to a template with the given name.

Arguments:

template_name: the name of the template.

search_dirs: the list of directories in which to search.

find_object(obj, search_dirs, file_name=None)[source]

Return the path to a template associated with the given object.

get_object_directory(obj)[source]

Return the directory containing an object’s defining class.

Returns None if there is no such directory, for example if the class was defined in an interactive Python session, or in a doctest that appears in a text file (rather than a Python file).

make_file_name(template_name, template_extension=None)[source]

Generate and return the file name for the given template name.

Arguments:

template_extension: defaults to the instance’s extension.

make_template_name(obj)[source]

Return the canonical template name for an object instance.

This method converts Python-style class names (PEP 8’s recommended CamelCase, aka CapWords) to lower_case_with_underscords. Here is an example with code:

>>> class HelloWorld(object):
...     pass
>>> hi = HelloWorld()
>>>
>>> locator = Locator()
>>> locator.make_template_name(hi)
'hello_world'