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
ed2c5521
Commit
ed2c5521
authored
Mar 28, 2012
by
Chris Jerdonek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Divided Loader.load() into load_name() and load_object().
parent
80dd7698
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
12 deletions
+26
-12
pystache/loader.py
+24
-10
pystache/renderer.py
+2
-2
No files found.
pystache/loader.py
View file @
ed2c5521
...
...
@@ -50,6 +50,7 @@ class Loader(object):
self
.
encoding
=
encoding
self
.
extension
=
extension
# TODO: eliminate redundancy with the Renderer class's unicode code.
def
unicode
(
self
,
s
,
encoding
=
None
):
"""
Call Python's built-in function unicode(), and return the result.
...
...
@@ -80,25 +81,38 @@ class Loader(object):
return
self
.
unicode
(
text
,
encoding
)
def
load
(
self
,
obj
,
search_dirs
):
# TODO: unit-test this method.
def
load_name
(
self
,
name
,
search_dirs
):
"""
Find and return the template with the given name.
Arguments:
name: the name of the template.
search_dirs: the list of directories in which to search.
"""
locator
=
Locator
(
extension
=
self
.
extension
)
path
=
locator
.
find_path_by_name
(
search_dirs
,
name
)
return
self
.
read
(
path
)
# TODO: unit-test this method.
def
load_object
(
self
,
obj
,
search_dirs
):
"""
Find and return the template associated to the given object.
Arguments:
obj: a string or object instance. If obj is a string, then obj
will be interpreted as the template name. Otherwise, obj will
be interpreted as an instance of a user-defined class.
obj: an instance of a user-defined class.
search_dirs: the list of directories in which to search for
templates when loading a template by name.
search_dirs: the list of directories in which to search.
"""
locator
=
Locator
(
extension
=
self
.
extension
)
if
isinstance
(
obj
,
basestring
):
path
=
locator
.
find_path_by_name
(
search_dirs
,
obj
)
else
:
path
=
locator
.
find_path_by_object
(
search_dirs
,
obj
)
path
=
locator
.
find_path_by_object
(
search_dirs
,
obj
)
return
self
.
read
(
path
)
pystache/renderer.py
View file @
ed2c5521
...
...
@@ -185,7 +185,7 @@ class Renderer(object):
loader
=
self
.
_make_loader
()
def
load_template
(
template_name
):
return
loader
.
load
(
template_name
,
self
.
search_dirs
)
return
loader
.
load
_name
(
template_name
,
self
.
search_dirs
)
return
load_template
...
...
@@ -258,7 +258,7 @@ class Renderer(object):
"""
loader
=
self
.
_make_loader
()
template
=
loader
.
load
(
obj
,
self
.
search_dirs
)
template
=
loader
.
load
_object
(
obj
,
self
.
search_dirs
)
context
=
[
obj
]
+
list
(
context
)
...
...
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