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
41c92afc
Commit
41c92afc
authored
Feb 15, 2011
by
Pieter van de Bruggen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactoring the match handling logic.
parent
50bdc535
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
34 deletions
+39
-34
pystache/template.py
+39
-34
No files found.
pystache/template.py
View file @
41c92afc
...
...
@@ -43,46 +43,51 @@ class Template(object):
if
match
is
None
:
break
# Normalize the captures dictionary.
captures
=
match
.
groupdict
()
if
captures
[
'change'
]
is
not
None
:
captures
.
update
(
tag
=
'='
,
name
=
captures
[
'delims'
])
elif
captures
[
'raw'
]
is
not
None
:
captures
.
update
(
tag
=
'{'
,
name
=
captures
[
'raw_name'
])
# Save the literal text content.
buffer
.
append
(
captures
[
'content'
])
pos
=
match
.
end
()
# Standalone (non-interpolation) tags consume the entire line,
# both leading whitespace and trailing newline.
tagBeganLine
=
(
not
buffer
[
-
1
]
or
buffer
[
-
1
][
-
1
]
==
'
\n
'
)
tagEndedLine
=
(
pos
==
len
(
template
)
or
template
[
pos
]
==
'
\n
'
)
interpolationTag
=
captures
[
'tag'
]
in
[
''
,
'&'
,
'{'
]
if
(
tagBeganLine
and
tagEndedLine
and
not
interpolationTag
):
pos
+=
1
elif
captures
[
'whitespace'
]:
buffer
.
append
(
captures
[
'whitespace'
])
captures
[
'whitespace'
]
=
''
# TODO: Process the remaining tag types.
if
captures
[
'tag'
]
==
'!'
:
pass
elif
captures
[
'tag'
]
in
[
'{'
,
'&'
]:
def
unescapedTag
(
view
):
return
view
.
get
(
captures
[
'name'
])
buffer
.
append
(
unescapedTag
)
elif
captures
[
'tag'
]
==
''
:
def
escapedTag
(
view
):
return
cgi
.
escape
(
view
.
get
(
captures
[
'name'
]))
buffer
.
append
(
escapedTag
)
pos
=
self
.
_handle_match
(
template
,
match
,
buffer
)
# Save the rest of the template.
buffer
.
append
(
template
[
pos
:])
return
buffer
def
_handle_match
(
self
,
template
,
match
,
buffer
):
# Normalize the captures dictionary.
captures
=
match
.
groupdict
()
if
captures
[
'change'
]
is
not
None
:
captures
.
update
(
tag
=
'='
,
name
=
captures
[
'delims'
])
elif
captures
[
'raw'
]
is
not
None
:
captures
.
update
(
tag
=
'{'
,
name
=
captures
[
'raw_name'
])
# Save the literal text content.
buffer
.
append
(
captures
[
'content'
])
pos
=
match
.
end
()
# Standalone (non-interpolation) tags consume the entire line,
# both leading whitespace and trailing newline.
tagBeganLine
=
(
not
buffer
[
-
1
]
or
buffer
[
-
1
][
-
1
]
==
'
\n
'
)
tagEndedLine
=
(
pos
==
len
(
template
)
or
template
[
pos
]
==
'
\n
'
)
interpolationTag
=
captures
[
'tag'
]
in
[
''
,
'&'
,
'{'
]
if
(
tagBeganLine
and
tagEndedLine
and
not
interpolationTag
):
pos
+=
1
elif
captures
[
'whitespace'
]:
buffer
.
append
(
captures
[
'whitespace'
])
captures
[
'whitespace'
]
=
''
# TODO: Process the remaining tag types.
print
captures
[
'name'
]
fetch
=
lambda
view
:
unicode
(
view
.
get
(
captures
[
'name'
]))
if
captures
[
'tag'
]
==
'!'
:
pass
elif
captures
[
'tag'
]
in
[
'{'
,
'&'
]:
buffer
.
append
(
fetch
)
elif
captures
[
'tag'
]
==
''
:
buffer
.
append
(
lambda
view
:
cgi
.
escape
(
fetch
(
view
),
True
))
else
:
print
'Error!'
return
pos
def
render
(
self
,
encoding
=
None
):
parsed
=
self
.
_parse
(
self
.
template
)
...
...
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