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
4a4b4ddc
Commit
4a4b4ddc
authored
May 04, 2012
by
Chris Jerdonek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplified Renderer._make_resolve_partial().
parent
bc2ca04c
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
28 deletions
+29
-28
pystache/renderer.py
+29
-28
No files found.
pystache/renderer.py
View file @
4a4b4ddc
...
...
@@ -232,47 +232,48 @@ class Renderer(object):
return
load_template
# TODO: simplify this method.
def
_make_resolve_partial
(
self
):
def
_make_load_partial
(
self
):
"""
Return
the resolve_partial function to pass to RenderEngine.__init__()
.
Return
a function that loads a partial by name
.
"""
if
self
.
partials
is
None
:
load_template
=
self
.
_make_load_template
()
return
self
.
_make_load_template
()
if
self
.
missing_tags
==
MissingTags
.
strict
:
return
load_template
# Otherwise, ignore missing tags.
# Otherwise, create a function from the custom partial loader.
partials
=
self
.
partials
def
resolve_partial
(
name
):
try
:
return
load_template
(
name
)
except
TemplateNotFoundError
:
return
u''
def
load_partial
(
name
):
# TODO: consider using EAFP here instead.
# http://docs.python.org/glossary.html#term-eafp
# This would mean requiring that the custom partial loader
# raise a KeyError on name not found.
template
=
partials
.
get
(
name
)
if
template
is
None
:
raise
TemplateNotFoundError
(
"Name
%
s not found in partials:
%
s"
%
(
repr
(
name
),
type
(
partials
)))
return
resolve_partial
# RenderEngine requires that the return value be unicode.
return
self
.
_to_unicode_hard
(
template
)
# Otherwise, create a resolve_partial function from the custom partial
# loader that satisfies RenderEngine requirements (and that provides
# a nicer exception, etc).
partials
=
self
.
partials
return
load_partial
def
_make_resolve_partial
(
self
):
"""
Return the resolve_partial function to pass to RenderEngine.__init__().
"""
load_partial
=
self
.
_make_load_partial
()
if
self
.
missing_tags
==
MissingTags
.
strict
:
def
on_template_none
(
name
,
partials
):
raise
TemplateNotFoundError
(
"Name
%
s not found in partials:
%
s"
%
(
repr
(
name
),
type
(
partials
)))
else
:
return
load_partial
# Otherwise, ignore missing tags.
on_template_none
=
lambda
name
,
partials
:
u''
def
resolve_partial
(
name
):
template
=
partials
.
get
(
name
)
if
template
is
None
:
return
on_template_none
(
name
,
partials
)
# RenderEngine requires that the return value be unicode.
return
self
.
_to_unicode_hard
(
template
)
try
:
return
load_partial
(
name
)
except
TemplateNotFoundError
:
return
u''
return
resolve_partial
...
...
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