|
|
@ -3,8 +3,10 @@
|
|
|
|
# https://www.sphinx-doc.org/en/master/development/tutorials/recipe.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
|
|
|
|
# https://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html#rst-directives
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from typing import List
|
|
|
|
|
|
|
|
|
|
|
|
import docutils.nodes as nodes
|
|
|
|
import docutils.nodes as nodes
|
|
|
|
# import docutils.parsers.rst.directives as rst_directives
|
|
|
|
import docutils.parsers.rst.directives as rst_directives
|
|
|
|
import sphinx
|
|
|
|
import sphinx
|
|
|
|
import sphinx.addnodes as addnodes
|
|
|
|
import sphinx.addnodes as addnodes
|
|
|
|
import sphinx.directives
|
|
|
|
import sphinx.directives
|
|
|
@ -22,27 +24,31 @@ class DFHackToolDirectiveBase(sphinx.directives.ObjectDescription):
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
return self.env.docname.split('/')[-1]
|
|
|
|
return self.env.docname.split('/')[-1]
|
|
|
|
|
|
|
|
|
|
|
|
def make_labeled_paragraph(self, label, content, label_class=nodes.strong, content_class=nodes.inline):
|
|
|
|
@staticmethod
|
|
|
|
|
|
|
|
def make_labeled_paragraph(label, content, label_class=nodes.strong, content_class=nodes.inline) -> nodes.paragraph:
|
|
|
|
return nodes.paragraph('', '', *[
|
|
|
|
return nodes.paragraph('', '', *[
|
|
|
|
label_class('', '{}: '.format(label)),
|
|
|
|
label_class('', '{}: '.format(label)),
|
|
|
|
content_class('', content),
|
|
|
|
content_class('', content),
|
|
|
|
])
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
|
|
def make_nodes(self):
|
|
|
|
@staticmethod
|
|
|
|
|
|
|
|
def wrap_box(*children: List[nodes.Node]) -> nodes.Admonition:
|
|
|
|
|
|
|
|
return nodes.admonition('', *children, classes=['dfhack-tool-summary'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def render_content(self) -> List[nodes.Node]:
|
|
|
|
raise NotImplementedError
|
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
def run(self):
|
|
|
|
return [
|
|
|
|
return [self.wrap_box(*self.render_content())]
|
|
|
|
nodes.admonition('', *self.make_nodes(), classes=['dfhack-tool-summary']),
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class DFHackToolDirective(DFHackToolDirectiveBase):
|
|
|
|
class DFHackToolDirective(DFHackToolDirectiveBase):
|
|
|
|
option_spec = {
|
|
|
|
option_spec = {
|
|
|
|
'tags': dfhack.util.directive_arg_str_list,
|
|
|
|
'tags': dfhack.util.directive_arg_str_list,
|
|
|
|
|
|
|
|
'no-command': rst_directives.flag,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
def make_nodes(self):
|
|
|
|
def render_content(self) -> List[nodes.Node]:
|
|
|
|
tag_nodes = [nodes.strong(text='Tags: ')]
|
|
|
|
tag_nodes = [nodes.strong(text='Tags: ')]
|
|
|
|
for tag in self.options.get('tags', []):
|
|
|
|
for tag in self.options.get('tags', []):
|
|
|
|
tag_nodes += [
|
|
|
|
tag_nodes += [
|
|
|
@ -62,9 +68,15 @@ class DFHackToolDirective(DFHackToolDirectiveBase):
|
|
|
|
nodes.paragraph('', '', *tag_nodes),
|
|
|
|
nodes.paragraph('', '', *tag_nodes),
|
|
|
|
]
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
|
|
|
|
out = DFHackToolDirectiveBase.run(self)
|
|
|
|
|
|
|
|
if 'no-command' not in self.options:
|
|
|
|
|
|
|
|
out += [self.wrap_box(*DFHackCommandDirective.render_content(self))]
|
|
|
|
|
|
|
|
return out
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class DFHackCommandDirective(DFHackToolDirectiveBase):
|
|
|
|
class DFHackCommandDirective(DFHackToolDirectiveBase):
|
|
|
|
def make_nodes(self):
|
|
|
|
def render_content(self) -> List[nodes.Node]:
|
|
|
|
return [
|
|
|
|
return [
|
|
|
|
self.make_labeled_paragraph('Command', self.get_name_or_docname(), content_class=nodes.literal),
|
|
|
|
self.make_labeled_paragraph('Command', self.get_name_or_docname(), content_class=nodes.literal),
|
|
|
|
]
|
|
|
|
]
|
|
|
|