def render_apiarg_table(r, apiargs): table = TableData() header = [apiargs.field_type()] if apiargs.has_type() is True: header.append('Type') header.append('Description') num_columns = len(header) table.add_header(header) if num_columns == 2: widths = [20, 80] for entry in apiargs.ordered_content(): table.add_row([RstCloth.pre(entry.name), fill(string=entry.description, first=0, hanging=3, wrap=False)]) elif num_columns == 3: widths = [20, 20, 80] for entry in apiargs.ordered_content(): table.add_row([RstCloth.pre(entry.name), entry.type_for_table_output(), fill(string=entry.description, first=0, hanging=3, wrap=False)]) r.content(TableBuilder(ListTable(table, widths=widths)).output, indent=3)
def render_apiarg_table(r, apiargs): table = TableData() header = [apiargs.field_type()] if apiargs.has_type() is True: header.append('Type') header.append('Description') num_columns = len(header) table.add_header(header) if num_columns == 2: widths = [20, 80] for entry in apiargs.ordering: table.add_row([RstCloth.pre(entry.name), entry.description]) elif num_columns == 3: widths = [20, 20, 80] for entry in apiargs.ordering: table.add_row([ RstCloth.pre(entry.name), entry.type_for_table_output(), entry.description ]) r.content(TableBuilder(ListTable(table, widths=widths)).output, indent=3)
def render_toc_table(toc_items): table = TableData() table.add_header(['Name', 'Description']) for entry in toc_items: entry.render() if 'name' in entry: table.add_row([entry.name, entry.description]) else: table.add_row([RstCloth.role('doc', entry.file), entry.description]) return TableBuilder(RstTable(table))
class CustomTocTree(object): def __init__(self, filename, conf, sort=False): if "ref-toc" in filename: self._is_ref = True sort = True else: self._is_ref = False self.spec = self._process_spec(filename, sort) self.conf = conf self.table = None self.contents = None self.dfn = None self.final = False def build_table(self): self.table = TableData() self.table.add_header(['Name', 'Description']) def build_dfn(self): self.dfn = RstCloth() self.dfn.directive('class', 'toc') self.dfn.newline() def build_contents(self): self.contents = RstCloth() self.contents.directive('class', 'hidden') self.contents.newline() self.contents.directive('toctree', fields=[('titlesonly', '')], indent=3) self.contents.newline() def _process_spec(self, spec, sort=False): o = [] with open(spec, 'r') as f: data = yaml.safe_load_all(f) for datum in data: if 'description' not in datum or datum['description'] is None: datum['description'] = '' if sort is False: pass elif 'name' not in datum: sort = False o.append(datum) if sort is True: o.sort(key=lambda o: o['name']) return o def finalize(self): if not self.final: for ref in self.spec: if giza.content.helper.edition_check(ref, self.conf) is False: continue if self.table is not None: if 'text' in ref: if ref['name'] is None: self.table.add_row( [ '', ref['text'] ] ) else: self.table.add_row( [ ref['name'], ref['text'] ]) if 'name' in ref: self.table.add_row([ ref['name'], ref['description'] ]) else: self.table = None if self.contents is not None and 'file' in ref: if 'name' in ref and self._is_ref is False: self.contents.content("{0} <{1}>".format(ref['name'], ref['file']), 6, wrap=False, block='toc') else: self.contents.content(ref['file'], 6, wrap=False, block='toc') if self.dfn is not None: if 'name' in ref: text = ref['name'] else: text = None if 'level' in ref: idnt = 3 * ref['level'] else: idnt = 3 if 'class' in ref: self.dfn.directive(name='class', arg=ref['class'], indent=idnt) idnt += 3 if 'text' in ref: if ref['name'] is None: self.dfn.content(ref['text'], idnt) else: self.dfn.definition(ref['name'], ref['text'], indent=idnt, bold=False, wrap=False) else: link = self.dfn.role('doc', ref['file'], text) self.dfn.definition(link, ref['description'], indent=idnt, bold=False, wrap=False) self.dfn.newline()
class CustomTocTree(object): def __init__(self, filename, conf, sort=False): if "ref-toc" in filename: self._is_ref = True sort = True else: self._is_ref = False self.spec = self._process_spec(filename, sort) self.conf = conf self.table = None self.contents = None self.dfn = None self.final = False def build_table(self): self.table = TableData() self.table.add_header(['Name', 'Description']) def build_dfn(self): self.dfn = RstCloth() self.dfn.directive('class', 'toc') self.dfn.newline() def build_contents(self): self.contents = RstCloth() self.contents.directive('class', 'hidden') self.contents.newline() self.contents.directive('toctree', fields=[('titlesonly', '')], indent=3) self.contents.newline() def _process_spec(self, spec, sort=False): o = [] with open(spec, 'r') as f: data = yaml.safe_load_all(f) for datum in data: if 'description' not in datum or datum['description'] is None: datum['description'] = '' if sort is False: pass elif 'name' not in datum: sort = False o.append(datum) if sort is True: o.sort(key=lambda o: o['name']) return o def finalize(self): if not self.final: for ref in self.spec: if giza.content.helper.edition_check(ref, self.conf) is False: continue if self.table is not None: if 'text' in ref: if ref['name'] is None: self.table.add_row(['', ref['text']]) else: self.table.add_row([ref['name'], ref['text']]) if 'name' in ref: self.table.add_row([ref['name'], ref['description']]) else: self.table = None if self.contents is not None and 'file' in ref: if 'name' in ref and self._is_ref is False: self.contents.content("{0} <{1}>".format( ref['name'], ref['file']), 6, wrap=False, block='toc') else: self.contents.content(ref['file'], 6, wrap=False, block='toc') if self.dfn is not None: if 'name' in ref: text = ref['name'] else: text = None if 'level' in ref: idnt = 3 * ref['level'] else: idnt = 3 if 'class' in ref: self.dfn.directive(name='class', arg=ref['class'], indent=idnt) idnt += 3 if 'text' in ref: if ref['name'] is None: self.dfn.content(ref['text'], idnt) else: self.dfn.definition(ref['name'], ref['text'], indent=idnt, bold=False, wrap=False) else: link = self.dfn.role('doc', ref['file'], text) self.dfn.definition(link, ref['description'], indent=idnt, bold=False, wrap=False) self.dfn.newline()