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
47f24b4e
Commit
47f24b4e
authored
Jan 01, 2012
by
Chris Jerdonek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Deleted no-longer-used methods from RenderEngine.
parent
1979c2bb
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
0 additions
and
169 deletions
+0
-169
pystache/renderengine.py
+0
-169
No files found.
pystache/renderengine.py
View file @
47f24b4e
...
@@ -163,175 +163,6 @@ class RenderEngine(object):
...
@@ -163,175 +163,6 @@ class RenderEngine(object):
return
_template
.
render_template
(
template
=
template
,
context
=
context
)
return
_template
.
render_template
(
template
=
template
,
context
=
context
)
def
_compile_regexps
(
self
):
"""
Compile and set the regular expression attributes.
This method uses the current values for the otag and ctag attributes.
"""
tags
=
{
'otag'
:
re
.
escape
(
self
.
otag
),
'ctag'
:
re
.
escape
(
self
.
ctag
)
}
# The section contents include white space to comply with the spec's
# requirement that sections not alter surrounding whitespace.
section
=
r"
%(otag)
s([#|^])([^\}]*)
%(ctag)
s(.+?)
%(otag)
s/\2
%(ctag)
s"
%
tags
self
.
section_re
=
re
.
compile
(
section
,
re
.
M
|
re
.
S
)
tag
=
r"
%(otag)
s(#|=|&|!|>|\{)?(.+?)\1?
%(ctag)
s+"
%
tags
# We use re.DOTALL to permit multiline comments, in accordance with the spec.
self
.
tag_re
=
re
.
compile
(
tag
,
re
.
DOTALL
)
def
_render_tags
(
self
,
template
):
output
=
[]
while
True
:
parts
=
self
.
tag_re
.
split
(
template
,
maxsplit
=
1
)
output
.
append
(
parts
[
0
])
if
len
(
parts
)
<
2
:
# Then there was no match.
break
tag_type
,
tag_name
,
template
=
parts
[
1
:]
tag_name
=
tag_name
.
strip
()
func
=
self
.
modifiers
[
tag_type
]
tag_value
=
func
(
self
,
tag_name
)
# Appending the tag value to the output prevents treating the
# value as a template string (bug: issue #44).
output
.
append
(
tag_value
)
output
=
""
.
join
(
output
)
return
output
def
_render_dictionary
(
self
,
template
,
context
):
self
.
context
.
push
(
context
)
out
=
self
.
_render
(
template
)
self
.
context
.
pop
()
return
out
def
_render_list
(
self
,
template
,
listing
):
insides
=
[]
for
item
in
listing
:
insides
.
append
(
self
.
_render_dictionary
(
template
,
item
))
return
''
.
join
(
insides
)
def
_get_string_context
(
self
,
tag_name
):
"""
Get a value from the current context as a basestring instance.
"""
val
=
self
.
context
.
get
(
tag_name
)
# We use "==" rather than "is" to compare integers, as using "is"
# relies on an implementation detail of CPython. The test about
# rendering zeroes failed while using PyPy when using "is".
# See issue #34: https://github.com/defunkt/pystache/issues/34
if
not
val
and
val
!=
0
:
if
tag_name
!=
'.'
:
return
''
val
=
self
.
context
.
top
()
if
not
isinstance
(
val
,
basestring
):
val
=
str
(
val
)
return
val
def
_render_escaped
(
self
,
tag_name
):
"""
Return a variable value as an escaped unicode string.
"""
s
=
self
.
_get_string_context
(
tag_name
)
return
self
.
escape
(
s
)
def
_render_literal
(
self
,
tag_name
):
"""
Return a variable value as a unicode string (unescaped).
"""
s
=
self
.
_get_string_context
(
tag_name
)
return
self
.
literal
(
s
)
def
_render_comment
(
self
,
tag_name
):
return
''
def
_render_partial
(
self
,
template_name
):
template
=
self
.
load_partial
(
template_name
)
return
self
.
_render
(
template
)
def
_change_delimiter
(
self
,
tag_name
):
"""
Change the current delimiter.
"""
self
.
otag
,
self
.
ctag
=
tag_name
.
split
(
' '
)
self
.
_compile_regexps
()
return
''
def
_render
(
self
,
template
):
"""
Arguments:
template: a template string with type unicode.
"""
output
=
[]
while
True
:
parts
=
self
.
section_re
.
split
(
template
,
maxsplit
=
1
)
start
=
self
.
_render_tags
(
parts
[
0
])
output
.
append
(
start
)
if
len
(
parts
)
<
2
:
# Then there was no match.
break
section_type
,
section_key
,
section_contents
,
template
=
parts
[
1
:]
section_key
=
section_key
.
strip
()
section_value
=
self
.
context
.
get
(
section_key
,
None
)
rendered
=
''
# Callable
if
section_value
and
check_callable
(
section_value
):
rendered
=
section_value
(
section_contents
)
# Dictionary
elif
section_value
and
hasattr
(
section_value
,
'keys'
)
and
hasattr
(
section_value
,
'__getitem__'
):
if
section_type
!=
'^'
:
rendered
=
self
.
_render_dictionary
(
section_contents
,
section_value
)
# Lists
elif
section_value
and
hasattr
(
section_value
,
'__iter__'
):
if
section_type
!=
'^'
:
rendered
=
self
.
_render_list
(
section_contents
,
section_value
)
# Other objects
elif
section_value
and
isinstance
(
section_value
,
object
):
if
section_type
!=
'^'
:
rendered
=
self
.
_render_dictionary
(
section_contents
,
section_value
)
# Falsey and Negated or Truthy and Not Negated
elif
(
not
section_value
and
section_type
==
'^'
)
or
(
section_value
and
section_type
!=
'^'
):
rendered
=
self
.
_render_dictionary
(
section_contents
,
section_value
)
# Render template prior to section too
output
.
append
(
rendered
)
output
=
""
.
join
(
output
)
return
output
class
Template
(
object
):
class
Template
(
object
):
tag_re
=
None
tag_re
=
None
...
...
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