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