Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: third_party/pystache/src/parsed.py

Issue 2962783004: Adding pystache to third_party (Closed)
Patch Set: Merge branch 'master' into mustache Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/pystache/src/locator.py ('k') | third_party/pystache/src/parser.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 # coding: utf-8
2
3 """
4 Exposes a class that represents a parsed (or compiled) template.
5
6 """
7
8
9 class ParsedTemplate(object):
10
11 """
12 Represents a parsed or compiled template.
13
14 An instance wraps a list of unicode strings and node objects. A node
15 object must have a `render(engine, stack)` method that accepts a
16 RenderEngine instance and a ContextStack instance and returns a unicode
17 string.
18
19 """
20
21 def __init__(self):
22 self._parse_tree = []
23
24 def __repr__(self):
25 return repr(self._parse_tree)
26
27 def add(self, node):
28 """
29 Arguments:
30
31 node: a unicode string or node object instance. See the class
32 docstring for information.
33
34 """
35 self._parse_tree.append(node)
36
37 def render(self, engine, context):
38 """
39 Returns: a string of type unicode.
40
41 """
42 # We avoid use of the ternary operator for Python 2.4 support.
43 def get_unicode(node):
44 if type(node) is unicode:
45 return node
46 return node.render(engine, context)
47 parts = map(get_unicode, self._parse_tree)
48 s = ''.join(parts)
49
50 return unicode(s)
OLDNEW
« no previous file with comments | « third_party/pystache/src/locator.py ('k') | third_party/pystache/src/parser.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698