Show More
@@ -40,24 +40,25 class _hybrid(object): | |||
|
40 | 40 | raise AttributeError(name) |
|
41 | 41 | return getattr(self.values, name) |
|
42 | 42 | |
|
43 | def showlist(name, values, plural=None, element=None, **args): | |
|
43 | def showlist(name, values, plural=None, element=None, separator=' ', **args): | |
|
44 | 44 | if not element: |
|
45 | 45 | element = name |
|
46 | f = _showlist(name, values, plural, **args) | |
|
46 | f = _showlist(name, values, plural, separator, **args) | |
|
47 | 47 | return _hybrid(f, values, lambda x: {element: x}) |
|
48 | 48 | |
|
49 | def _showlist(name, values, plural=None, **args): | |
|
49 | def _showlist(name, values, plural=None, separator=' ', **args): | |
|
50 | 50 | '''expand set of values. |
|
51 | 51 | name is name of key in template map. |
|
52 | 52 | values is list of strings or dicts. |
|
53 | 53 | plural is plural of name, if not simply name + 's'. |
|
54 | separator is used to join values as a string | |
|
54 | 55 | |
|
55 | 56 | expansion works like this, given name 'foo'. |
|
56 | 57 | |
|
57 | 58 | if values is empty, expand 'no_foos'. |
|
58 | 59 | |
|
59 | 60 | if 'foo' not in template map, return values as a string, |
|
60 |
joined by |
|
|
61 | joined by 'separator'. | |
|
61 | 62 | |
|
62 | 63 | expand 'start_foos'. |
|
63 | 64 | |
@@ -77,7 +78,7 def _showlist(name, values, plural=None, | |||
|
77 | 78 | return |
|
78 | 79 | if name not in templ: |
|
79 | 80 | if isinstance(values[0], str): |
|
80 |
yield |
|
|
81 | yield separator.join(values) | |
|
81 | 82 | else: |
|
82 | 83 | for v in values: |
|
83 | 84 | yield dict(v, **args) |
General Comments 0
You need to be logged in to leave comments.
Login now