Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
pystache_custom
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
pystache_custom
Commits
89dd6059
Commit
89dd6059
authored
Dec 10, 2011
by
Chris Jerdonek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removed the Template.template_path instance attribute.
Also simplified the Template.load_template() method.
parent
16aaa7f8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
15 deletions
+16
-15
pystache/loader.py
+14
-14
tests/test_loader.py
+2
-1
No files found.
pystache/loader.py
View file @
89dd6059
...
...
@@ -10,15 +10,23 @@ import os
class
Loader
(
object
):
template_path
=
os
.
curdir
# i.e. "."
def
__init__
(
self
,
search_dirs
=
None
,
encoding
=
None
,
extension
=
None
):
"""
Construct a template loader.
Arguments:
search_dirs: the directories in which to search for templates.
Defaults to the current working directory.
"""
if
extension
is
None
:
extension
=
'mustache'
if
search_dirs
is
None
:
search_dirs
=
os
.
curdir
# i.e. "."
if
isinstance
(
search_dirs
,
basestring
):
search_dirs
=
[
search_dirs
]
self
.
search_dirs
=
search_dirs
self
.
template_encoding
=
encoding
...
...
@@ -31,24 +39,16 @@ class Loader(object):
Raises an IOError if the template cannot be found.
"""
template_dirs
=
self
.
search_dirs
or
self
.
template_path
search_dirs
=
self
.
search_dirs
file_name
=
template_name
+
'.'
+
self
.
template_extension
# Given a single directory, we'll load from it.
if
isinstance
(
template_dirs
,
basestring
):
file_path
=
os
.
path
.
join
(
template_dirs
,
file_name
)
return
self
.
_load_template_file
(
file_path
)
# Given a list of directories, we'll check each for our file.
for
path
in
template_dirs
:
file_path
=
os
.
path
.
join
(
path
,
file_name
)
for
dir_path
in
search_dirs
:
file_path
=
os
.
path
.
join
(
dir_path
,
file_name
)
if
os
.
path
.
exists
(
file_path
):
return
self
.
_load_template_file
(
file_path
)
# TODO: we should probably raise an exception of our own type.
raise
IOError
(
'"
%
s" not found in "
%
s"'
%
(
template_name
,
':'
.
join
(
template
_dirs
),))
raise
IOError
(
'"
%
s" not found in "
%
s"'
%
(
template_name
,
':'
.
join
(
search
_dirs
),))
def
_load_template_file
(
self
,
file_path
):
"""
...
...
tests/test_loader.py
View file @
89dd6059
import
os
import
unittest
from
pystache.loader
import
Loader
...
...
@@ -11,7 +12,7 @@ class LoaderTestCase(unittest.TestCase):
"""
loader
=
Loader
()
self
.
assert
True
(
loader
.
search_dirs
is
None
)
self
.
assert
Equals
(
loader
.
search_dirs
,
[
os
.
curdir
]
)
self
.
assertTrue
(
loader
.
template_encoding
is
None
)
self
.
assertEquals
(
loader
.
template_extension
,
'mustache'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment