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
9c0b9291
Commit
9c0b9291
authored
May 01, 2010
by
David Logie
Committed by
Chris Wanstrath
May 04, 2010
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Inverted sections.
parent
830f9fd9
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
24 additions
and
1 deletions
+24
-1
examples/inverted.mustache
+2
-0
examples/inverted.py
+13
-0
pystache/template.py
+4
-1
tests/test_view.py
+5
-0
No files found.
examples/inverted.mustache
0 → 100644
View file @
9c0b9291
{{^
f
}}
one
{{/
f
}}
,
{{
two
}}
,
{{^
f
}}
three
{{/
f
}}{{^
t
}}
, four!
{{/
t
}}
\ No newline at end of file
examples/inverted.py
0 → 100644
View file @
9c0b9291
import
pystache
class
Inverted
(
pystache
.
View
):
template_path
=
'examples'
def
t
(
self
):
return
True
def
f
(
self
):
return
False
def
two
(
self
):
return
'two'
pystache/template.py
View file @
9c0b9291
...
...
@@ -49,7 +49,7 @@ class Template(object):
"""Compiles our section and tag regular expressions."""
tags
=
{
'otag'
:
re
.
escape
(
self
.
otag
),
'ctag'
:
re
.
escape
(
self
.
ctag
)
}
section
=
r"
%(otag)
s
\#
([^\}]*)
%(ctag)
s\s*(.+?)\s*
%(otag)
s/\1
%(ctag)
s"
section
=
r"
%(otag)
s
[\#|^]
([^\}]*)
%(ctag)
s\s*(.+?)\s*
%(otag)
s/\1
%(ctag)
s"
self
.
section_re
=
re
.
compile
(
section
%
tags
,
re
.
M
|
re
.
S
)
tag
=
r"
%(otag)
s(#|=|&|!|>|\{)?(.+?)\1?
%(ctag)
s+"
...
...
@@ -70,12 +70,15 @@ class Template(object):
if
it
and
hasattr
(
it
,
'__call__'
):
replacer
=
it
(
inner
)
elif
it
and
not
hasattr
(
it
,
'__iter__'
):
if
section
[
2
]
!=
'^'
:
replacer
=
inner
elif
it
:
insides
=
[]
for
item
in
it
:
insides
.
append
(
self
.
render
(
inner
,
item
))
replacer
=
''
.
join
(
insides
)
elif
not
it
and
section
[
2
]
==
'^'
:
replacer
=
inner
template
=
template
.
replace
(
section
,
replacer
)
...
...
tests/test_view.py
View file @
9c0b9291
...
...
@@ -4,6 +4,7 @@ import pystache
from
examples.simple
import
Simple
from
examples.complex_view
import
ComplexView
from
examples.lambdas
import
Lambdas
from
examples.inverted
import
Inverted
class
TestView
(
unittest
.
TestCase
):
def
test_basic
(
self
):
...
...
@@ -75,6 +76,10 @@ class TestView(unittest.TestCase):
view
.
template
=
'{{#sort}}zyxwvutsrqponmlkjihgfedcba{{/sort}}'
self
.
assertEquals
(
view
.
render
(),
'abcdefghijklmnopqrstuvwxyz'
)
def
test_inverted
(
self
):
view
=
Inverted
()
self
.
assertEquals
(
view
.
render
(),
"""one, two, three"""
)
if
__name__
==
'__main__'
:
unittest
.
main
()
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