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
c180cc76
Commit
c180cc76
authored
Dec 18, 2011
by
Chris Jerdonek
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'issue_40' into development: closing issue #40
parents
9b087b28
39875728
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
53 additions
and
3 deletions
+53
-3
HISTORY.rst
+1
-0
examples/extensionless
+2
-0
pystache/loader.py
+12
-1
tests/test_loader.py
+32
-2
tests/test_view.py
+6
-0
No files found.
HISTORY.rst
View file @
c180cc76
...
...
@@ -24,6 +24,7 @@ Bug fixes:
the mustache spec. [heliodor]
* Fixed an issue that affected the rendering of zeroes when using certain
implementations of Python (i.e. PyPy). [alex]
* Extensionless template files could not be loaded. [cjerdonek]
Misc:
...
...
examples/extensionless
0 → 100644
View file @
c180cc76
No file extension: {{foo}}
\ No newline at end of file
pystache/loader.py
View file @
c180cc76
...
...
@@ -22,6 +22,9 @@ class Loader(object):
search_dirs: the directories in which to search for templates.
Defaults to the current working directory.
extension: the template file extension. Defaults to "mustache".
Pass False for no extension.
"""
if
extension
is
None
:
extension
=
DEFAULT_EXTENSION
...
...
@@ -35,6 +38,13 @@ class Loader(object):
self
.
template_encoding
=
encoding
self
.
template_extension
=
extension
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
load_template
(
self
,
template_name
):
"""
Find and load the given template, and return it as a string.
...
...
@@ -43,7 +53,8 @@ class Loader(object):
"""
search_dirs
=
self
.
search_dirs
file_name
=
template_name
+
'.'
+
self
.
template_extension
file_name
=
self
.
make_file_name
(
template_name
)
for
dir_path
in
search_dirs
:
file_path
=
os
.
path
.
join
(
dir_path
,
file_name
)
...
...
tests/test_loader.py
View file @
c180cc76
...
...
@@ -6,6 +6,8 @@ from pystache.loader import Loader
class
LoaderTestCase
(
unittest
.
TestCase
):
search_dirs
=
'examples'
def
test_init
(
self
):
"""
Test the __init__() constructor.
...
...
@@ -14,13 +16,34 @@ class LoaderTestCase(unittest.TestCase):
loader
=
Loader
()
self
.
assertEquals
(
loader
.
search_dirs
,
[
os
.
curdir
])
self
.
assertTrue
(
loader
.
template_encoding
is
None
)
self
.
assertEquals
(
loader
.
template_extension
,
'mustache'
)
loader
=
Loader
(
search_dirs
=
[
'foo'
],
encoding
=
'utf-8'
,
extension
=
'txt'
)
loader
=
Loader
(
search_dirs
=
[
'foo'
],
encoding
=
'utf-8'
)
self
.
assertEquals
(
loader
.
search_dirs
,
[
'foo'
])
self
.
assertEquals
(
loader
.
template_encoding
,
'utf-8'
)
def
test_init__extension
(
self
):
# Test the default value.
loader
=
Loader
()
self
.
assertEquals
(
loader
.
template_extension
,
'mustache'
)
loader
=
Loader
(
extension
=
'txt'
)
self
.
assertEquals
(
loader
.
template_extension
,
'txt'
)
loader
=
Loader
(
extension
=
False
)
self
.
assertTrue
(
loader
.
template_extension
is
False
)
def
test_make_file_name
(
self
):
loader
=
Loader
()
loader
.
template_extension
=
'bar'
self
.
assertEquals
(
loader
.
make_file_name
(
'foo'
),
'foo.bar'
)
loader
.
template_extension
=
False
self
.
assertEquals
(
loader
.
make_file_name
(
'foo'
),
'foo'
)
loader
.
template_extension
=
''
self
.
assertEquals
(
loader
.
make_file_name
(
'foo'
),
'foo.'
)
def
test_template_is_loaded
(
self
):
loader
=
Loader
(
search_dirs
=
'examples'
)
template
=
loader
.
load_template
(
'simple'
)
...
...
@@ -37,3 +60,10 @@ class LoaderTestCase(unittest.TestCase):
loader
=
Loader
()
self
.
assertRaises
(
IOError
,
loader
.
load_template
,
'doesnt_exist'
)
def
test_load_template__extensionless_file
(
self
):
loader
=
Loader
(
search_dirs
=
self
.
search_dirs
)
self
.
assertRaises
(
IOError
,
loader
.
load_template
,
'extensionless'
)
loader
.
template_extension
=
False
self
.
assertEquals
(
loader
.
load_template
(
'extensionless'
),
"No file extension: {{foo}}"
)
tests/test_view.py
View file @
c180cc76
...
...
@@ -54,6 +54,12 @@ class ViewTestCase(unittest.TestCase):
template
=
Simple
()
.
load_template
(
"escaped"
)
self
.
assertEquals
(
template
,
"<h1>{{title}}</h1>"
)
def
test_load_template__extensionless_file
(
self
):
view
=
Simple
()
view
.
template_extension
=
False
template
=
view
.
load_template
(
'extensionless'
)
self
.
assertEquals
(
template
,
"No file extension: {{foo}}"
)
def
test_custom_load_template
(
self
):
"""
Test passing a custom load_template to View.__init__().
...
...
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