""" A directive for organization/areas.rst to render the area tables. """ from docutils import nodes from docutils.parsers.rst import Directive import re area_table_rows = ("Communication", "GitHub reviews", "GitHub labels", "Triage project", "Maintainers") channel_re = re.compile(r'#([\w-]+)') godot_team_re = re.compile(r'@godotengine/([\w-]+)') labels_re = re.compile(r'(.+?)') triage_re = re.compile(r'(.*?)') def transform_channels(match: re.Match): old_value = match.group(1) transformed = f'#{old_value}' return transformed def transform_github_teams(match: re.Match): old_value = match.group(1) transformed = f'@godotengine/{old_value}' return transformed def transform_github_labels(match: re.Match): old_value = match.group(1) transformed = f'{old_value} (issues, PRs)' return transformed def transform_github_triage(match: re.Match): number = match.group(1) name = match.group(2) transformed = f'{name}' return transformed class TableDirective(Directive): has_content = False required_arguments = 0 optional_arguments = 0 final_argument_whitespace = False option_spec = {column.lower().replace(" ", "_"): str for column in area_table_rows} def run(self): # Create a table node with the parsed header and data table = nodes.table() table.setdefault('classes', []).append("gdarea-table") tgroup = nodes.tgroup(cols=2) table += tgroup # Set column specifications tgroup += nodes.colspec(colwidth=2) tgroup += nodes.colspec(colwidth=5) # Create and add the table body tbody = nodes.tbody() tgroup += tbody for column_title in area_table_rows: row_text = self.options.get(column_title.lower().replace(" ", "_"), '') if not row_text: continue body_row = nodes.row() entry = nodes.entry() entry.setdefault('classes', []).append("gdarea-table-header") entry += nodes.paragraph(text=column_title) body_row += entry row_text = channel_re.sub(transform_channels, row_text) row_text = godot_team_re.sub(transform_github_teams, row_text) row_text = labels_re.sub(transform_github_labels, row_text) row_text = triage_re.sub(transform_github_triage, row_text) entry = nodes.entry() paragraph = nodes.paragraph() paragraph += nodes.raw('', row_text, format='html') entry += paragraph body_row += entry tbody += body_row return [table] def setup(app): app.add_directive('gdareatable', TableDirective)