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
423db900
Commit
423db900
authored
Apr 01, 2012
by
Chris Jerdonek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
The Renderer class now passes search_dirs to Loader via the constructor.
parent
00fa136b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
12 deletions
+21
-12
pystache/loader.py
+16
-7
pystache/renderer.py
+5
-5
No files found.
pystache/loader.py
View file @
423db900
...
@@ -31,7 +31,8 @@ class Loader(object):
...
@@ -31,7 +31,8 @@ class Loader(object):
"""
"""
def
__init__
(
self
,
file_encoding
=
None
,
extension
=
None
,
to_unicode
=
None
):
def
__init__
(
self
,
file_encoding
=
None
,
extension
=
None
,
to_unicode
=
None
,
search_dirs
=
None
):
"""
"""
Construct a template loader instance.
Construct a template loader instance.
...
@@ -44,6 +45,9 @@ class Loader(object):
...
@@ -44,6 +45,9 @@ class Loader(object):
file_encoding: the name of the encoding to use when converting file
file_encoding: the name of the encoding to use when converting file
contents to unicode. Defaults to the package default.
contents to unicode. Defaults to the package default.
search_dirs: the list of directories in which to search when loading
a template by name or file name. Defaults to the package default.
to_unicode: the function to use when converting strings of type
to_unicode: the function to use when converting strings of type
str to unicode. The function should have the signature:
str to unicode. The function should have the signature:
...
@@ -61,11 +65,16 @@ class Loader(object):
...
@@ -61,11 +65,16 @@ class Loader(object):
if
file_encoding
is
None
:
if
file_encoding
is
None
:
file_encoding
=
defaults
.
FILE_ENCODING
file_encoding
=
defaults
.
FILE_ENCODING
if
search_dirs
is
None
:
search_dirs
=
defaults
.
SEARCH_DIRS
if
to_unicode
is
None
:
if
to_unicode
is
None
:
to_unicode
=
_to_unicode
to_unicode
=
_to_unicode
self
.
extension
=
extension
self
.
extension
=
extension
self
.
file_encoding
=
file_encoding
self
.
file_encoding
=
file_encoding
# TODO: unit test setting this attribute.
self
.
search_dirs
=
search_dirs
self
.
to_unicode
=
to_unicode
self
.
to_unicode
=
to_unicode
def
_make_locator
(
self
):
def
_make_locator
(
self
):
...
@@ -107,9 +116,8 @@ class Loader(object):
...
@@ -107,9 +116,8 @@ class Loader(object):
return
self
.
unicode
(
text
,
encoding
)
return
self
.
unicode
(
text
,
encoding
)
# TODO: consider passing search_dirs in the constructor.
# TODO: unit-test this method.
# TODO: unit-test this method.
def
load_name
(
self
,
name
,
search_dirs
):
def
load_name
(
self
,
name
):
"""
"""
Find and return the template with the given name.
Find and return the template with the given name.
...
@@ -122,13 +130,13 @@ class Loader(object):
...
@@ -122,13 +130,13 @@ class Loader(object):
"""
"""
locator
=
self
.
_make_locator
()
locator
=
self
.
_make_locator
()
path
=
locator
.
find_name
(
search_dirs
,
name
)
# TODO: change the order of these arguments.
path
=
locator
.
find_name
(
self
.
search_dirs
,
name
)
return
self
.
read
(
path
)
return
self
.
read
(
path
)
# TODO: consider passing search_dirs in the constructor.
# TODO: unit-test this method.
# TODO: unit-test this method.
def
load_object
(
self
,
obj
,
search_dirs
):
def
load_object
(
self
,
obj
):
"""
"""
Find and return the template associated to the given object.
Find and return the template associated to the given object.
...
@@ -141,6 +149,7 @@ class Loader(object):
...
@@ -141,6 +149,7 @@ class Loader(object):
"""
"""
locator
=
self
.
_make_locator
()
locator
=
self
.
_make_locator
()
path
=
locator
.
find_object
(
search_dirs
,
obj
)
# TODO: change the order of these arguments.
path
=
locator
.
find_object
(
self
.
search_dirs
,
obj
)
return
self
.
read
(
path
)
return
self
.
read
(
path
)
pystache/renderer.py
View file @
423db900
...
@@ -76,8 +76,8 @@ class Renderer(object):
...
@@ -76,8 +76,8 @@ class Renderer(object):
extension (i.e. to use extensionless template files).
extension (i.e. to use extensionless template files).
Defaults to the package default.
Defaults to the package default.
search_dirs: the list of directories in which to search
for
search_dirs: the list of directories in which to search
when
templates when loading a template by
name. If given a string,
loading a template by name or file
name. If given a string,
the method interprets the string as a single directory.
the method interprets the string as a single directory.
Defaults to the package default.
Defaults to the package default.
...
@@ -167,7 +167,7 @@ class Renderer(object):
...
@@ -167,7 +167,7 @@ class Renderer(object):
"""
"""
return
Loader
(
file_encoding
=
self
.
file_encoding
,
extension
=
self
.
file_extension
,
return
Loader
(
file_encoding
=
self
.
file_encoding
,
extension
=
self
.
file_extension
,
to_unicode
=
self
.
unicode
)
to_unicode
=
self
.
unicode
,
search_dirs
=
self
.
search_dirs
)
def
_make_load_template
(
self
):
def
_make_load_template
(
self
):
"""
"""
...
@@ -177,7 +177,7 @@ class Renderer(object):
...
@@ -177,7 +177,7 @@ class Renderer(object):
loader
=
self
.
_make_loader
()
loader
=
self
.
_make_loader
()
def
load_template
(
template_name
):
def
load_template
(
template_name
):
return
loader
.
load_name
(
template_name
,
self
.
search_dirs
)
return
loader
.
load_name
(
template_name
)
return
load_template
return
load_template
...
@@ -250,7 +250,7 @@ class Renderer(object):
...
@@ -250,7 +250,7 @@ class Renderer(object):
"""
"""
loader
=
self
.
_make_loader
()
loader
=
self
.
_make_loader
()
template
=
loader
.
load_object
(
obj
,
self
.
search_dirs
)
template
=
loader
.
load_object
(
obj
)
context
=
[
obj
]
+
list
(
context
)
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