Commit a6559835 by Chris Jerdonek

Added a constructor to the Loader class.

The constructor accepts search_dirs, template_encoding, and template_extension.
parent 3c83ed33
......@@ -10,9 +10,19 @@ import os
class Loader(object):
template_extension = 'mustache'
template_path = '.'
template_encoding = None
def __init__(self, search_dirs=None, template_encoding=None, template_extension=None):
"""
Construct a template loader.
"""
if template_extension is None:
template_extension = 'mustache'
self.search_dirs = search_dirs
self.template_encoding = template_encoding
self.template_extension = template_extension
def load_template(self, template_name, template_dirs=None, encoding=None, extension=None):
"""
......@@ -21,8 +31,8 @@ class Loader(object):
Raises an IOError if the template cannot be found.
"""
if None == template_dirs:
template_dirs = self.template_path
if template_dirs is None:
template_dirs = self.search_dirs or self.template_path
if encoding is not None:
self.template_encoding = encoding
......
......@@ -5,6 +5,21 @@ from pystache.loader import Loader
class LoaderTestCase(unittest.TestCase):
def test_init(self):
"""
Test the __init__() constructor.
"""
loader = Loader()
self.assertTrue(loader.search_dirs is None)
self.assertTrue(loader.template_encoding is None)
self.assertEquals(loader.template_extension, 'mustache')
loader = Loader(search_dirs=['foo'], template_encoding='utf-8', template_extension='txt')
self.assertEquals(loader.search_dirs, ['foo'])
self.assertEquals(loader.template_encoding, 'utf-8')
self.assertEquals(loader.template_extension, 'txt')
def test_template_is_loaded(self):
loader = Loader()
template = loader.load_template('simple', 'examples')
......
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