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
708d6fb0
Commit
708d6fb0
authored
Dec 29, 2011
by
Chris Jerdonek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Stubbed out Renderer.get_associated_template() method.
parent
5d2fe4f2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
7 deletions
+27
-7
pystache/renderer.py
+27
-7
No files found.
pystache/renderer.py
View file @
708d6fb0
...
@@ -255,6 +255,16 @@ class Renderer(object):
...
@@ -255,6 +255,16 @@ class Renderer(object):
load_template
=
self
.
_make_load_template
()
load_template
=
self
.
_make_load_template
()
return
load_template
(
template_name
)
return
load_template
(
template_name
)
def
get_associated_template
(
self
,
obj
):
"""
Find and return the template associated with an object.
TODO: document this.
"""
# TODO: implement this.
raise
NotImplementedError
()
def
_render_string
(
self
,
template
,
*
context
,
**
kwargs
):
def
_render_string
(
self
,
template
,
*
context
,
**
kwargs
):
"""
"""
Render the given template string using the given context.
Render the given template string using the given context.
...
@@ -282,16 +292,22 @@ class Renderer(object):
...
@@ -282,16 +292,22 @@ class Renderer(object):
def
render
(
self
,
template
,
*
context
,
**
kwargs
):
def
render
(
self
,
template
,
*
context
,
**
kwargs
):
"""
"""
Render the given template using the given context.
Render the given template (or templated object) using the given context.
Returns the rendering as a unicode string.
Returns a unicode string.
Prior to rendering, templates of type str are converted to unicode
using the default_encoding and decode_errors attributes. See the
constructor docstring for more information.
Arguments:
Arguments:
template: a template string that is either unicode or of type str.
template: a template string of type unicode or str, or an object
If the string has type str, it is first converted to unicode
instance. If the argument is an object, the function attempts
using this instance's default_encoding and decode_errors
to find a template associated to the object by calling the
attributes. See the constructor docstring for more information.
get_associated_template() method. The object is also used as
the first element of the context stack when rendering this
associated template.
*context: zero or more dictionaries, Context instances, or objects
*context: zero or more dictionaries, Context instances, or objects
with which to populate the initial context stack. None
with which to populate the initial context stack. None
...
@@ -305,5 +321,9 @@ class Renderer(object):
...
@@ -305,5 +321,9 @@ class Renderer(object):
all items in the *context list.
all items in the *context list.
"""
"""
return
self
.
_render_string
(
template
,
*
context
,
**
kwargs
)
if
not
isinstance
(
template
,
basestring
):
# Then we assume the template is an object instance.
context
=
[
template
]
+
list
(
context
)
template
=
self
.
get_associated_template
(
template
)
return
self
.
_render_string
(
template
,
*
context
,
**
kwargs
)
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