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
43cc3d1f
Commit
43cc3d1f
authored
Jan 24, 2012
by
Chris Jerdonek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Finished implementing and testing view.Locator.get_relative_template_location().
parent
008198b5
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
77 additions
and
17 deletions
+77
-17
pystache/view.py
+33
-6
tests/test_view.py
+44
-11
No files found.
pystache/view.py
View file @
43cc3d1f
...
...
@@ -15,12 +15,34 @@ from .renderer import Renderer
# TODO: rename this class to something else (e.g. ITemplateInfo)
class
View
(
object
):
template_name
=
None
template_path
=
None
"""
Subclass this class only if template customizations are needed.
The following attributes allow one to customize/override template
information on a per View basis. A None value means to use default
behavior and perform no customization. All attributes are initially
set to None.
Attributes:
template: the template to use, as a unicode string.
template_path: the path to the template file, relative to the
directory containing the module defining the class.
template_extension: the template file extension. Defaults to "mustache".
Pass False for no extension (i.e. extensionless template files).
"""
template
=
None
template_encoding
=
None
template_path
=
None
template_name
=
None
template_extension
=
None
template_encoding
=
None
_renderer
=
None
locator
=
TemplateLocator
()
...
...
@@ -120,7 +142,6 @@ class Locator(object):
self
.
search_dirs
=
search_dirs
self
.
template_locator
=
template_locator
# TODO: unit test
def
get_relative_template_location
(
self
,
view
):
"""
Return the relative template path as a (dir, file_name) pair.
...
...
@@ -128,10 +149,14 @@ class Locator(object):
"""
if
view
.
template_path
is
not
None
:
return
os
.
path
.
split
(
view
.
template_path
)
# Otherwise, we don't know the directory.
template_name
=
(
view
.
template_name
if
view
.
template_name
is
not
None
else
self
.
template_locator
.
make_template_name
(
view
))
file_name
=
self
.
template_locator
.
make_file_name
(
template_name
,
view
.
template_extension
)
# TODO: finish this
return
(
None
,
None
)
return
(
None
,
file_name
)
def
get_template_path
(
self
,
view
):
"""
...
...
@@ -155,8 +180,10 @@ class Locator(object):
"""
if
view
.
template
is
not
None
:
# TODO: unit test rendering with a non-unicode value for this attribute.
return
view
.
template
path
=
self
.
get_template_path
(
view
)
# TODO: add support for encoding.
return
self
.
reader
.
read
(
path
)
tests/test_view.py
View file @
43cc3d1f
...
...
@@ -193,21 +193,54 @@ class LocatorTests(unittest.TestCase, AssertIsMixin):
self
.
assertIs
(
locator
.
reader
,
reader
)
# TODO: make this test real
def
test_get_relative_template_location__template_path__file_name
(
self
):
def
_assert_template_location
(
self
,
view
,
expected
):
locator
=
self
.
_make_locator
()
view
=
View
()
actual
=
locator
.
get_relative_template_location
(
view
)
self
.
assertEquals
(
actual
,
expected
)
view
.
template_path
=
'foo.txt'
self
.
assertEquals
(
locator
.
get_relative_template_location
(
view
),
(
''
,
'foo.txt'
))
def
test_get_relative_template_location
(
self
):
"""
Test get_relative_template_location(): default behavior (no attributes set).
# TODO: make this test real
def
test_get_relative_template_location__template_path__full_path
(
self
):
locator
=
self
.
_make_locator
()
view
=
View
()
"""
view
=
SampleView
()
self
.
_assert_template_location
(
view
,
(
None
,
'sample_view.mustache'
))
def
test_get_relative_template_location__template_path__file_name_only
(
self
):
"""
Test get_relative_template_location(): template_path attribute.
"""
view
=
SampleView
()
view
.
template_path
=
'template.txt'
self
.
_assert_template_location
(
view
,
(
''
,
'template.txt'
))
def
test_get_relative_template_location__template_path__file_name_with_directory
(
self
):
"""
Test get_relative_template_location(): template_path attribute.
"""
view
=
SampleView
()
view
.
template_path
=
'foo/bar/template.txt'
self
.
_assert_template_location
(
view
,
(
'foo/bar'
,
'template.txt'
))
view
.
template_path
=
'foo.txt'
self
.
assertEquals
(
locator
.
get_relative_template_location
(
view
),
(
''
,
'foo.txt'
))
def
test_get_relative_template_location__template_name
(
self
):
"""
Test get_relative_template_location(): template_name attribute.
"""
view
=
SampleView
()
view
.
template_name
=
'new_name'
self
.
_assert_template_location
(
view
,
(
None
,
'new_name.mustache'
))
def
test_get_relative_template_location__template_extension
(
self
):
"""
Test get_relative_template_location(): template_extension attribute.
"""
view
=
SampleView
()
view
.
template_extension
=
'txt'
self
.
_assert_template_location
(
view
,
(
None
,
'sample_view.txt'
))
def
test_get_template_path__with_directory
(
self
):
"""
...
...
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