Show More
@@ -324,14 +324,8 b' def join(context, mapping, args):' | |||
|
324 | 324 | joiner = " " |
|
325 | 325 | if len(args) > 1: |
|
326 | 326 | joiner = evalstring(context, mapping, args[1]) |
|
327 | ||
|
328 | first = True | |
|
329 | for x in pycompat.maybebytestr(joinset): | |
|
330 | if first: | |
|
331 | first = False | |
|
332 | else: | |
|
333 | yield joiner | |
|
334 | yield joinfmt(x) | |
|
327 | itemiter = (joinfmt(x) for x in pycompat.maybebytestr(joinset)) | |
|
328 | return templateutil.joinitems(itemiter, joiner) | |
|
335 | 329 | |
|
336 | 330 | @templatefunc('label(label, expr)') |
|
337 | 331 | def label(context, mapping, args): |
@@ -75,19 +75,12 b' class hybrid(wrapped):' | |||
|
75 | 75 | """ |
|
76 | 76 | |
|
77 | 77 | def __init__(self, gen, values, makemap, joinfmt, keytype=None): |
|
78 | if gen is not None: | |
|
79 | self._gen = gen # generator or function returning generator | |
|
78 | self._gen = gen # generator or function returning generator | |
|
80 | 79 | self._values = values |
|
81 | 80 | self._makemap = makemap |
|
82 | 81 | self.joinfmt = joinfmt |
|
83 | 82 | self.keytype = keytype # hint for 'x in y' where type(x) is unresolved |
|
84 | 83 | |
|
85 | def _gen(self): | |
|
86 | """Default generator to stringify this as {join(self, ' ')}""" | |
|
87 | for i, x in enumerate(self._values): | |
|
88 | if i > 0: | |
|
89 | yield ' ' | |
|
90 | yield self.joinfmt(x) | |
|
91 | 84 | def itermaps(self, context): |
|
92 | 85 | makemap = self._makemap |
|
93 | 86 | for x in self._values: |
@@ -96,6 +89,8 b' class hybrid(wrapped):' | |||
|
96 | 89 | def show(self, context, mapping): |
|
97 | 90 | # TODO: switch gen to (context, mapping) API? |
|
98 | 91 | gen = self._gen |
|
92 | if gen is None: | |
|
93 | return joinitems((self.joinfmt(x) for x in self._values), ' ') | |
|
99 | 94 | if callable(gen): |
|
100 | 95 | return gen() |
|
101 | 96 | return gen |
@@ -556,3 +551,13 b' def getdictitem(dictarg, key):' | |||
|
556 | 551 | if val is None: |
|
557 | 552 | return |
|
558 | 553 | return wraphybridvalue(dictarg, key, val) |
|
554 | ||
|
555 | def joinitems(itemiter, sep): | |
|
556 | """Join items with the separator; Returns generator of bytes""" | |
|
557 | first = True | |
|
558 | for x in itemiter: | |
|
559 | if first: | |
|
560 | first = False | |
|
561 | else: | |
|
562 | yield sep | |
|
563 | yield x |
General Comments 0
You need to be logged in to leave comments.
Login now