From ae68dc1a863d3562ea85de9616c1b212aaa5ee77 Mon Sep 17 00:00:00 2001 From: xgecko Date: Fri, 20 Jul 2012 13:03:26 -0700 Subject: Updated to not append template_extension if it is already there. --- pystache/locator.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'pystache') diff --git a/pystache/locator.py b/pystache/locator.py index 2189cf2..6ffc951 100644 --- a/pystache/locator.py +++ b/pystache/locator.py @@ -92,7 +92,8 @@ class Locator(object): template_extension = self.template_extension if template_extension is not False: - file_name += os.path.extsep + template_extension + if not file_name.endswith(template_extension): + file_name += os.path.extsep + template_extension return file_name -- cgit v1.2.1 From 131c403be4c8d18ad353319497b55901c6e719e9 Mon Sep 17 00:00:00 2001 From: xgecko Date: Fri, 20 Jul 2012 16:11:17 -0700 Subject: Condensed nested if statements --- pystache/locator.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'pystache') diff --git a/pystache/locator.py b/pystache/locator.py index 6ffc951..04260bd 100644 --- a/pystache/locator.py +++ b/pystache/locator.py @@ -91,9 +91,8 @@ class Locator(object): if template_extension is None: template_extension = self.template_extension - if template_extension is not False: - if not file_name.endswith(template_extension): - file_name += os.path.extsep + template_extension + if template_extension is not False and not file_name.endswith(template_extension): + file_name += os.path.extsep + template_extension return file_name -- cgit v1.2.1 From 2b07ad52a45fb109c981dd505f63eade84be8558 Mon Sep 17 00:00:00 2001 From: xgecko Date: Sat, 21 Jul 2012 17:44:53 -0700 Subject: Added load_file function --- pystache/loader.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'pystache') diff --git a/pystache/loader.py b/pystache/loader.py index 0fdadc5..fcbe488 100644 --- a/pystache/loader.py +++ b/pystache/loader.py @@ -119,10 +119,28 @@ 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: -- cgit v1.2.1 From a111e91673bcc7c7ec765e6c92aa2395f7e5eafe Mon Sep 17 00:00:00 2001 From: xgecko Date: Sat, 21 Jul 2012 17:46:50 -0700 Subject: Added find_file function, and remove extension check logic from make_file_name --- pystache/locator.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'pystache') diff --git a/pystache/locator.py b/pystache/locator.py index 04260bd..9bb095a 100644 --- a/pystache/locator.py +++ b/pystache/locator.py @@ -91,7 +91,7 @@ class Locator(object): if template_extension is None: template_extension = self.template_extension - if template_extension is not False and not file_name.endswith(template_extension): + if template_extension is not False: file_name += os.path.extsep + template_extension return file_name @@ -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. -- cgit v1.2.1