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
3f119240
Commit
3f119240
authored
Jan 23, 2012
by
Chris Jerdonek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reordered and renamed some methods in locator.Locator.
parent
9202ce23
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
25 deletions
+29
-25
pystache/locator.py
+25
-25
pystache/view.py
+4
-0
No files found.
pystache/locator.py
View file @
3f119240
...
...
@@ -30,20 +30,6 @@ class Locator(object):
self
.
template_extension
=
extension
def
_find_path
(
self
,
file_name
,
search_dirs
):
"""
Search for the given file, and return the path.
Returns None if the file is not found.
"""
for
dir_path
in
search_dirs
:
file_path
=
os
.
path
.
join
(
dir_path
,
file_name
)
if
os
.
path
.
exists
(
file_path
):
return
file_path
return
None
def
get_object_directory
(
self
,
obj
):
"""
Return the directory containing an object's defining class.
...
...
@@ -66,13 +52,6 @@ class Locator(object):
return
os
.
path
.
dirname
(
path
)
def
make_file_name
(
self
,
template_name
):
file_name
=
template_name
if
self
.
template_extension
is
not
False
:
file_name
+=
os
.
path
.
extsep
+
self
.
template_extension
return
file_name
def
make_template_name
(
self
,
obj
):
"""
Return the canonical template name for an object instance.
...
...
@@ -97,12 +76,33 @@ class Locator(object):
return
re
.
sub
(
'[A-Z]'
,
repl
,
template_name
)[
1
:]
def
_find_path_by_file_name
(
self
,
search_dirs
,
file_name
):
def
make_file_name
(
self
,
template_name
):
file_name
=
template_name
if
self
.
template_extension
is
not
False
:
file_name
+=
os
.
path
.
extsep
+
self
.
template_extension
return
file_name
def
_find_path
(
self
,
search_dirs
,
file_name
):
"""
Search for the given file, and return the path.
Returns None if the file is not found.
"""
for
dir_path
in
search_dirs
:
file_path
=
os
.
path
.
join
(
dir_path
,
file_name
)
if
os
.
path
.
exists
(
file_path
):
return
file_path
return
None
def
_find_path_required
(
self
,
search_dirs
,
file_name
):
"""
Return the path to a template with the given file name.
"""
path
=
self
.
_find_path
(
file_name
,
search_dirs
)
path
=
self
.
_find_path
(
search_dirs
,
file_name
)
if
path
is
None
:
# TODO: we should probably raise an exception of our own type.
...
...
@@ -118,7 +118,7 @@ class Locator(object):
"""
file_name
=
self
.
make_file_name
(
template_name
)
return
self
.
_find_path_
by_file_name
(
search_dirs
,
file_name
)
return
self
.
_find_path_
required
(
search_dirs
,
file_name
)
def
find_path_by_object
(
self
,
search_dirs
,
obj
,
file_name
=
None
):
"""
...
...
@@ -135,6 +135,6 @@ class Locator(object):
if
dir_path
is
not
None
:
search_dirs
=
[
dir_path
]
+
search_dirs
path
=
self
.
_find_path_
by_file_name
(
search_dirs
,
file_name
)
path
=
self
.
_find_path_
required
(
search_dirs
,
file_name
)
return
path
pystache/view.py
View file @
3f119240
...
...
@@ -150,6 +150,10 @@ class Locator(object):
return
path
def
get_template
(
self
,
view
):
"""
Return the unicode template string associated with a view.
"""
if
view
.
template
is
not
None
:
return
view
.
template
...
...
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