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
1b31b0dc
Commit
1b31b0dc
authored
Feb 21, 2011
by
Pieter van de Bruggen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding basic support for partials.
parent
bd24077a
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
2 deletions
+19
-2
pystache/template.py
+3
-1
pystache/view.py
+4
-0
tests/test_spec.py
+12
-1
No files found.
pystache/template.py
View file @
1b31b0dc
...
@@ -82,12 +82,14 @@ class Template(object):
...
@@ -82,12 +82,14 @@ class Template(object):
elif
captures
[
'tag'
]
==
'='
:
elif
captures
[
'tag'
]
==
'='
:
self
.
otag
,
self
.
ctag
=
captures
[
'name'
]
.
split
()
self
.
otag
,
self
.
ctag
=
captures
[
'name'
]
.
split
()
self
.
_compile_regexps
()
self
.
_compile_regexps
()
elif
captures
[
'tag'
]
==
'>'
:
buffer
+=
self
.
_parse
(
self
.
view
.
partial
(
captures
[
'name'
]))
elif
captures
[
'tag'
]
in
[
'{'
,
'&'
]:
elif
captures
[
'tag'
]
in
[
'{'
,
'&'
]:
buffer
.
append
(
lambda
view
:
unicode
(
fetch
(
view
)))
buffer
.
append
(
lambda
view
:
unicode
(
fetch
(
view
)))
elif
captures
[
'tag'
]
==
''
:
elif
captures
[
'tag'
]
==
''
:
buffer
.
append
(
lambda
view
:
cgi
.
escape
(
unicode
(
fetch
(
view
)),
True
))
buffer
.
append
(
lambda
view
:
cgi
.
escape
(
unicode
(
fetch
(
view
)),
True
))
else
:
else
:
raise
raise
Exception
(
"'
%
s' is an unrecognized type!"
%
(
captures
[
'tag'
]))
return
pos
return
pos
...
...
pystache/view.py
View file @
1b31b0dc
...
@@ -49,6 +49,10 @@ class View(object):
...
@@ -49,6 +49,10 @@ class View(object):
return
self
.
template
return
self
.
template
def
partial
(
self
,
name
):
from
pystache
import
Loader
return
Loader
()
.
load_template
(
name
,
self
.
template_path
,
encoding
=
self
.
template_encoding
,
extension
=
self
.
template_extension
)
def
_get_template_name
(
self
,
template_name
=
None
):
def
_get_template_name
(
self
,
template_name
=
None
):
"""TemplatePartial => template_partial
"""TemplatePartial => template_partial
Takes a string but defaults to using the current class' name or
Takes a string but defaults to using the current class' name or
...
...
tests/test_spec.py
View file @
1b31b0dc
import
glob
import
glob
import
os.path
import
os.path
import
pystache
import
pystache
from
pystache
import
Loader
import
unittest
import
unittest
import
yaml
import
yaml
...
@@ -19,10 +20,20 @@ class MustacheSpec(unittest.TestCase):
...
@@ -19,10 +20,20 @@ class MustacheSpec(unittest.TestCase):
def
buildTest
(
testData
,
spec
):
def
buildTest
(
testData
,
spec
):
def
test
(
self
):
def
test
(
self
):
template
=
testData
[
'template'
]
template
=
testData
[
'template'
]
partials
=
testData
.
has_key
(
'partials'
)
and
test
[
'partials'
]
or
{}
partials
=
testData
.
has_key
(
'partials'
)
and
test
Data
[
'partials'
]
or
{}
expected
=
testData
[
'expected'
]
expected
=
testData
[
'expected'
]
data
=
testData
[
'data'
]
data
=
testData
[
'data'
]
files
=
[]
try
:
for
key
in
partials
.
keys
():
filename
=
"
%
s.
%
s"
%
(
key
,
Loader
.
template_extension
)
files
.
append
(
os
.
path
.
join
(
Loader
.
template_path
,
filename
))
p
=
open
(
files
[
-
1
],
'w'
)
p
.
write
(
partials
[
key
])
self
.
assertEquals
(
pystache
.
render
(
template
,
data
),
expected
)
self
.
assertEquals
(
pystache
.
render
(
template
,
data
),
expected
)
finally
:
[
os
.
remove
(
f
)
for
f
in
files
]
test
.
__doc__
=
testData
[
'desc'
]
test
.
__doc__
=
testData
[
'desc'
]
test
.
__name__
=
'test
%
s (
%
s)'
%
(
testData
[
'name'
],
spec
)
test
.
__name__
=
'test
%
s (
%
s)'
%
(
testData
[
'name'
],
spec
)
...
...
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