Commit 06fa9e75 by Chris Jerdonek

Merge pull request #127 from @xgecko into issue-127

From: https://github.com/xgecko/pystache/commit/a111e91673bcc7c7ec765e6c92aa2395f7e5eafe

This request adds support for loading and locating template files
by file name rather than template name.

Thanks @xgecko!
parents 3d995628 a111e916
......@@ -120,9 +120,27 @@ class Loader(object):
return self.unicode(b, encoding)
# TODO: unit-test this method.
def load_file(self, file_name):
"""
Find and return the 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.
"""
locator = self._make_locator()
path = locator.find_file(file_name, self.search_dirs)
return self.read(path)
# TODO: unit-test this method.
def load_name(self, name):
"""
Find and return the template with the given name.
Find and return the template with the given template name.
Arguments:
......
......@@ -123,6 +123,13 @@ class Locator(object):
return path
def find_file(self, template_file, search_dirs):
"""
Return the path to a template with the given file name.
"""
return self._find_path_required(search_dirs, template_file)
def find_name(self, template_name, search_dirs):
"""
Return the path to a template with the given name.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment