def run(self): ncolumns = self.options.get('columns', 2) node = nodes.Element() node.document = self.state.document self.state.nested_parse(self.content, self.content_offset, node) if len(node.children) != 1 or not isinstance(node.children[0], nodes.bullet_list): return [self.state.document.reporter.warning( '.. hlist content is not a list', line=self.lineno)] fulllist = node.children[0] # create a hlist node where the items are distributed npercol, nmore = divmod(len(fulllist), ncolumns) index = 0 table = nodes.table() tg = nodes.tgroup() table += tg row = nodes.row() tbody = nodes.tbody() for column in range(ncolumns): endindex = index + (column < nmore and (npercol + 1) or npercol) colspec = nodes.colspec() colspec.attributes['stub'] = 0 colspec.attributes['colwidth'] = 100. / ncolumns col = nodes.entry() col += nodes.bullet_list() col[0] += fulllist.children[index:endindex] index = endindex tg += colspec row += col tbody += row tg += tbody table['classes'].append('hlist') return [table]
def description_table(descriptions, widths, headers): # generate table-root tgroup = nodes.tgroup(cols=len(widths)) for width in widths: tgroup += nodes.colspec(colwidth=width) table = nodes.table() table += tgroup # generate table-header thead = nodes.thead() row = nodes.row() for header in headers: entry = nodes.entry() entry += nodes.paragraph(text=header) row += entry thead += row tgroup += thead # generate table-body tbody = nodes.tbody() for desc in descriptions: row = nodes.row() for col in desc: entry = nodes.entry() if not isinstance(col, basestring): col = str(col) paragraph = nodes.paragraph() paragraph += nodes.Text(col) entry += paragraph row += entry tbody += row tgroup += tbody return table
def run(self): if ValueTableDirective.values[0].description is None: list = nodes.bullet_list() for v in ValueTableDirective.values: item = nodes.list_item() item += nodes.literal(v.value, v.value) list += item return [list] table = nodes.table() tgroup = nodes.tgroup() tbody = nodes.tbody() for v in ValueTableDirective.values: row = nodes.row() entry = nodes.entry() entry += nodes.literal(v.value, v.value) row += entry entry = nodes.entry() entry += nodes.paragraph(text=v.description) row += entry tbody += row tgroup += nodes.colspec(colwidth=10) tgroup += nodes.colspec(colwidth=90) tgroup += tbody table += tgroup return [table]
def gen_table(columns, data): table = nodes.table() tgroup = nodes.tgroup(cols=len(columns)) table += tgroup for column in columns: tgroup += nodes.colspec(colwidth=1) thead = nodes.thead() tgroup += thead headrow = nodes.row() for column in columns: entry = nodes.entry() para = nodes.paragraph() entry += para header = column.header() para += nodes.Text(header, header) headrow += entry thead += headrow tbody = nodes.tbody() tgroup += tbody for obj in data: row = nodes.row() for column in columns: entry = nodes.entry() para = nodes.paragraph() entry += para para += column.data(obj) row += entry tbody += row return [table]
def create_cross_table(self, app, docname, node, matrix, options): table = nodes.table() table["classes"].append("traceables-crosstable") tgroup = nodes.tgroup(cols=len(matrix.secondaries), colwidths="auto") table += tgroup # Add column specifications. tgroup += nodes.colspec(colwidth=1) for column in matrix.secondaries: tgroup += nodes.colspec(colwidth=1) # Add heading row. thead = nodes.thead() tgroup += thead row = nodes.row() thead += row entry = nodes.entry() row += entry for secondary in matrix.secondaries: entry = nodes.entry() row += entry container = nodes.container() entry += container inline = nodes.inline() container += inline paragraph = nodes.paragraph() inline += paragraph paragraph += secondary.make_reference_node(app.builder, docname) # Add table body. tbody = nodes.tbody() tgroup += tbody for primary in matrix.primaries: row = nodes.row() tbody += row entry = nodes.entry() row += entry paragraph = nodes.paragraph() entry += paragraph paragraph += primary.make_reference_node(app.builder, docname) for is_related in matrix.get_boolean_row(primary): entry = nodes.entry() row += entry if is_related: checkmark = traceable_checkmark() entry += checkmark checkmark += nodes.inline(u"\u2714", u"\u2714") else: continue container = traceable_matrix_crosstable() container += table container["traceables-matrix"] = matrix # backward = matrix.backward_relationship.capitalize() # forward = matrix.forward_relationship.capitalize() # container["relationships"] = (forward, backward) # container["boolean_matrix"] = 0#boolean_matrix # container["secondaries"] = matrix.secondaries return container
def build_toc(descinfo, env): """Return a desc table of contents node tree""" separator = EMDASH child_ids = descinfo['children'] if not child_ids: return None max_fullname_len = 0 max_summary_len = 0 rows = [] for fullname, refid, summary in ichild_ids(child_ids, env): max_fullname_len = max(max_fullname_len, len(fullname)) max_summary_len = max(max_summary_len, len(summary)) reference_node = toc_ref(fullname, refid) ref_entry_node = entry('', paragraph('', '', reference_node)) sep_entry_node = entry('', paragraph('', separator)) sum_entry_node = entry('', paragraph('', summary)) row_node = row('', ref_entry_node, sep_entry_node, sum_entry_node) rows.append(row_node) col0_len = max_fullname_len + 2 # add error margin col1_len = len(separator) # no padding col2_len = max_summary_len + 10 # add error margin tbody_node = tbody('', *rows) col0_colspec_node = colspec(colwidth=col0_len) col1_colspec_node = colspec(colwidth=col1_len) col2_colspec_node = colspec(colwidth=col2_len) tgroup_node = tgroup('', col0_colspec_node, col1_colspec_node, col2_colspec_node, tbody_node, cols=3) return TocTable('', tgroup_node, classes=['toc'])
def _description_table(self, descriptions, widths, headers): # generate table-root tgroup = nodes.tgroup(cols=len(widths)) for width in widths: tgroup += nodes.colspec(colwidth=width) table = nodes.table() table += tgroup # generate table-header thead = nodes.thead() row = nodes.row() for header in headers: entry = nodes.entry() entry += nodes.paragraph(text=header) row += entry thead += row tgroup += thead # generate table-body tbody = nodes.tbody() for desc in descriptions: row = nodes.row() for attr in desc: entry = nodes.entry() if not isinstance(attr, string_types): attr = str(attr) self.state.nested_parse(ViewList([attr], source=attr), 0, entry) row += entry tbody += row tgroup += tbody return table
def get_tablespec(self): table_spec = addnodes.tabular_col_spec() table_spec['spec'] = 'll' table = autosummary_table('') real_table = nodes.table('', classes=['longtable']) table.append(real_table) group = nodes.tgroup('', cols=2) real_table.append(group) group.append(nodes.colspec('', colwidth=10)) group.append(nodes.colspec('', colwidth=90)) body = nodes.tbody('') group.append(body) def append_row(*column_texts): row = nodes.row('') for text in column_texts: node = nodes.paragraph('') vl = ViewList() vl.append(text, '<autosummary>') self.state.nested_parse(vl, 0, node) try: if isinstance(node[0], nodes.paragraph): node = node[0] except IndexError: pass row.append(nodes.entry('', node)) body.append(row) return table, table_spec, append_row
def build_table_from_list(self, table_data, num_cols, col_widths, header_rows, stub_columns): table = nodes.table() tgroup = nodes.tgroup(cols=len(col_widths)) table += tgroup for col_width in col_widths: colspec = nodes.colspec(colwidth=col_width) if stub_columns: colspec.attributes['stub'] = 1 stub_columns -= 1 tgroup += colspec rows = [] for row in table_data: row_node = nodes.row() for cell_index, cell in enumerate(row): entry = nodes.entry() entry += cell row_node += entry if self.bias == "left" and not cell_index: remainder = num_cols - len(row) if remainder: entry["morecols"] = remainder if self.bias == "right" and cell_index == len(row) - 1: remainder = num_cols - (cell_index + 1) if remainder: entry["morecols"] = remainder rows.append(row_node) if header_rows: thead = nodes.thead() thead.extend(rows[:header_rows]) tgroup += thead tbody = nodes.tbody() tbody.extend(rows[header_rows:]) tgroup += tbody return table
def create_progtable(self, **attrs): _attrs = { 'classes': ['progress', 'outer', 'docutils', 'field-list'], 'colwidths': [20, 80] } _attrs.update(attrs) # create container elements node = nodes.table(classes=_attrs['classes']) tgroup = nodes.tgroup(cols=2) thead = thead = nodes.thead() thead += self.create_headrow() tbody = nodes.tbody() # tgroup gets: # - colspec # - thead # - tbody for w in _attrs['colwidths']: tgroup += nodes.colspec(colwidth=w) # assemble the hierarchy tgroup += thead tgroup += tbody node += tgroup # return the table return node
def create_table(self, data, num_headers=1): table_node = nodes.table() if len(data) > 0: tgroup_node = nodes.tgroup(cols=len(data[0])) table_node += tgroup_node col_width = 100 // len(data[0]) for col_index in range(len(data[0])): colspec_node = nodes.colspec(colwidth=col_width) tgroup_node += colspec_node thead = nodes.thead() tgroup_node += thead tbody = nodes.tbody() tgroup_node += tbody for row_index, row in enumerate(data): row_node = nodes.row() for col_index, cell_item in enumerate(row): row_node += self.create_cell(col_index, cell_item, row_index < num_headers) if row_index < num_headers: thead += row_node else: tbody += row_node return table_node
def run(self): header = self.options.get('header').split(',') lines = self._get_lines() regex = self.options.get('regex') max_cols = len(header) table = nodes.table() tgroup = nodes.tgroup(max_cols) table += tgroup col_widths = self.get_column_widths(max_cols) tgroup.extend(nodes.colspec(colwidth=col_width) for col_width in col_widths) thead = nodes.thead() tgroup += thead thead += self.create_table_row(header) tbody = nodes.tbody() tgroup += tbody for row in lines: matched = re.search(regex, row) if matched: tbody += self.create_table_row(matched.groups()) return [table]
def build_table_from_list(self, table_data, col_widths, header_rows, stub_columns): table = nodes.table() if self.widths == 'auto': table['classes'] += ['colwidths-auto'] elif self.widths: # "grid" or list of integers table['classes'] += ['colwidths-given'] tgroup = nodes.tgroup(cols=len(col_widths)) table += tgroup for col_width in col_widths: colspec = nodes.colspec() if col_width is not None: colspec.attributes['colwidth'] = col_width if stub_columns: colspec.attributes['stub'] = 1 stub_columns -= 1 tgroup += colspec rows = [] for row in table_data: row_node = nodes.row() for cell in row: entry = nodes.entry() entry += cell row_node += entry rows.append(row_node) if header_rows: thead = nodes.thead() thead.extend(rows[:header_rows]) tgroup += thead tbody = nodes.tbody() tbody.extend(rows[header_rows:]) tgroup += tbody return table
def build_table_from_list(self, table_data, col_widths, header_rows, stub_columns): table = nodes.table() tgroup = nodes.tgroup(cols=len(col_widths)) table += tgroup for col_width in col_widths: colspec = nodes.colspec(colwidth=col_width) if stub_columns: colspec.attributes['stub'] = 1 stub_columns -= 1 tgroup += colspec rows = [] for row in table_data: row_node = nodes.row() for cell in row: entry = nodes.entry() entry += cell row_node += entry rows.append(row_node) if header_rows: thead = nodes.thead() thead.extend(rows[:header_rows]) tgroup += thead tbody = nodes.tbody() tbody.extend(rows[header_rows:]) tgroup += tbody return table
def build_table(row_nodes, colwidth_list, headrow_data=None): """ Creates new rst table node tree. Args: row_nodes (list): list of docutils.nodes.row nodes, contains actual content of the rst table colwidth_list (list): list of width percentages for each column, eg.: use [10, 90] for 2 columns, 1st has 10% width, 2nd the rest Returns: docutils.nodes.table: rst table node tree which contains given rows """ table = nodes.table() tgroup = nodes.tgroup(cols=len(colwidth_list)) table += tgroup for colwidth in colwidth_list: colspec = nodes.colspec(colwidth=colwidth) tgroup += colspec if headrow_data is not None: thead = nodes.thead() tgroup += thead head_row_node = build_row(headrow_data) thead += head_row_node tbody = nodes.tbody() tgroup += tbody for row in row_nodes: tbody += row return table
def build_table(self, table_data): table = nodes.table() tgroup = nodes.tgroup(cols=len(self.headers)) table += tgroup tgroup.extend( nodes.colspec(colwidth=col_width, colname='c' + str(idx)) for idx, col_width in enumerate(self.col_widths) ) thead = nodes.thead() tgroup += thead row_node = nodes.row() thead += row_node row_node.extend(nodes.entry(h, nodes.paragraph(text=h)) for h in self.headers) tbody = nodes.tbody() tgroup += tbody rows, groups = self.get_rows(table_data) tbody.extend(rows) table.extend(groups) return table
def build_table(self): table = nodes.table() tgroup = nodes.tgroup(cols=len(self.headers)) table += tgroup # TODO(sdague): it would be really nice to figure out how not # to have this stanza, it kind of messes up all of the table # formatting because it doesn't let tables just be the right # size. tgroup.extend( nodes.colspec(colwidth=col_width, colname='c' + str(idx)) for idx, col_width in enumerate(self.col_widths) ) thead = nodes.thead() tgroup += thead row_node = nodes.row() thead += row_node row_node.extend(nodes.entry(h, nodes.paragraph(text=h)) for h in self.headers) tbody = nodes.tbody() tgroup += tbody rows, groups = self.collect_rows() tbody.extend(rows) table.extend(groups) return table
def run(self): table = nodes.table('') ## Create table group = nodes.tgroup('', cols=3) table.append(group) for colwidth in 10,40,5: group.append(nodes.colspec('', colwidth=colwidth)) head = nodes.thead('') group.append(head) body = nodes.tbody('') group.append(body) def add_row(target, *column_texts): row = nodes.row('') for text in column_texts: if text == None: text = "" node = nodes.paragraph('') vl = ViewList() vl.append(text, '<autosummary>') self.state.nested_parse(vl, 0, node) try: if isinstance(node[0], nodes.paragraph): node = node[0] except IndexError: pass row.append(nodes.entry('', node)) target.append(row) def get_symbol(s): parametertable_path = s.split('.') for i in reversed(range(len(parametertable_path))): module = '.'.join(parametertable_path[:i]) symbol = parametertable_path[i:] try: m = __import__(str(module), fromlist='true') except ImportError: continue else: break parent = m for sym in symbol: parent = getattr(parent, sym) return parent add_row(head, 'Parameter', 'Description' , 'Unit') for param in get_symbol(self.arguments[0]): add_row(body, param.name, param.desc, param.unit) return [table]
def envy_resolve(app, doctree, fromdocname): objects = app.env.domaindata['envy']['objects'] # add uplink info for holder in doctree.traverse(uplink_placeholder): obj = objects[holder.name] links = [] for sp, pos, name, variants in obj.uplinks: signode = addnodes.desc_signature('', '') signode['first'] = False signode += make_refnode(app.builder, fromdocname, sp.docname, sp.iname + '-' + sp.name, addnodes.desc_addname(sp.name, sp.name), sp.name) text = ' {}: {}'.format(pos, name) signode += addnodes.desc_name(text, text) if variants is not None: text = ' [{}]'.format(variants) signode += addnodes.desc_annotation(text, text) links.append(signode) holder.replace_self(links) # add subnode list for holder in doctree.traverse(sub_placeholder): obj = objects[holder.name] add_variant = False for pos, name, child, variants in obj.subs: if variants is not None: add_variant = True table = nodes.table() headers = [(1, 'Address'), (1, 'Name'), (10, 'Description')] if add_variant: headers.insert(1, (1, 'Variants')) tgroup = nodes.tgroup(cols=len(headers)) table += tgroup for colwidth, header in headers: tgroup += nodes.colspec(colwidth=colwidth) thead = nodes.thead() tgroup += thead headrow = nodes.row() for colwidth, header in headers: entry = nodes.entry() para = nodes.paragraph() entry += para para += nodes.Text(header, header) headrow += entry thead += headrow tbody = nodes.tbody() tgroup += tbody for pos, name, child, variants in obj.subs: row = nodes.row() row += wrap_text_entry(pos) if add_variant: row += wrap_text_entry('all' if variants is None else variants) row += wrap_text_entry(name) entry = nodes.entry() para = nodes.paragraph() entry += para para += make_refnode(app.builder, fromdocname, child.docname, child.iname + '-' + child.name, nodes.Text(child.brief, child.brief), obj.brief) row += entry tbody += row holder.replace_self([table])
def build_links_table(self, resource): is_list = "is-list" in self.options table = nodes.table() tgroup = nodes.tgroup(cols=3) table += tgroup tgroup += nodes.colspec(colwidth=25) tgroup += nodes.colspec(colwidth=15) tgroup += nodes.colspec(colwidth=60) thead = nodes.thead() tgroup += thead append_row(thead, ["Name", "Method", "Resource"]) tbody = nodes.tbody() tgroup += tbody request = DummyRequest() if is_list: child_resources = resource.list_child_resources else: child_resources = resource.item_child_resources names_to_resource = {} for child in child_resources: names_to_resource[child.name_plural] = (child, True) if not is_list and resource.model: child_keys = {} create_fake_resource_path(request, resource, child_keys, True) obj = resource.get_queryset(request, **child_keys)[0] else: obj = None related_links = resource.get_related_links(request=request, obj=obj) for key, info in related_links.iteritems(): if "resource" in info: names_to_resource[key] = (info["resource"], info.get("list-resource", False)) links = resource.get_links(child_resources, request=DummyRequest(), obj=obj) for linkname in sorted(links.iterkeys()): info = links[linkname] child, is_child_link = names_to_resource.get(linkname, (resource, is_list)) paragraph = nodes.paragraph() paragraph += get_ref_to_resource(child, is_child_link) append_row(tbody, [nodes.strong(text=linkname), info["method"], paragraph]) return table
def create_list_table(self, matrix, options, docname): table = nodes.table() tgroup = nodes.tgroup(cols=2, colwidths="auto") table += tgroup # Add column specifications. tgroup += nodes.colspec(colwidth=50) tgroup += nodes.colspec(colwidth=50) # Add heading row. thead = nodes.thead() tgroup += thead row = nodes.row() thead += row entry = nodes.entry() row += entry backward_relationship = matrix.backward_relationship.capitalize() entry += nodes.paragraph(backward_relationship, backward_relationship) entry = nodes.entry() row += entry forward_relationship = matrix.forward_relationship.capitalize() entry += nodes.paragraph(forward_relationship, forward_relationship) # Add table body. tbody = nodes.tbody() tgroup += tbody for traceable in matrix.primaries: relatives = matrix.get_relatives(traceable) # Create first row with a first column. row = nodes.row() entry = nodes.entry(morerows=len(relatives) - 1) row += entry paragraph = nodes.paragraph() entry += paragraph paragraph += traceable.make_reference_node( self.app.builder, docname) for relative in relatives: if not row: # Create subsequent rows without a first column. row = nodes.row() tbody += row entry = nodes.entry() row += entry paragraph = nodes.paragraph() entry += paragraph paragraph += relative.make_reference_node( self.app.builder, docname) row = None return table
def get_table(self, items_set): """Generate a proper list of table nodes for errorsummary:: directive. *items* is a list produced by :meth:`get_items`. """ table_spec = addnodes.tabular_col_spec() table_spec['spec'] = 'll' table = autosummary_table('') real_table = nodes.table('', classes=['longtable']) table.append(real_table) group = nodes.tgroup('', cols=3) real_table.append(group) group.append(nodes.colspec('', colwidth=70)) group.append(nodes.colspec('', colwidth=20)) group.append(nodes.colspec('', colwidth=90)) body = nodes.tbody('') group.append(body) def append_row(*column_texts): row = nodes.row('') for text in column_texts: node = nodes.paragraph('') vl = ViewList() vl.append(text, '<autosummary>') self.state.nested_parse(vl, 0, node) try: if isinstance(node[0], nodes.paragraph): node = node[0] except IndexError: pass row.append(nodes.entry('', node)) body.append(row) col1 = u"**Name**" col2 = u"**Code**" col3 = u"**Message**" append_row(col1, col2, col3) for class_name, items in sorted(items_set.items()): for name, sig, summary, real_name, code in items: if 'nosignatures' not in self.options: col1 = '_%s' % name col2 = '{}'.format(code) translated = translate(summary, "ru") if summary else "" if translated != summary: col3 = u"{} / {}".format(translated, summary) else: col3 = summary append_row(col1, col2, col3) return [table_spec, table]
def get_autosummary(names, state, no_signatures=False): """ Generate a proper table node for autosummary:: directive. *names* is a list of names of Python objects to be imported and added to the table. *document* is the Docutils document object. """ document = state.document real_names = {} warnings = [] prefixes = [''] prefixes.insert(0, document.settings.env.currmodule) table = nodes.table('') group = nodes.tgroup('', cols=2) table.append(group) group.append(nodes.colspec('', colwidth=30)) group.append(nodes.colspec('', colwidth=70)) body = nodes.tbody('') group.append(body) def append_row(*column_texts): row = nodes.row('') for text in column_texts: node = nodes.paragraph('') vl = ViewList() vl.append(text, '<autosummary>') state.nested_parse(vl, 0, node) row.append(nodes.entry('', node)) body.append(row) for name in names: try: obj, real_name = import_by_name(name, prefixes=prefixes) except ImportError: warnings.append(document.reporter.warning( 'failed to import %s' % name)) append_row(':obj:`%s`' % name, '') continue real_names[name] = real_name title = '' qualifier = 'obj' col1 = ':'+qualifier+':`%s <%s>`' % (name, real_name) col2 = title append_row(col1, col2) return table, warnings, real_names
def process_indigo_option_nodes(app, doctree, fromdocname): env = app.builder.env for node in doctree.traverse(optionslist): content = [] tbl = nodes.table() tgroup = nodes.tgroup(cols=4) tbl += tgroup tgroup += nodes.colspec(colwidth=35) tgroup += nodes.colspec(colwidth=9) tgroup += nodes.colspec(colwidth=9) tgroup += nodes.colspec(colwidth=73) thead = nodes.thead() tgroup += thead row = nodes.row() thead += row row += createRowEntryText('Name') row += createRowEntryText('Type') row += createRowEntryText('Default') row += createRowEntryText('Short description') tbody = nodes.tbody() tgroup += tbody content.append(tbl) sorted_options = sorted(env.indigo_options, key=lambda o:o['name']) for opt_info in sorted_options: row = nodes.row() tbody += row # Create a reference newnode = nodes.reference('', '') innernode = nodes.Text(opt_info['name'], opt_info['name']) newnode['refdocname'] = opt_info['docname'] newnode['refuri'] = app.builder.get_relative_uri( fromdocname, opt_info['docname']) newnode['refuri'] += '#' + normalize_name(opt_info['name']) newnode.append(innernode) row += createRowEntry(newnode) row += createRowEntryText(opt_info['type']) row += createRowEntryText(opt_info['default']) row += createRowEntryText(opt_info['short']) node.replace_self(content)
def build_details_table(self, error_obj): table = nodes.table() tgroup = nodes.tgroup(cols=2) table += tgroup tgroup += nodes.colspec(colwidth=20) tgroup += nodes.colspec(colwidth=80) tbody = nodes.tbody() tgroup += tbody # API Error Code append_detail_row(tbody, 'API Error Code', nodes.literal(text=error_obj.code)) # HTTP Status Code ref = parse_text(self, ':http:`%s`' % error_obj.http_status) append_detail_row(tbody, 'HTTP Status Code', ref) # Error Text append_detail_row(tbody, 'Error Text', nodes.literal(text=error_obj.msg)) if error_obj.headers: if callable(error_obj.headers): headers = error_obj.headers(DummyRequest()) # HTTP Headers if len(headers) == 1: content = nodes.literal(text=headers.keys()[0]) else: content = nodes.bullet_list() for header in headers.iterkeys(): item = nodes.list_item() content += item literal = nodes.literal(text=header) item += literal append_detail_row(tbody, 'HTTP Headers', content) # Description append_detail_row( tbody, 'Description', parse_text(self, '\n'.join(self.content), where='API error %s description' % error_obj.code)) return table
def format(self, app, docname, node, traceables, options): additional_attributes = options.get("attributes") or [] columns = ["tag", "title"] + additional_attributes table = nodes.table() table["classes"].append("traceables-listtable") tgroup = nodes.tgroup(cols=len(columns), colwidths="auto") table += tgroup # Add column specifications. for attribute_name in columns: tgroup += nodes.colspec(colwidth=1) # Add heading row. thead = nodes.thead() tgroup += thead row = nodes.row() thead += row for attribute_name in columns: entry = nodes.entry() row += entry container = nodes.container() entry += container text = attribute_name.capitalize() inline = nodes.inline(text, text) container += inline # Add table body. tbody = nodes.tbody() tgroup += tbody for traceable in traceables: row = nodes.row() tbody += row for attribute_name in columns: entry = nodes.entry() row += entry if attribute_name == "tag": inline = nodes.inline() inline += traceable.make_reference_node( app.builder, docname) elif attribute_name == "title": text = traceable.title if traceable.has_title else "" inline = nodes.inline(text, text) else: text = traceable.attributes.get(attribute_name, "") inline = nodes.inline(text, text) entry += inline return table
def _build_markup(self, notifications): content = [] cols = ['Notification class', 'Payload class', 'Sample file link'] table = nodes.table() content.append(table) group = nodes.tgroup(cols=len(cols)) table.append(group) head = nodes.thead() group.append(head) for i in range(len(cols)): group.append(nodes.colspec(colwidth=1)) body = nodes.tbody() group.append(body) # fill the table header row = nodes.row() body.append(row) for col_name in cols: col = nodes.entry() row.append(col) text = nodes.strong(text=col_name) col.append(text) # fill the table content, one notification per row for name, payload, sample in notifications: row = nodes.row() body.append(row) col = nodes.entry() row.append(col) text = nodes.literal(text=name) col.append(text) col = nodes.entry() row.append(col) text = nodes.literal(text=payload) col.append(text) col = nodes.entry() row.append(col) ref = nodes.reference(refuri=self.LINK_PREFIX + self.SAMPLE_ROOT + sample) txt = nodes.inline() col.append(txt) txt.append(ref) ref.append(nodes.literal(text=sample)) return content
def _build_grade_listing(self, matrix, content): summarytitle = nodes.subtitle(text="Grades") content.append(nodes.raw(text="Grades", attributes={'tagname': 'h2'})) content.append(summarytitle) table = nodes.table() table.set_class("table") table.set_class("table-condensed") grades = matrix.grades tablegroup = nodes.tgroup(cols=2) summarybody = nodes.tbody() summaryhead = nodes.thead() for i in range(2): tablegroup.append(nodes.colspec(colwidth=1)) tablegroup.append(summaryhead) tablegroup.append(summarybody) table.append(tablegroup) content.append(table) header = nodes.row() blank = nodes.entry() blank.append(nodes.strong(text="Grade")) header.append(blank) blank = nodes.entry() blank.append(nodes.strong(text="Description")) header.append(blank) summaryhead.append(header) for grade in grades: item = nodes.row() namecol = nodes.entry() class_name = "label-%s" % grade.css_class status_text = nodes.paragraph(text=grade.title) status_text.set_class(class_name) status_text.set_class("label") namecol.append(status_text) item.append(namecol) notescol = nodes.entry() notescol.append(nodes.paragraph(text=grade.notes)) item.append(notescol) summarybody.append(item) return content
def get_table(self): """docstring for get_table""" table_spec = addnodes.tabular_col_spec() table_spec['spec'] = 'll' table = autosummary_table('') real_table = nodes.table('', classes=['longtable']) table.append(real_table) group = nodes.tgroup('', cols=2) real_table.append(group) group.append(nodes.colspec('', colwidth=10)) group.append(nodes.colspec('', colwidth=90)) body = nodes.tbody('') group.append(body) return table_spec, table, body
def get_table(self, items): """Generate a proper list of table nodes for autosummary:: directive. *items* is a list produced by :meth:`get_items`. """ table_spec = addnodes.tabular_col_spec() table_spec['spec'] = 'LL' table = autosummary_table('') real_table = nodes.table('') if "title" in self.options: title_node = self.make_title(self.options["title"]) real_table.insert(0, title_node) table.append(real_table) group = nodes.tgroup('', cols=2) real_table.append(group) group.append(nodes.colspec('', colwidth=10)) group.append(nodes.colspec('', colwidth=90)) body = nodes.tbody('') group.append(body) def append_row(*column_texts): row = nodes.row('') for text in column_texts: node = nodes.paragraph('') vl = ViewList() vl.append(text, '<doxybridge-autosummary>') self.sphinx_directive.state.nested_parse(vl, 0, node) try: if isinstance(node[0], nodes.paragraph): node = node[0] except IndexError: pass row.append(nodes.entry('', node)) body.append(row) for name, sig, summary, real_name in items: qualifier = self.get_qualifier(name) if 'nosignatures' not in self.options: col1 = ':%s:`%s <%s>`\ %s' % (qualifier, name, real_name, sig) else: col1 = ':%s:`%s <%s>`' % (qualifier, name, real_name) col2 = summary append_row(col1, col2) return [table_spec, table]
def run(self): """Generate a table summary of subcommands of a click group. :param name: Name of group, as used on the command line :param subcommands: Display only listed subcommands or skip the section if empty :param column_names: The :returns: A list with a docutil node, representing the resulting table. """ self.env = self.state.document.settings.env command = self._load_module(self.arguments[0]) if 'prog' not in self.options: raise self.error(':prog: must be specified') prog_name = self.options.get('prog') column_names = self.options.get( 'column_names', 'Subcommand, Description') column_names = [s.strip() for s in column_names.split(',')] subcommands = self.options.get('subcommands') ctx = click.Context(command, info_name=prog_name) colwidths = [1, 2] table = nodes.table() tgroup = nodes.tgroup(cols=len(column_names)) table += tgroup for colwidth in colwidths: tgroup += nodes.colspec(colwidth=colwidth) thead = nodes.thead() tgroup += thead thead += self._create_table_row(column_names) tbody = nodes.tbody() tgroup += tbody subcommands = _filter_commands(ctx, subcommands) for subcommand in subcommands: tbody += self._create_table_row( (subcommand.name, subcommand.short_help)) return [table]
def prepare_table_header(titles, widths): """Build docutil empty table""" ncols = len(titles) assert len(widths) == ncols tgroup = nodes.tgroup(cols=ncols) for width in widths: tgroup += nodes.colspec(colwidth=width) header = nodes.row() for title in titles: header += nodes.entry("", nodes.paragraph(text=title)) tgroup += nodes.thead("", header) tbody = nodes.tbody() tgroup += tbody return nodes.table("", tgroup), tbody
def build_details_table(self, error_obj): table = nodes.table() tgroup = nodes.tgroup(cols=2) table += tgroup tgroup += nodes.colspec(colwidth=20) tgroup += nodes.colspec(colwidth=80) tbody = nodes.tbody() tgroup += tbody # API Error Code append_detail_row(tbody, 'API Error Code', nodes.literal(text=error_obj.code)) # HTTP Status Code ref = parse_text(self, ':http:`%s`' % error_obj.http_status) append_detail_row(tbody, 'HTTP Status Code', ref) # Error Text append_detail_row(tbody, 'Error Text', nodes.literal(text=error_obj.msg)) if error_obj.headers: # HTTP Headers if len(error_obj.headers) == 1: content = nodes.literal(text=error_obj.headers.keys()[0]) else: content = nodes.bullet_list() for header in error_obj.headers.iterkeys(): item = nodes.list_item() content += item literal = nodes.literal(text=header) item += literal append_detail_row(tbody, 'HTTP Headers', content) # Description append_detail_row(tbody, 'Description', parse_text(self, '\n'.join(self.content))) return table
def get_table(self, items: List[Tuple[str, str, str, str]]) -> List[Node]: """Generate a proper list of table nodes for autosummary:: directive. *items* is a list produced by :meth:`get_items`. """ table_spec = addnodes.tabular_col_spec() table_spec['spec'] = r'\X{1}{2}\X{1}{2}' table = autosummary_table('') real_table = nodes.table('', classes=['longtable']) table.append(real_table) group = nodes.tgroup('', cols=2) real_table.append(group) group.append(nodes.colspec('', colwidth=10)) group.append(nodes.colspec('', colwidth=90)) body = nodes.tbody('') group.append(body) def append_row(*column_texts: str) -> None: row = nodes.row('') source, line = self.state_machine.get_source_and_line() for text in column_texts: node = nodes.paragraph('') vl = StringList() vl.append(text, '%s:%d:<autosummary>' % (source, line)) with switch_source_input(self.state, vl): self.state.nested_parse(vl, 0, node) try: if isinstance(node[0], nodes.paragraph): node = node[0] except IndexError: pass row.append(nodes.entry('', node)) body.append(row) for name, sig, summary, real_name in items: qualifier = 'obj' if 'nosignatures' not in self.options: col1 = ':%s:`%s <%s>`\\ %s' % (qualifier, name, real_name, rst.escape(sig)) else: col1 = ':%s:`%s <%s>`' % (qualifier, name, real_name) col2 = summary append_row(col1, col2) return [table_spec, table]
def build_errors_table(self, errors): """Build a table representing a list of errors. Args: errors (list of djblets.webapi.errors.WebAPIError): The errors to display. Returns: list of docutils.nodes.Node: The resulting list of nodes for the errors table. """ table = nodes.table(classes=['api-errors']) tgroup = nodes.tgroup(cols=2) table += tgroup tgroup += nodes.colspec(colwidth=25) tgroup += nodes.colspec(colwidth=75) tbody = nodes.tbody() tgroup += tbody for error in sorted(errors, key=lambda x: x.code): http_code = nodes.inline(classes=['http-error']) http_code += nodes.reference( text='HTTP %s - %s' % (error.http_status, HTTP_STATUS_CODES[error.http_status]), refuri=(DEFAULT_HTTP_STATUS_CODES_URL % error.http_status)), error_code = nodes.inline(classes=['api-error']) error_code += get_ref_to_error(error) error_info = nodes.inline() error_info += error_code error_info += http_code append_row( tbody, [ error_info, nodes.inline(text=error.msg), ]) return table
def transform_content(self, contentnode: addnodes.desc_content) -> None: name = self.names[0] path = Path(name) js_path = path.with_suffix('.json') if not js_path.exists(): w = self.state.reporter.warning( f'schema file {js_path} does not exist') contentnode += w return schema = json.loads(js_path.read_text()) table = nodes.table(classes=['colwidths-auto']) tg = nodes.tgroup(cols=2) tg += nodes.colspec(colwidth=1) tg += nodes.colspec(colwidth=0) table += tg # set up the table heading head = nodes.thead() hrow = nodes.row() head += hrow hrow += nodes.entry('', nodes.paragraph('', '', nodes.inline('', 'Field'))) hrow += nodes.entry('', nodes.paragraph('', '', nodes.inline('', 'Type'))) tg += head # write the field table tb = nodes.tbody() tg += tb for field in schema.get('fields', []): row = nodes.row() row += nodes.entry( '', nodes.paragraph('', '', nodes.literal('', field['name']))) type = field['data_type'] if field['nullable']: type += '?' row += nodes.entry( '', nodes.paragraph('', '', nodes.literal('', type))) tb += row contentnode += table
def model_table(model): table = nodes.table() tgroup = nodes.tgroup(cols=2) colspec = nodes.colspec(colwidth=1) tgroup.append(colspec) colspec = nodes.colspec(colwidth=1) tgroup.append(colspec) table += tgroup rows = [] row = nodes.row() rows.append(row) entry = nodes.entry() entry += nodes.paragraph(text="id") row += entry entry = nodes.entry() entry += nodes.paragraph(text=model.id) row += entry row = nodes.row() rows.append(row) entry = nodes.entry() entry += nodes.paragraph(text="name") row += entry entry = nodes.entry() entry += nodes.paragraph(text=model.name) row += entry row = nodes.row() rows.append(row) entry = nodes.entry() entry += nodes.paragraph(text="num_populations") row += entry entry = nodes.entry() entry += nodes.paragraph(text=model.num_populations) row += entry tbody = nodes.tbody() tbody.extend(rows) tgroup += tbody return table
def get_table(self, items): """Generate a proper list of table nodes for autosummary:: directive. *items* is a list produced by :meth:`get_items`. """ table_spec = addnodes.tabular_col_spec() table_spec['spec'] = 'll' table = autosummary_table('') real_table = nodes.table('', classes=['longtable']) table.append(real_table) group = nodes.tgroup('') real_table.append(group) group.append(nodes.colspec('', colwidth=0)) group.append(nodes.colspec('', colwidth=100)) body = nodes.tbody('') group.append(body) def append_row(*column_texts): row = nodes.row('') for text in column_texts: node = nodes.paragraph('') vl = ViewList() vl.append(text, '<autosummary>') self.state.nested_parse(vl, 0, node) try: if isinstance(node[0], nodes.paragraph): node = node[0] except IndexError: pass row.append(nodes.entry('', node)) body.append(row) for name, sig, summary, real_name, prefix in items: qualifier = 'obj' if 'nosignatures' not in self.options: col1 = ':%s:`%s <%s>`\ %s' % (qualifier, name, real_name, sig) else: col1 = ':%s:`%s <%s>`' % (qualifier, name, real_name) if prefix: prefix = "*%s*" % prefix append_row(prefix, col1) return [table_spec, table]
def run(self): env = self.state.document.settings.env xml_path = self.arguments[0] root_path = env.app.config.tr_rootdir if not os.path.isabs(xml_path): xml_path = os.path.join(root_path, xml_path) parser = JUnitParser(xml_path) results = parser.parse() # Construction idea taken from http://agateau.com/2015/docutils-snippets/ main_section = [] for testsuite in results: section = nodes.section() section += nodes.title(text=testsuite["name"]) section += nodes.paragraph(text="Tests: {tests}, Failures: {failure}, Errors: {error}, " "Skips: {skips}".format(tests=testsuite["tests"], failure=testsuite["failures"], error=testsuite["errors"], skips=testsuite["skips"] )) section += nodes.paragraph(text="Time: {time}".format(time=testsuite["time"])) table = nodes.table() section += table tgroup = nodes.tgroup(cols=len(self.header)) table += tgroup for colwidth in self.colwidths: tgroup += nodes.colspec(colwidth=colwidth) thead = nodes.thead() tgroup += thead thead += self._create_table_row(self.header) tbody = nodes.tbody() tgroup += tbody for testcase in testsuite["testcases"]: tbody += self._create_testcase_row(testcase) main_section += section return main_section
def get_table(self, items): # type: (List[Tuple[unicode, unicode, unicode, unicode]]) -> List[Union[addnodes.tabular_col_spec, autosummary_table]] # NOQA """Generate a proper list of table nodes for autosummary:: directive. *items* is a list produced by :meth:`get_items`. """ table_spec = addnodes.tabular_col_spec() table_spec['spec'] = r'p{0.5\linewidth}p{0.5\linewidth}' table = autosummary_table('') real_table = nodes.table('', classes=['longtable']) table.append(real_table) group = nodes.tgroup('', cols=2) real_table.append(group) group.append(nodes.colspec('', colwidth=10)) group.append(nodes.colspec('', colwidth=90)) body = nodes.tbody('') group.append(body) def append_row(*column_texts): # type: (unicode) -> None row = nodes.row('') for text in column_texts: node = nodes.paragraph('') vl = ViewList() vl.append(text, '<autosummary>') self.state.nested_parse(vl, 0, node) try: if isinstance(node[0], nodes.paragraph): node = node[0] except IndexError: pass row.append(nodes.entry('', node)) body.append(row) for name, sig, summary, real_name in items: qualifier = 'obj' if 'nosignatures' not in self.options: col1 = ':%s:`%s <%s>`\\ %s' % (qualifier, name, real_name, rst.escape(sig)) # type: unicode # NOQA else: col1 = ':%s:`%s <%s>`' % (qualifier, name, real_name) col2 = summary append_row(col1, col2) return [table_spec, table]
def run(self, reader: LineReader, document: Element) -> bool: location = reader.get_source_and_line(incr=1) header_row, aligns = self.read_table_header(reader) if header_row is None: return False body_rows = self.read_table_body(reader, aligns) colspecs = [ nodes.colspec('', colwidth=int(100 / len(aligns))) for _ in aligns ] thead = nodes.thead('', header_row) tgroup = nodes.tgroup('', *colspecs, thead, cols=len(aligns)) if body_rows: tgroup += nodes.tbody('', *body_rows) table = nodes.table('', tgroup) location.set_source_info(table) document += table return True
def _get_table(self, objects): table_spec = addnodes.tabular_col_spec() table_spec['spec'] = r'p{0.5\linewidth}p{0.5\linewidth}' table = sphinx.ext.autosummary.autosummary_table('') real_table = nodes.table('', classes=['longtable']) table.append(real_table) group = nodes.tgroup('', cols=2) real_table.append(group) group.append(nodes.colspec('', colwidth=10)) group.append(nodes.colspec('', colwidth=90)) body = nodes.tbody('') group.append(body) for obj in objects: body.append(self._get_row(obj)) return [table_spec, table]
def _get_table(self, objects): table_spec = addnodes.tabular_col_spec() table_spec["spec"] = r"p{0.5\linewidth}p{0.5\linewidth}" table = sphinx.ext.autosummary.autosummary_table("") real_table = nodes.table("", classes=["longtable"]) table.append(real_table) group = nodes.tgroup("", cols=2) real_table.append(group) group.append(nodes.colspec("", colwidth=10)) group.append(nodes.colspec("", colwidth=90)) body = nodes.tbody("") group.append(body) for obj in objects: body.append(self._get_row(obj)) return [table_spec, table]
def build_table(self, table_data, col_widths): table = nodes.table() # Set up the column specifications # based on the widths. tgroup = nodes.tgroup(cols=len(col_widths)) table += tgroup tgroup.extend( nodes.colspec(colwidth=col_width) for col_width in col_widths) # Set the headers thead = nodes.thead() tgroup += thead row_node = nodes.row() thead += row_node row_node.extend( nodes.entry(h, nodes.paragraph(text=h)) for h in self.HEADERS) # The body of the table is made up of rows. # Each row contains a series of entries, # and each entry contains a paragraph of text. tbody = nodes.tbody() tgroup += tbody rows = [] for member, tc_projects in table_data.items(): trow = nodes.row() # Iterate over the headers in the same order every time. name = nodes.entry() name += nodes.paragraph(text=str(member)) trow += name project = nodes.entry() project_list = nodes.paragraph() for proj in tc_projects: project_list += nodes.reference(proj, proj, refuri="projects/%s.html" % proj) project_list += nodes.Text(", ") project += project_list trow += project rows.append(trow) tbody.extend(rows) return table
def run(self): table = nodes.table( "", classes=[ "longtable", "colwidths-auto", # "colwidths-given", ], ) group = nodes.tgroup("", cols=3) table.append(group) group.append(nodes.colspec("", colwidth=35)) group.append(nodes.colspec("", colwidth=15)) group.append(nodes.colspec("", colwidth=50)) thead = nodes.thead("") group.append(thead) headrow = nodes.row("") thead.append(headrow) headrow.append(nodes.entry("", nodes.paragraph(text="Config Option"))) headrow.append(nodes.entry("", nodes.paragraph(text="Default Value"))) headrow.append(nodes.entry("", nodes.paragraph(text="Description"))) tbody = nodes.tbody("") group.append(tbody) for config_option in pn.config._options_registry.values(): row = nodes.row("") tbody.append(row) name = config_option.name default_value = config_option.default_value description = config_option.description row.append(nodes.entry("", nodes.literal(text=name))) row.append(nodes.entry("", nodes.literal(text=repr(default_value)))) row.append(nodes.entry("", self._parse_string(description))) return [table]
def chromosomes_table(species): table = nodes.table() tgroup = nodes.tgroup(cols=2) colspec = nodes.colspec(colwidth=1) tgroup.append(colspec) colspec = nodes.colspec(colwidth=1) tgroup.append(colspec) table += tgroup thead = nodes.thead() tgroup += thead row = nodes.row() entry = nodes.entry() entry += nodes.paragraph(text="Name") row += entry entry = nodes.entry() entry += nodes.paragraph(text="Length") row += entry thead.append(row) rows = [] for chrom in species.genome.chromosomes: row = nodes.row() entry = nodes.entry() entry += nodes.paragraph(text=chrom.id) row += entry entry = nodes.entry() entry += nodes.paragraph(text="{:d}".format(chrom.length)) row += entry # TODO add mutation/recombination rate. rows.append(row) tbody = nodes.tbody() tbody.extend(rows) tgroup += tbody return table
def _build_grade_listing(self, matrix, content): summarytitle = nodes.title(text="Grades") content.append(summarytitle) table = nodes.table() grades = matrix.grades tablegroup = nodes.tgroup(cols=2) summarybody = nodes.tbody() summaryhead = nodes.thead() for i in range(2): tablegroup.append(nodes.colspec(colwidth=1)) tablegroup.append(summaryhead) tablegroup.append(summarybody) table.append(tablegroup) content.append(table) header = nodes.row() blank = nodes.entry() blank.append(nodes.strong(text="Grade")) header.append(blank) blank = nodes.entry() blank.append(nodes.strong(text="Description")) header.append(blank) summaryhead.append(header) for grade in grades: item = nodes.row() namecol = nodes.entry() namecol.append(nodes.paragraph(text=grade.title)) item.append(namecol) notescol = nodes.entry() notescol.append(nodes.paragraph(text=grade.notes)) item.append(notescol) summarybody.append(item) return content
def buildTableNode(self): colwidths = self.directive.get_column_widths(self.max_cols) if isinstance(colwidths, tuple): # Since docutils 0.13, get_column_widths returns a (widths, # colwidths) tuple, where widths is a string (i.e. 'auto'). # See https://sourceforge.net/p/docutils/patches/120/. colwidths = colwidths[1] stub_columns = self.directive.options.get('stub-columns', 0) header_rows = self.directive.options.get('header-rows', 0) table = nodes.table() tgroup = nodes.tgroup(cols=len(colwidths)) table += tgroup for colwidth in colwidths: colspec = nodes.colspec(colwidth=colwidth) # FIXME: It seems, that the stub method only works well in the # absence of rowspan (observed by the html buidler, the docutils-xml # build seems OK). This is not extraordinary, because there exists # no table directive (except *this* flat-table) which allows to # define coexistent of rowspan and stubs (there was no use-case # before flat-table). This should be reviewed (later). if stub_columns: colspec.attributes['stub'] = 1 stub_columns -= 1 tgroup += colspec stub_columns = self.directive.options.get('stub-columns', 0) if header_rows: thead = nodes.thead() tgroup += thead for row in self.rows[:header_rows]: thead += self.buildTableRowNode(row) tbody = nodes.tbody() tgroup += tbody for row in self.rows[header_rows:]: tbody += self.buildTableRowNode(row) return table
def gene_table(list2d, title=None, colwidths=None, rows_highlight=[], classes=[], _baseclass='neorg-gene-table', rows_highlight_class='neorg-gene-table-rows-highlight'): """ Generate table node from 2D list """ allclasses = [_baseclass] + classes if not list2d: table = nodes.table() table['classes'] += allclasses return table nrow = len(list2d) ncol = len(list2d[0]) if colwidths is None: colwidths = [1] * ncol table = nodes.table() tgroup = nodes.tgroup(cols=ncol) tbody = nodes.tbody() colspecs = [nodes.colspec(colwidth=cw) for cw in colwidths] rows = [nodes.row() for dummy in range(nrow)] if title: table += nodes.title(title, title) table += tgroup tgroup += colspecs tgroup += tbody tbody += rows for (row, list1d) in zip(rows, list2d): row += [gene_entry(elem) for elem in list1d] for (i, row) in enumerate(rows): if i in rows_highlight: row['classes'].append(rows_highlight_class) table['classes'] += allclasses return table
def env_vars_to_table(env_vars, ci): table = nodes.table() tgroup = nodes.tgroup(cols=3) table += tgroup colspec = nodes.colspec() tgroup += colspec tgroup += colspec tgroup += colspec thead = nodes.thead() tgroup += thead row = nodes.row() row += nodes.entry("", nodes.paragraph(text="ENV-VARS")) row += nodes.entry("", nodes.paragraph(text="Required?")) row += nodes.entry("", nodes.paragraph(text="Notes")) thead += row tbody = nodes.tbody() for env_var in env_vars: row = nodes.row() row += nodes.entry("", nodes.paragraph(text=env_var.name)) if env_var.is_required(ci): required = 'yes' else: required = 'no' row += nodes.entry("", nodes.paragraph(text=required)) notes = env_var.notes(ci) if notes == "<FINGERPRINT_LINK>": ref = "../../fingerprints/docker_fingerprint.html" para = nodes.paragraph(text="") para += nodes.reference('', 'Fingerprint', internal=False, refuri=ref) row += nodes.entry("", para) else: row += nodes.entry("", nodes.paragraph(text=notes)) tbody += row tgroup += tbody return table
def build_table(self, table_data, col_widths): table = nodes.table() # Set up the column specifications # based on the widths. tgroup = nodes.tgroup(cols=len(self.HEADERS)) table += tgroup tgroup.extend(nodes.colspec(colwidth=col_width) for col_width in col_widths) # Set the headers thead = nodes.thead() tgroup += thead row_node = nodes.row() thead += row_node row_node.extend( nodes.entry(h, nodes.paragraph(text=h)) for h in self.HEADERS ) # The body of the table is made up of rows. # Each row contains a series of entries, # and each entry contains a paragraph of text. tbody = nodes.tbody() tgroup += tbody rows = [] for row in table_data: trow = nodes.row() # Iterate over the headers in the same order every time. for h in self.HEADERS: # Get the cell value from the row data, replacing None # in re match group with empty string. cell = row.get(self.HEADER_MAP[h]) or '' entry = nodes.entry() para = nodes.paragraph(text=str(cell)) entry += para trow += entry rows.append(trow) tbody.extend(rows) return table
def models_table(self, species): table = nodes.table() tgroup = nodes.tgroup(cols=2) for _ in range(2): colspec = nodes.colspec(colwidth=1) tgroup.append(colspec) table += tgroup thead = nodes.thead() tgroup += thead row = nodes.row() entry = nodes.entry() entry += nodes.paragraph(text="ID") row += entry entry = nodes.entry() entry += nodes.paragraph(text="Description") row += entry thead.append(row) rows = [] for model in species.demographic_models: row = nodes.row() rows.append(row) mid = self.get_demographic_model_id(species, model) entry = nodes.entry() para = nodes.paragraph() entry += para para += nodes.reference(internal=True, refid=mid, text=model.id) row += entry entry = nodes.entry() entry += nodes.paragraph(text=model.description) row += entry tbody = nodes.tbody() tbody.extend(rows) tgroup += tbody return table
def run(self): tree = self.state.document.settings.env.app.doxyxml table = nodes.table() tgroup = nodes.tgroup(cols=2) tgroup += nodes.colspec(colwidth=50) tgroup += nodes.colspec(colwidth=50) # header tgroup += nodes.thead( '', nodes.row( '', *[ nodes.entry('', nodes.line(text=c)) for c in ["Function", "Description"] ])) # rows tbody = nodes.tbody() for c in self.content: name = c.strip() query = name.replace("&", " &") for elem in tree.findall( "./compounddef/sectiondef/memberdef/[name='%s']" % query): args = ', '.join(e.text for e in elem.findall("./param/declname")) ref = addnodes.pending_xref('', refdomain='cpp', refexplicit=False, reftype='func', reftarget='percy::' + name) ref += nodes.literal(text='%s(%s)' % (name, args)) reft = nodes.paragraph() reft.extend([ref]) func = nodes.entry('', reft) desc = nodes.entry( '', nodes.line(text=elem.findtext("./briefdescription/para"))) tbody += nodes.row('', func, desc) tgroup += tbody table += tgroup return [table]
def table(item, state): """Build the arguments table""" # Set up the column specifications # based on the widths. col_widths = [300, 300, 300] ntable = nodes.table(align='left') ngroup = nodes.tgroup(cols=len(TABLE_HEADERS)) ntable += ngroup ngroup.extend( nodes.colspec(colwidth=col_width) for col_width in col_widths) # Set the table headers nhead = nodes.thead() ngroup += nhead head_row = nodes.row() nhead += head_row head_row.extend( nodes.entry(header, nodes.paragraph(text=header)) for header in TABLE_HEADERS) tbody = nodes.tbody() ngroup += tbody rows = [] for key, value in item[1].args.items(): trow = nodes.row() row = [str(key), str(value.type), str(value.description)] for cell in row: rst = ViewList() entry = nodes.entry(cell) rst.append(cell, 'schema.rst', 0) nested_parse_with_titles(state, rst, entry) # parse rst markup trow += entry rows.append(trow) tbody.extend(rows) return ntable
def _build_property_table(data): header = ( nodes.paragraph(text='Name'), nodes.paragraph(text='Type'), nodes.paragraph(text='Default Value'), nodes.paragraph(text='Description') ) colwidths = (1, 1, 1, 1) table = nodes.table() tgroup = nodes.tgroup(cols=len(header)) table += tgroup for colwidth in colwidths: tgroup += nodes.colspec(colwidth=colwidth) thead = nodes.thead() tgroup += thead thead += create_table_row(header) tbody = nodes.tbody() tgroup += tbody for data_row in data: tbody += create_table_row(data_row) return [table]
def run(self): doc = ET.parse("doxyxml/xml/{}.xml".format(self.arguments[0])) table = nodes.table() tgroup = nodes.tgroup(cols=2) tgroup += nodes.colspec(colwidth=50) tgroup += nodes.colspec(colwidth=50) # header colname = self.options.get('column', "Function") tgroup += nodes.thead( '', nodes.row( '', *[ nodes.entry('', nodes.line(text=c)) for c in [colname, "Description"] ])) # rows tbody = nodes.tbody() for target in self.content: for elem in doc.findall( "./compounddef/sectiondef/memberdef/[name='%s']" % target): ref = nodes.reference('', target, internal=True) ref['refuri'] = '#{}'.format(elem.attrib["id"]) reft = nodes.paragraph() reft.extend([ref]) func = nodes.entry('', reft) desc = nodes.entry( '', nodes.line(text=elem.findtext("./briefdescription/para"))) tbody += nodes.row('', func, desc) tgroup += tbody table += tgroup return [table]
def run(self) -> List[Node]: ncolumns = self.options.get('columns', 2) node = addnodes.compact_paragraph() node.document = self.state.document self.state.nested_parse(self.content, self.content_offset, node) if len(node.children) != 1 or not isinstance(node.children[0], nodes.bullet_list): reporter = self.state.document.reporter raise SphinxError('table_from_list content is not a list') fulllist = node.children[0] # fill list with empty items to have a number of entries # that is divisible by ncolumns if (len(fulllist) % ncolumns) != 0: missing = int(ncolumns - (len(fulllist) % ncolumns)) for i in range(0, missing): fulllist += list_item() table = nodes.table() tgroup = nodes.tgroup(cols=ncolumns) table += tgroup for i in range(ncolumns): tgroup += nodes.colspec(colwidth=1) tbody = nodes.tbody() tgroup += tbody current_row = nodes.row() for idx, cell in enumerate(fulllist.children): if len(current_row.children) == ncolumns: tbody += current_row current_row = nodes.row() entry = nodes.entry() current_row += entry if len(cell.children) > 0: entry += cell.children[0] tbody += current_row return [table]
def build_table(self, table_data, col_widths, headers): table = nodes.table() # Set up the column specifications # based on the widths. tgroup = nodes.tgroup(cols=len(col_widths)) table += tgroup tgroup.extend(nodes.colspec(colwidth=col_width) for col_width in col_widths) # Add headers, if given. if headers: thead = nodes.thead() tgroup += thead row_node = nodes.row() thead += row_node row_node.extend( nodes.entry(h, nodes.paragraph(text=h)) for h in headers ) # The body of the table is made up of rows. # Each row contains a series of entries, # and each entry contains a paragraph of text. tgroup += nodes.tbody( '', *[ nodes.row( '', *[nodes.entry( cell, nodes.paragraph(text=cell) ) for cell in row] ) for row in table_data ] ) #print table return table
def run(self): # table = nodes.table() dilution = self.options.get('dilution', None) num_cols = 3 if dilution else 2 col_widths = self.get_column_widths(num_cols) tgroup = nodes.tgroup(cols=num_cols) table += tgroup for w in col_widths: colspec = nodes.colspec() colspec['colwidth'] = w tgroup += colspec thead = nodes.thead() title = self.options.get('title', 'Strain') if dilution: thead += make_row(title, f'OD600/{dilution}', 'OD600') else: thead += make_row(title, 'OD600') tbody = nodes.tbody() for line in self.content: strain, od = line.split(':') if dilution: real_od = f'{float(dilution) * float(od):0.3f}' tbody += make_row(strain, od, real_od) else: tbody += make_row(strain, od) tgroup += thead tgroup += tbody alignments = ['left'] + (num_cols - 1) * ['right'] align_cols(table, *alignments) return [table]
def visit_enumerated_list(self, node): children = [] for child in node.children: if isinstance(child, nodes.list_item) and len(child.children): children.append(child) if not len(children): return suffix = self.list_suffix if self.list_suffix != None else '' self.list_level += 1 n = number('list' + str(self.list_level), self.project, self.storage) if n: if node.hasattr('ids'): for node_id in node['ids']: self.refs[node_id] = n newnode = nodes.table() newnode['classes'] = ['item-list'] tgroup = nodes.tgroup(cols=2) newnode += tgroup tbody = nodes.tbody() tgroup += tbody i = 0 for child in children: self.__process_list_in_children(child.children) trow = nodes.row() tbody += trow tentry1 = nodes.entry() trow += tentry1 tpar = nodes.paragraph(text=n + suffix) tpar['classes'] = ['item-list-number'] tentry1 += tpar tentry2 = nodes.entry() trow += tentry2 tentry2 += child.children i += 1 if i < len(children): n = number('list' + str(self.list_level), self.project, self.storage) node.replace_self(newnode) self.list_level -= 1