diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2016-08-27 17:42:40 +0300 |
---|---|---|
committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2016-08-27 17:42:40 +0300 |
commit | e64ee7e330bd82b7887493f14e52024658f5bbce (patch) | |
tree | 3f2fcf93172694951b1015dd36318f14a5e02f73 /sphinx/jinja2glue.py | |
parent | 654ab7757422f2b3adfaf5dc5d5891b590356aa3 (diff) | |
parent | 281942ce25e6a88bbe03253552b09a7a99670057 (diff) |
Merge branch 'stable'
Diffstat (limited to 'sphinx/jinja2glue.py')
-rw-r--r-- | sphinx/jinja2glue.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/sphinx/jinja2glue.py b/sphinx/jinja2glue.py index c5e0e29e5..6e2ef7186 100644 --- a/sphinx/jinja2glue.py +++ b/sphinx/jinja2glue.py @@ -35,6 +35,27 @@ def _toint(val): return 0 +def _slice_index(values, slices): + seq = list(values) + length = 0 + for value in values: + length += 1 + len(value[1][1]) # count includes subitems + items_per_slice = length // slices + offset = 0 + for slice_number in range(slices): + count = 0 + start = offset + if slices == slice_number + 1: # last column + offset = len(seq) + else: + for value in values[offset:]: + count += 1 + len(value[1][1]) + offset += 1 + if count >= items_per_slice: + break + yield seq[start:offset] + + def accesskey(context, key): """Helper to output each access key only once.""" if '_accesskeys' not in context: @@ -125,6 +146,7 @@ class BuiltinTemplateLoader(TemplateBridge, BaseLoader): extensions=extensions) self.environment.filters['tobool'] = _tobool self.environment.filters['toint'] = _toint + self.environment.filters['slice_index'] = _slice_index self.environment.globals['debug'] = contextfunction(pformat) self.environment.globals['accesskey'] = contextfunction(accesskey) self.environment.globals['idgen'] = idgen |