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
e87e859f
Commit
e87e859f
authored
Apr 01, 2012
by
Chris Jerdonek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removed View class (finally!).
parent
49c1d7a9
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
25 additions
and
118 deletions
+25
-118
pystache/init.py
+1
-2
pystache/template_spec.py
+1
-2
pystache/view.py
+0
-82
tests/test_template_spec.py
+23
-32
No files found.
pystache/init.py
View file @
e87e859f
...
...
@@ -7,10 +7,9 @@ This module contains the initialization logic called by __init__.py.
from
.renderer
import
Renderer
from
.template_spec
import
TemplateSpec
from
.view
import
View
__all__
=
[
'render'
,
'Renderer'
,
'
View'
,
'
TemplateSpec'
]
__all__
=
[
'render'
,
'Renderer'
,
'TemplateSpec'
]
def
render
(
template
,
context
=
None
,
**
kwargs
):
...
...
pystache/template_spec.py
View file @
e87e859f
...
...
@@ -52,8 +52,7 @@ class TemplateSpec(object):
template_encoding
=
None
# TODO: add test cases for this class, and then refactor while replacing the
# View class.
# TODO: add test cases for this class.
class
SpecLoader
(
object
):
"""
...
...
pystache/view.py
deleted
100644 → 0
View file @
49c1d7a9
# coding: utf-8
"""
This module exposes the deprecated View class.
TODO: remove this module.
"""
from
.context
import
Context
from
.locator
import
Locator
from
.renderer
import
Renderer
from
.template_spec
import
TemplateSpec
# TODO: remove this class.
class
View
(
TemplateSpec
):
_renderer
=
None
locator
=
Locator
()
def
__init__
(
self
,
context
=
None
):
"""
Construct a View instance.
"""
context
=
Context
.
create
(
self
,
context
)
self
.
context
=
context
def
_get_renderer
(
self
):
if
self
.
_renderer
is
None
:
# We delay setting self._renderer until now (instead of, say,
# setting it in the constructor) in case the user changes after
# instantiation some of the attributes on which the Renderer
# depends. This lets users set the template_extension attribute,
# etc. after View.__init__() has already been called.
renderer
=
Renderer
(
file_encoding
=
self
.
template_encoding
,
search_dirs
=
self
.
template_path
,
file_extension
=
self
.
template_extension
)
self
.
_renderer
=
renderer
return
self
.
_renderer
def
get_template
(
self
):
"""
Return the current template after setting it, if necessary.
"""
if
not
self
.
template
:
template_name
=
self
.
_get_template_name
()
renderer
=
self
.
_get_renderer
()
self
.
template
=
renderer
.
load_template
(
template_name
)
return
self
.
template
def
_get_template_name
(
self
):
"""
Return the name of the template to load.
If the template_name attribute is not set, then this method constructs
the template name from the class name as follows, for example:
TemplatePartial => template_partial
Otherwise, this method returns the template_name.
"""
if
self
.
template_name
:
return
self
.
template_name
return
self
.
locator
.
make_template_name
(
self
)
def
render
(
self
):
"""
Return the view rendered using the current context.
"""
template
=
self
.
get_template
()
renderer
=
self
.
_get_renderer
()
return
renderer
.
render
(
template
,
self
.
context
)
tests/test_template_spec.py
View file @
e87e859f
...
...
@@ -14,9 +14,8 @@ from examples.simple import Simple
from
examples.complex
import
Complex
from
examples.lambdas
import
Lambdas
from
examples.inverted
import
Inverted
,
InvertedLists
from
pystache
import
TemplateSpec
as
Template
from
pystache
import
TemplateSpec
from
pystache
import
Renderer
from
pystache
import
View
from
pystache.template_spec
import
SpecLoader
from
pystache.locator
import
Locator
from
pystache.loader
import
Loader
...
...
@@ -34,46 +33,38 @@ class Thing(object):
class
ViewTestCase
(
unittest
.
TestCase
,
AssertStringMixin
):
def
test_
init
(
self
):
def
test_
template_rel_directory
(
self
):
"""
Test th
e constructor
.
Test th
at View.template_rel_directory is respected
.
"""
class
TestView
(
View
):
template
=
"foo"
view
=
TestView
()
self
.
assertEquals
(
view
.
template
,
"foo"
)
def
test_template_path
(
self
):
"""
Test that View.template_path is respected.
"""
class
Tagless
(
View
):
class
Tagless
(
TemplateSpec
):
pass
view
=
Tagless
()
self
.
assertRaises
(
IOError
,
view
.
render
)
renderer
=
Renderer
(
)
view
=
Tagless
()
view
.
template_path
=
"examples"
self
.
assertEquals
(
view
.
render
(),
"No tags..."
)
self
.
assertRaises
(
IOError
,
renderer
.
render
,
view
)
view
.
template_rel_directory
=
"../examples"
actual
=
renderer
.
render
(
view
)
self
.
assertEquals
(
actual
,
"No tags..."
)
def
test_template_path_for_partials
(
self
):
"""
Test that View.template_rel_path is respected for partials.
"""
class
TestView
(
View
):
template
=
"Partial: {{>tagless}}"
spec
=
TemplateSpec
()
spec
.
template
=
"Partial: {{>tagless}}"
renderer1
=
Renderer
()
renderer2
=
Renderer
(
search_dirs
=
EXAMPLES_DIR
)
view
=
TestView
()
self
.
assertRaises
(
IOError
,
view
.
render
)
self
.
assertRaises
(
IOError
,
renderer1
.
render
,
spec
)
view
=
TestView
()
view
.
template_path
=
"examples"
self
.
assertEquals
(
view
.
render
(),
"Partial: No tags..."
)
actual
=
renderer2
.
render
(
spec
)
self
.
assertEquals
(
actual
,
"Partial: No tags..."
)
def
test_basic_method_calls
(
self
):
renderer
=
Renderer
()
...
...
@@ -192,7 +183,7 @@ class SpecLoaderTests(unittest.TestCase, AssertIsMixin, AssertStringMixin):
Test the template attribute: str string.
"""
custom
=
Template
()
custom
=
Template
Spec
()
custom
.
template
=
"abc"
self
.
_assert_template
(
SpecLoader
(),
custom
,
u"abc"
)
...
...
@@ -202,7 +193,7 @@ class SpecLoaderTests(unittest.TestCase, AssertIsMixin, AssertStringMixin):
Test the template attribute: unicode string.
"""
custom
=
Template
()
custom
=
Template
Spec
()
custom
.
template
=
u"abc"
self
.
_assert_template
(
SpecLoader
(),
custom
,
u"abc"
)
...
...
@@ -212,7 +203,7 @@ class SpecLoaderTests(unittest.TestCase, AssertIsMixin, AssertStringMixin):
Test the template attribute: non-ascii unicode string.
"""
custom
=
Template
()
custom
=
Template
Spec
()
custom
.
template
=
u"é"
self
.
_assert_template
(
SpecLoader
(),
custom
,
u"é"
)
...
...
@@ -222,7 +213,7 @@ class SpecLoaderTests(unittest.TestCase, AssertIsMixin, AssertStringMixin):
Test the template attribute: with template encoding attribute.
"""
custom
=
Template
()
custom
=
Template
Spec
()
custom
.
template
=
u'é'
.
encode
(
'utf-8'
)
self
.
assertRaises
(
UnicodeDecodeError
,
self
.
_assert_template
,
SpecLoader
(),
custom
,
u'é'
)
...
...
@@ -257,7 +248,7 @@ class SpecLoaderTests(unittest.TestCase, AssertIsMixin, AssertStringMixin):
custom_loader
=
SpecLoader
()
custom_loader
.
loader
=
loader
view
=
Template
()
view
=
Template
Spec
()
view
.
template
=
"template-foo"
view
.
template_encoding
=
"encoding-foo"
...
...
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