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
7826ec7f
Commit
7826ec7f
authored
Jan 01, 2012
by
Chris Jerdonek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merged Template class into RenderEngine.
parent
c7007a70
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
33 deletions
+11
-33
pystache/renderengine.py
+11
-33
No files found.
pystache/renderengine.py
View file @
7826ec7f
...
...
@@ -100,7 +100,9 @@ class RenderEngine(object):
unicode subclasses (e.g. markupsafe.Markup).
"""
tag_re
=
None
otag
=
'{{'
ctag
=
'}}'
...
...
@@ -155,18 +157,7 @@ class RenderEngine(object):
# don't use self.literal).
template
=
unicode
(
template
)
_template
=
Template
()
_template
.
to_unicode
=
self
.
literal
_template
.
escape
=
self
.
escape
_template
.
get_partial
=
self
.
load_partial
return
_template
.
render_template
(
template
=
template
,
context
=
context
)
class
Template
(
object
):
tag_re
=
None
otag
,
ctag
=
'{{'
,
'}}'
return
self
.
render_template
(
template
=
template
,
context
=
context
)
def
_compile_regexps
(
self
):
...
...
@@ -193,15 +184,6 @@ class Template(object):
self
.
tag_re
=
re
.
compile
(
tag
,
re
.
M
|
re
.
X
)
def
to_unicode
(
self
,
text
):
return
unicode
(
text
)
def
escape
(
self
,
text
):
return
cgi
.
escape
(
text
,
True
)
def
get_partial
(
self
,
name
):
pass
def
_get_string_value
(
self
,
context
,
tag_name
):
"""
Get a value from the given context as a basestring instance.
...
...
@@ -231,7 +213,7 @@ class Template(object):
# In case the template is an integer, for example.
template
=
str
(
template
)
if
type
(
template
)
is
not
unicode
:
template
=
self
.
to_unicode
(
template
)
template
=
self
.
literal
(
template
)
val
=
self
.
render_template
(
template
,
context
)
if
not
isinstance
(
val
,
basestring
):
...
...
@@ -250,7 +232,7 @@ class Template(object):
def
literal_tag_function
(
self
,
name
):
def
func
(
context
):
s
=
self
.
_get_string_value
(
context
,
name
)
s
=
self
.
to_unicode
(
s
)
s
=
self
.
literal
(
s
)
return
s
return
func
...
...
@@ -258,7 +240,7 @@ class Template(object):
def
partial_tag_function
(
self
,
name
,
indentation
=
''
):
def
func
(
context
):
nonblank
=
re
.
compile
(
r'^(.)'
,
re
.
M
)
template
=
self
.
get
_partial
(
name
)
template
=
self
.
load
_partial
(
name
)
# Indent before rendering.
template
=
re
.
sub
(
nonblank
,
indentation
+
r'\1'
,
template
)
return
self
.
render_template
(
template
,
context
)
...
...
@@ -290,18 +272,14 @@ class Template(object):
def
parse_string_to_tree
(
self
,
template_string
,
delims
=
(
'{{'
,
'}}'
)):
template
=
Template
()
template
.
otag
=
delims
[
0
]
template
.
ctag
=
delims
[
1
]
engine
=
RenderEngine
(
load_partial
=
self
.
load_partial
,
literal
=
self
.
literal
,
escape
=
self
.
escape
)
template
.
escape
=
self
.
escape
template
.
get_partial
=
self
.
get_partial
template
.
to_unicode
=
self
.
to_unicode
engine
.
otag
=
delims
[
0
]
engine
.
ctag
=
delims
[
1
]
templat
e
.
_compile_regexps
()
engin
e
.
_compile_regexps
()
return
templat
e
.
parse_to_tree
(
template
=
template_string
)
return
engin
e
.
parse_to_tree
(
template
=
template_string
)
def
parse_to_tree
(
self
,
template
,
index
=
0
):
"""
...
...
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