Browse Source

Added ability to iterate over an expando

main
Lakshmi Vyasarajan 14 years ago
parent
commit
5136969f92
2 changed files with 22 additions and 6 deletions
  1. +15
    -6
      hyde/ext/templates/jinja.py
  2. +7
    -0
      hyde/model.py

+ 15
- 6
hyde/ext/templates/jinja.py View File

@@ -266,8 +266,12 @@ class Refer(Extension):
includeNode.template = template

return [
nodes.Assign(nodes.Name(MARKINGS, 'store'), nodes.Const({})).set_lineno(lineno),
nodes.Assign(nodes.Name(namespace, 'store'), nodes.Const({})).set_lineno(lineno),
nodes.Assign(
nodes.Name(MARKINGS, 'store'),
nodes.Const({})).set_lineno(lineno),
nodes.Assign(
nodes.Name(namespace, 'store'),
nodes.Const({})).set_lineno(lineno),
nodes.CallBlock(
self.call_method('_push_resource',
args=[
@@ -276,8 +280,11 @@ class Refer(Extension):
nodes.Name('resource', 'load'),
template]),
[], [], []).set_lineno(lineno),
nodes.Assign(nodes.Name('resource', 'store'),
nodes.Getitem(nodes.Name(namespace, 'load'), nodes.Const('current_resource'), 'load')).set_lineno(lineno),
nodes.Assign(
nodes.Name('resource', 'store'),
nodes.Getitem(nodes.Name(namespace, 'load'),
nodes.Const('resource'), 'load')
).set_lineno(lineno),
nodes.CallBlock(
self.call_method('_assign_reference',
args=[
@@ -285,12 +292,14 @@ class Refer(Extension):
nodes.Name(namespace, 'load')]),
[], [], [includeNode]).set_lineno(lineno),
nodes.Assign(nodes.Name('resource', 'store'),
nodes.Getitem(nodes.Name(namespace, 'load'), nodes.Const('parent_resource'), 'load')).set_lineno(lineno),
nodes.Getitem(nodes.Name(namespace, 'load'),
nodes.Const('parent_resource'), 'load')
).set_lineno(lineno),
]

def _push_resource(self, namespace, site, resource, template, caller):
namespace['parent_resource'] = resource
namespace['current_resource'] = site.content.resource_from_relative_path(template)
namespace['resource'] = site.content.resource_from_relative_path(template)
return ''

def _assign_reference(self, markings, namespace, caller):


+ 7
- 0
hyde/model.py View File

@@ -19,6 +19,13 @@ class Expando(object):
super(Expando, self).__init__()
self.update(d)

def __iter__(self):
"""
Returns an iterator for all the items in the
dictionary as key value pairs.
"""
return self.__dict__.iteritems()

def update(self, d):
"""
Updates the expando with a new dictionary


Loading…
Cancel
Save