summaryrefslogtreecommitdiff
path: root/pystache
diff options
context:
space:
mode:
authorChris Jerdonek <chris.jerdonek@gmail.com>2012-07-23 06:30:12 -0700
committerChris Jerdonek <chris.jerdonek@gmail.com>2012-07-23 06:30:12 -0700
commit06fa9e75aec3dc60ca589cd2b765075d4b053101 (patch)
tree597f7b494a1779a507cebb4a271f4728ee8535f4 /pystache
parent3d995628ec8cfce38f3746643d343bb246d150e1 (diff)
parenta111e91673bcc7c7ec765e6c92aa2395f7e5eafe (diff)
downloadpystache-06fa9e75aec3dc60ca589cd2b765075d4b053101.tar.gz
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!
Diffstat (limited to 'pystache')
-rw-r--r--pystache/loader.py20
-rw-r--r--pystache/locator.py7
2 files changed, 26 insertions, 1 deletions
diff --git a/pystache/loader.py b/pystache/loader.py
index 0fdadc5..fcbe488 100644
--- a/pystache/loader.py
+++ b/pystache/loader.py
@@ -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:
diff --git a/pystache/locator.py b/pystache/locator.py
index 2189cf2..9bb095a 100644
--- a/pystache/locator.py
+++ b/pystache/locator.py
@@ -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.