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
b0e78f9a
Commit
b0e78f9a
authored
Dec 23, 2011
by
Chris Jerdonek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change Loader.load_template() to Loader.get().
parent
62d1264b
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
16 additions
and
17 deletions
+16
-17
pystache/commands.py
+1
-1
pystache/loader.py
+1
-1
pystache/renderer.py
+2
-3
pystache/view.py
+1
-1
tests/test_loader.py
+11
-11
No files found.
pystache/commands.py
View file @
b0e78f9a
...
@@ -55,7 +55,7 @@ def main(sys_argv):
...
@@ -55,7 +55,7 @@ def main(sys_argv):
template
=
template
[:
-
9
]
template
=
template
[:
-
9
]
try
:
try
:
template
=
Loader
()
.
load_template
(
template
)
template
=
Loader
()
.
get
(
template
)
except
IOError
:
except
IOError
:
pass
pass
...
...
pystache/loader.py
View file @
b0e78f9a
...
@@ -52,7 +52,7 @@ class Loader(object):
...
@@ -52,7 +52,7 @@ class Loader(object):
return
file_name
return
file_name
def
load_template
(
self
,
template_name
):
def
get
(
self
,
template_name
):
"""
"""
Find and load the given template, and return it as a string.
Find and load the given template, and return it as a string.
...
...
pystache/renderer.py
View file @
b0e78f9a
...
@@ -22,7 +22,6 @@ except ImportError:
...
@@ -22,7 +22,6 @@ except ImportError:
class
Renderer
(
object
):
class
Renderer
(
object
):
# TODO: change load_template to load_partial.
def
__init__
(
self
,
load_template
=
None
,
output_encoding
=
None
,
escape
=
None
,
def
__init__
(
self
,
load_template
=
None
,
output_encoding
=
None
,
escape
=
None
,
default_encoding
=
None
,
decode_errors
=
'strict'
):
default_encoding
=
None
,
decode_errors
=
'strict'
):
"""
"""
...
@@ -33,7 +32,7 @@ class Renderer(object):
...
@@ -33,7 +32,7 @@ class Renderer(object):
load_template: a function for loading templates by name, for
load_template: a function for loading templates by name, for
example when loading partials. The function should accept a
example when loading partials. The function should accept a
single template_name parameter and return a template as a string.
single template_name parameter and return a template as a string.
Defaults to the default Loader's
load_template
() method.
Defaults to the default Loader's
get
() method.
output_encoding: the encoding to use when rendering to a string.
output_encoding: the encoding to use when rendering to a string.
The argument should be the name of an encoding as a string, for
The argument should be the name of an encoding as a string, for
...
@@ -65,7 +64,7 @@ class Renderer(object):
...
@@ -65,7 +64,7 @@ class Renderer(object):
"""
"""
if
load_template
is
None
:
if
load_template
is
None
:
loader
=
Loader
()
loader
=
Loader
()
load_template
=
loader
.
load_template
load_template
=
loader
.
get
if
default_encoding
is
None
:
if
default_encoding
is
None
:
default_encoding
=
sys
.
getdefaultencoding
()
default_encoding
=
sys
.
getdefaultencoding
()
...
...
pystache/view.py
View file @
b0e78f9a
...
@@ -51,7 +51,7 @@ class View(object):
...
@@ -51,7 +51,7 @@ class View(object):
# View.__init__() has already been called.
# View.__init__() has already been called.
loader
=
Loader
(
search_dirs
=
self
.
template_path
,
encoding
=
self
.
template_encoding
,
loader
=
Loader
(
search_dirs
=
self
.
template_path
,
encoding
=
self
.
template_encoding
,
extension
=
self
.
template_extension
)
extension
=
self
.
template_extension
)
self
.
_load_template
=
loader
.
load_template
self
.
_load_template
=
loader
.
get
return
self
.
_load_template
(
template_name
)
return
self
.
_load_template
(
template_name
)
...
...
tests/test_loader.py
View file @
b0e78f9a
...
@@ -48,36 +48,36 @@ class LoaderTestCase(unittest.TestCase):
...
@@ -48,36 +48,36 @@ class LoaderTestCase(unittest.TestCase):
loader
.
template_extension
=
''
loader
.
template_extension
=
''
self
.
assertEquals
(
loader
.
make_file_name
(
'foo'
),
'foo.'
)
self
.
assertEquals
(
loader
.
make_file_name
(
'foo'
),
'foo.'
)
def
test_template_is_loaded
(
self
):
def
test_
get__
template_is_loaded
(
self
):
loader
=
Loader
(
search_dirs
=
'examples'
)
loader
=
Loader
(
search_dirs
=
'examples'
)
template
=
loader
.
load_template
(
'simple'
)
template
=
loader
.
get
(
'simple'
)
self
.
assertEqual
(
template
,
'Hi {{thing}}!{{blank}}'
)
self
.
assertEqual
(
template
,
'Hi {{thing}}!{{blank}}'
)
def
test_using_list_of_paths
(
self
):
def
test_
get__
using_list_of_paths
(
self
):
loader
=
Loader
(
search_dirs
=
[
'doesnt_exist'
,
'examples'
])
loader
=
Loader
(
search_dirs
=
[
'doesnt_exist'
,
'examples'
])
template
=
loader
.
load_template
(
'simple'
)
template
=
loader
.
get
(
'simple'
)
self
.
assertEqual
(
template
,
'Hi {{thing}}!{{blank}}'
)
self
.
assertEqual
(
template
,
'Hi {{thing}}!{{blank}}'
)
def
test_non_existent_template_fails
(
self
):
def
test_
get__
non_existent_template_fails
(
self
):
loader
=
Loader
()
loader
=
Loader
()
self
.
assertRaises
(
IOError
,
loader
.
load_template
,
'doesnt_exist'
)
self
.
assertRaises
(
IOError
,
loader
.
get
,
'doesnt_exist'
)
def
test_
load_template
__extensionless_file
(
self
):
def
test_
get
__extensionless_file
(
self
):
loader
=
Loader
(
search_dirs
=
self
.
search_dirs
)
loader
=
Loader
(
search_dirs
=
self
.
search_dirs
)
self
.
assertRaises
(
IOError
,
loader
.
load_template
,
'extensionless'
)
self
.
assertRaises
(
IOError
,
loader
.
get
,
'extensionless'
)
loader
.
template_extension
=
False
loader
.
template_extension
=
False
self
.
assertEquals
(
loader
.
load_template
(
'extensionless'
),
"No file extension: {{foo}}"
)
self
.
assertEquals
(
loader
.
get
(
'extensionless'
),
"No file extension: {{foo}}"
)
def
test_load_template__unicode_return_value
(
self
):
def
test_
get__
load_template__unicode_return_value
(
self
):
"""
"""
Check that load_template() returns unicode strings.
Check that load_template() returns unicode strings.
"""
"""
loader
=
Loader
(
search_dirs
=
self
.
search_dirs
)
loader
=
Loader
(
search_dirs
=
self
.
search_dirs
)
template
=
loader
.
load_template
(
'simple'
)
template
=
loader
.
get
(
'simple'
)
self
.
assertEqual
(
type
(
template
),
unicode
)
self
.
assertEqual
(
type
(
template
),
unicode
)
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