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
8eac16d8
Commit
8eac16d8
authored
Jan 27, 2011
by
Carl Whittaker
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding support for context nested on any flavoured object.
parent
c6f78bfd
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
7 deletions
+16
-7
pystache/template.py
+5
-2
tests/test_view.py
+11
-5
No files found.
pystache/template.py
View file @
8eac16d8
...
...
@@ -58,10 +58,9 @@ class Template(object):
section
,
section_name
,
inner
=
match
.
group
(
0
,
1
,
2
)
section_name
=
section_name
.
strip
()
it
=
self
.
view
.
get
(
section_name
,
None
)
replacer
=
''
# Callable
if
it
and
isinstance
(
it
,
collections
.
Callable
):
replacer
=
it
(
inner
)
...
...
@@ -73,6 +72,10 @@ class Template(object):
elif
it
and
hasattr
(
it
,
'__iter__'
):
if
section
[
2
]
!=
'^'
:
replacer
=
self
.
_render_list
(
inner
,
it
)
# Other objects
elif
it
and
isinstance
(
it
,
object
):
if
section
[
2
]
!=
'^'
:
replacer
=
self
.
_render_dictionary
(
inner
,
it
)
# Falsey and Negated or Truthy and Not Negated
elif
(
not
it
and
section
[
2
]
==
'^'
)
or
(
it
and
section
[
2
]
!=
'^'
):
replacer
=
inner
...
...
tests/test_view.py
View file @
8eac16d8
...
...
@@ -6,6 +6,9 @@ from examples.complex_view import ComplexView
from
examples.lambdas
import
Lambdas
from
examples.inverted
import
Inverted
class
Thing
(
object
):
pass
class
TestView
(
unittest
.
TestCase
):
def
test_basic
(
self
):
view
=
Simple
(
"Hi {{thing}}!"
,
{
'thing'
:
'world'
})
...
...
@@ -86,11 +89,14 @@ class TestView(unittest.TestCase):
view
=
Inverted
()
self
.
assertEquals
(
view
.
render
(),
"""one, two, three, empty list"""
)
# def test_accessing_properties_on_parent_view(self):
# view = Simple(context={'child':child})
# view.template = '{{#child}}{{#t}}{{thing}}{{/t}}{{/child}}'
#
# self.assertEquals(view.render(), 'pizza1')
def
test_accessing_properties_on_parent_object_from_child_objects
(
self
):
parent
=
Thing
()
parent
.
this
=
'derp'
parent
.
children
=
[
Thing
()]
view
=
Simple
(
context
=
{
'parent'
:
parent
})
view
.
template
=
"{{#parent}}{{#children}}{{this}}{{/children}}{{/parent}}"
self
.
assertEquals
(
view
.
render
(),
'derp'
)
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