diff options
Diffstat (limited to 'pystache/parsed.py')
-rw-r--r-- | pystache/parsed.py | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/pystache/parsed.py b/pystache/parsed.py index e94c644..372d96c 100644 --- a/pystache/parsed.py +++ b/pystache/parsed.py @@ -8,6 +8,16 @@ Exposes a class that represents a parsed (or compiled) template. class ParsedTemplate(object): + """ + Represents a parsed or compiled template. + + An instance wraps a list of unicode strings and node objects. A node + object must have a `render(engine, stack)` method that accepts a + RenderEngine instance and a ContextStack instance and returns a unicode + string. + + """ + def __init__(self): self._parse_tree = [] @@ -18,10 +28,8 @@ class ParsedTemplate(object): """ Arguments: - node: a unicode string or node object instance. A node object - instance must have a `render(engine, stack)` method that - accepts a RenderEngine instance and a ContextStack instance and - returns a unicode string. + node: a unicode string or node object instance. See the class + docstring for information. """ self._parse_tree.append(node) @@ -32,10 +40,10 @@ class ParsedTemplate(object): """ # We avoid use of the ternary operator for Python 2.4 support. - def get_unicode(val): - if type(val) is unicode: - return val - return val.render(engine, context) + def get_unicode(node): + if type(node) is unicode: + return node + return node.render(engine, context) parts = map(get_unicode, self._parse_tree) s = ''.join(parts) |