Automatically convert directive functions, and add a test for that.

This commit is contained in:
Georg Brandl
2009-10-27 19:42:44 +01:00
parent 414816bb37
commit 213eba0225
6 changed files with 35 additions and 4 deletions

View File

@@ -58,7 +58,12 @@ autosummary_generate = ['autosummary']
# modify tags from conf.py
tags.add('confpytag')
# -- extension API
from docutils import nodes
from sphinx import addnodes
from sphinx.util.compat import Directive
def userdesc_parse(env, sig, signode):
x, y = sig.split(':')
@@ -67,7 +72,18 @@ def userdesc_parse(env, sig, signode):
signode[-1] += addnodes.desc_parameter(y, y)
return x
def functional_directive(name, arguments, options, content, lineno,
content_offset, block_text, state, state_machine):
return [nodes.strong(text='from function: %s' % options['opt'])]
class ClassDirective(Directive):
option_spec = {'opt': lambda x: x}
def run(self):
return [nodes.strong(text='from class: %s' % self.options['opt'])]
def setup(app):
app.add_config_value('value_from_conf_py', 42, False)
app.add_directive('funcdir', functional_directive, opt=lambda x: x)
app.add_directive('clsdir', ClassDirective)
app.add_description_unit('userdesc', 'userdescrole', '%s (userdesc)',
userdesc_parse)

View File

@@ -11,6 +11,7 @@ Contents:
:maxdepth: 2
:numbered:
extapi
images
subdir/images
subdir/includes

10
tests/root/extapi.txt Normal file
View File

@@ -0,0 +1,10 @@
Extension API tests
===================
Testing directives:
.. funcdir::
:opt: Foo
.. clsdir::
:opt: Bar