2022-07-27 00:17:21 -06:00
|
|
|
# useful references:
|
|
|
|
# https://www.sphinx-doc.org/en/master/extdev/appapi.html
|
|
|
|
# https://www.sphinx-doc.org/en/master/development/tutorials/recipe.html
|
|
|
|
# https://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html#rst-directives
|
|
|
|
|
|
|
|
import docutils.nodes as nodes
|
|
|
|
# import docutils.parsers.rst.directives as rst_directives
|
|
|
|
import sphinx
|
|
|
|
import sphinx.directives
|
|
|
|
|
|
|
|
import dfhack.util
|
|
|
|
|
|
|
|
class DFHackToolDirective(sphinx.directives.ObjectDescription):
|
|
|
|
has_content = False
|
2022-08-06 14:24:56 -06:00
|
|
|
required_arguments = 0
|
2022-07-27 00:17:21 -06:00
|
|
|
option_spec = {
|
|
|
|
'tags': dfhack.util.directive_arg_str_list,
|
|
|
|
}
|
|
|
|
|
|
|
|
def run(self):
|
2022-08-06 14:24:56 -06:00
|
|
|
if self.arguments:
|
|
|
|
tool_name = self.arguments[0]
|
|
|
|
else:
|
|
|
|
tool_name = self.env.docname.split('/')[-1]
|
2022-07-27 00:17:21 -06:00
|
|
|
|
|
|
|
tag_nodes = [nodes.strong(text='Tags: ')]
|
2022-07-27 20:02:08 -06:00
|
|
|
for tag in self.options.get('tags', []):
|
2022-07-27 00:17:21 -06:00
|
|
|
tag_nodes += [
|
|
|
|
nodes.literal(tag, tag),
|
|
|
|
nodes.inline(text=' | '),
|
|
|
|
]
|
|
|
|
tag_nodes.pop()
|
|
|
|
|
|
|
|
return [
|
2022-08-06 14:59:45 -06:00
|
|
|
nodes.admonition('', *[
|
|
|
|
nodes.paragraph('', '', *[
|
|
|
|
nodes.strong('', 'Tool: '),
|
|
|
|
nodes.inline('', tool_name),
|
|
|
|
]),
|
|
|
|
nodes.paragraph('', '', *tag_nodes),
|
|
|
|
], classes=['dfhack-tool-summary']),
|
2022-07-27 00:17:21 -06:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
def register(app):
|
|
|
|
app.add_directive('dfhack-tool', DFHackToolDirective)
|
|
|
|
|
|
|
|
def setup(app):
|
|
|
|
app.connect('builder-inited', register)
|
|
|
|
|
|
|
|
return {
|
|
|
|
'version': '0.1',
|
|
|
|
'parallel_read_safe': True,
|
|
|
|
'parallel_write_safe': True,
|
|
|
|
}
|