Skip to content

Commit

Permalink
Minor tweaks to the SpecLoader class.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjerdonek committed Apr 1, 2012
1 parent aabb1c6 commit d26bdf3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
32 changes: 16 additions & 16 deletions pystache/template_spec.py
Expand Up @@ -141,27 +141,28 @@ def __init__(self, search_dirs=None, loader=None):
self.loader = loader
self.search_dirs = search_dirs

def _find_relative(self, view):
def _find_relative(self, spec):
"""
Return the relative template path as a (dir, file_name) pair.
Return the path to the template as a relative (dir, file_name) pair.
"""
if view.template_rel_path is not None:
return os.path.split(view.template_rel_path)

template_dir = view.template_rel_directory
The directory returned is relative to the directory containing the
class definition of the given object. The method returns None for
this directory if the directory is unknown without first searching
the search directories.
# Otherwise, we don't know the directory.
"""
if spec.template_rel_path is not None:
return os.path.split(spec.template_rel_path)

# TODO: share code with the loader attribute here.
locator = Locator(extension=self.loader.extension)
# Otherwise, determine the file name separately.
locator = self.loader._make_locator()

template_name = (view.template_name if view.template_name is not None else
locator.make_template_name(view))
template_name = (spec.template_name if spec.template_name is not None else
locator.make_template_name(spec))

file_name = locator.make_file_name(template_name, view.template_extension)
file_name = locator.make_file_name(template_name, spec.template_extension)

return (template_dir, file_name)
return (spec.template_rel_directory, file_name)

def _find(self, spec):
"""
Expand All @@ -170,8 +171,7 @@ def _find(self, spec):
"""
dir_path, file_name = self._find_relative(spec)

# TODO: share code with the loader attribute here.
locator = Locator(extension=self.loader.extension)
locator = self.loader._make_locator()

if dir_path is None:
# Then we need to search for the path.
Expand Down
2 changes: 1 addition & 1 deletion tests/test_template_spec.py
@@ -1,7 +1,7 @@
# coding: utf-8

"""
Unit tests of view.py.
Unit tests for template_spec.py.
"""

Expand Down

0 comments on commit d26bdf3

Please sign in to comment.