share tag list between tool and commands

so all relevant tag index entries get generated
develop
myk002 2022-09-23 11:13:49 -07:00
parent 5869ba64c8
commit 52011bde7b
No known key found for this signature in database
GPG Key ID: 8A39CA0FA0C16E78
1 changed files with 22 additions and 7 deletions

@ -125,9 +125,13 @@ class DFHackToolDirectiveBase(sphinx.directives.ObjectDescription):
else: else:
return parts[-1] return parts[-1]
def add_index_entry(self, name, tag) -> None: def add_index_entries(self, name) -> None:
indexdata = (name, self.options.get('summary', ''), '', self.env.docname, '', 0) docname = self.env.docname
self.env.domaindata[tag]['objects'].append(indexdata) tags = self.env.domaindata['tag-repo']['doctags'][docname]
indexdata = (name, self.options.get('summary', ''), '', docname, '', 0)
self.env.domaindata['all']['objects'].append(indexdata)
for tag in tags:
self.env.domaindata[tag]['objects'].append(indexdata)
@staticmethod @staticmethod
def wrap_box(*children: List[nodes.Node]) -> nodes.Admonition: def wrap_box(*children: List[nodes.Node]) -> nodes.Admonition:
@ -154,7 +158,9 @@ class DFHackToolDirective(DFHackToolDirectiveBase):
def render_content(self) -> List[nodes.Node]: def render_content(self) -> List[nodes.Node]:
tag_paragraph = self.make_labeled_paragraph('Tags') tag_paragraph = self.make_labeled_paragraph('Tags')
for tag in self.options.get('tags', []): tags = self.options.get('tags', [])
self.env.domaindata['tag-repo']['doctags'][self.env.docname] = tags
for tag in tags:
tag_paragraph += [ tag_paragraph += [
addnodes.pending_xref(tag, nodes.inline(text=tag), **{ addnodes.pending_xref(tag, nodes.inline(text=tag), **{
'reftype': 'ref', 'reftype': 'ref',
@ -165,12 +171,11 @@ class DFHackToolDirective(DFHackToolDirectiveBase):
}), }),
nodes.inline(text=' | '), nodes.inline(text=' | '),
] ]
self.add_index_entry(self.get_name_or_docname(), tag)
tag_paragraph.pop() tag_paragraph.pop()
ret_nodes = [tag_paragraph] ret_nodes = [tag_paragraph]
if 'no-command' in self.options: if 'no-command' in self.options:
self.add_index_entry(self.get_name_or_docname() + ' (plugin)', 'all') self.add_index_entries(self.get_name_or_docname() + ' (plugin)')
ret_nodes += [make_summary(self.env.app.builder, self.options.get('summary', ''))] ret_nodes += [make_summary(self.env.app.builder, self.options.get('summary', ''))]
return ret_nodes return ret_nodes
@ -188,7 +193,7 @@ class DFHackCommandDirective(DFHackToolDirectiveBase):
def render_content(self) -> List[nodes.Node]: def render_content(self) -> List[nodes.Node]:
command = self.get_name_or_docname() command = self.get_name_or_docname()
self.add_index_entry(command, 'all') self.add_index_entries(command)
return [ return [
self.make_labeled_paragraph('Command', command, content_class=nodes.literal), self.make_labeled_paragraph('Command', command, content_class=nodes.literal),
make_summary(self.env.app.builder, self.options.get('summary', '')), make_summary(self.env.app.builder, self.options.get('summary', '')),
@ -196,6 +201,15 @@ class DFHackCommandDirective(DFHackToolDirectiveBase):
] ]
class TagRepoDomain(Domain):
name = 'tag-repo'
label = 'Holds tag associations per document'
initial_data = {'doctags': {}}
def merge_domaindata(self, docnames: List[str], otherdata: Dict) -> None:
self.data['doctags'].update(otherdata['doctags'])
def get_tags(): def get_tags():
groups = {} groups = {}
group_re = re.compile(r'"([^"]+)"') group_re = re.compile(r'"([^"]+)"')
@ -277,6 +291,7 @@ def register(app):
def setup(app): def setup(app):
app.connect('builder-inited', register) app.connect('builder-inited', register)
app.add_domain(TagRepoDomain)
register_index(app, 'all', 'Index of DFHack tools') register_index(app, 'all', 'Index of DFHack tools')
init_tag_indices(app) init_tag_indices(app)