diff options
| author | Georg Brandl <georg@python.org> | 2009-10-27 19:42:44 +0100 |
|---|---|---|
| committer | Georg Brandl <georg@python.org> | 2009-10-27 19:42:44 +0100 |
| commit | 61560f1882023c3d9c21cbf2546b0548e36cdb3b (patch) | |
| tree | cc1c949b1320839c2c6c85f373a731ee481319f4 | |
| parent | cef1a0c504f3ff8e5f6def978b3ba86d6b02fbec (diff) | |
| download | sphinx-61560f1882023c3d9c21cbf2546b0548e36cdb3b.tar.gz | |
Automatically convert directive functions, and add a test for that.
| -rw-r--r-- | sphinx/application.py | 7 | ||||
| -rw-r--r-- | sphinx/domains/__init__.py | 1 | ||||
| -rw-r--r-- | tests/root/conf.py | 16 | ||||
| -rw-r--r-- | tests/root/contents.txt | 1 | ||||
| -rw-r--r-- | tests/root/extapi.txt | 10 | ||||
| -rw-r--r-- | tests/test_build_html.py | 4 |
6 files changed, 35 insertions, 4 deletions
diff --git a/sphinx/application.py b/sphinx/application.py index 4d861a69..af10bb7e 100644 --- a/sphinx/application.py +++ b/sphinx/application.py @@ -18,7 +18,8 @@ from os import path from cStringIO import StringIO from docutils import nodes -from docutils.parsers.rst import Directive, directives, roles +from docutils.parsers.rst import Directive, convert_directive_function, \ + directives, roles import sphinx from sphinx import package_dir, locale @@ -341,9 +342,9 @@ class Sphinx(object): return obj else: obj.content = content - obj.arguments = arguments + obj.arguments = arguments or (0, 0, False) obj.options = options - return obj + return convert_directive_function(obj) def add_directive(self, name, obj, content=None, arguments=None, **options): directives.register_directive( diff --git a/sphinx/domains/__init__.py b/sphinx/domains/__init__.py index 563fd2aa..0ec0622f 100644 --- a/sphinx/domains/__init__.py +++ b/sphinx/domains/__init__.py @@ -112,7 +112,6 @@ class Domain(object): if name not in self.directives: return None fullname = '%s:%s' % (self.name, name) - # XXX what about function-style directives? BaseDirective = self.directives[name] class DirectiveAdapter(BaseDirective): def run(self): diff --git a/tests/root/conf.py b/tests/root/conf.py index d268ae3a..dbb2bca7 100644 --- a/tests/root/conf.py +++ b/tests/root/conf.py @@ -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) diff --git a/tests/root/contents.txt b/tests/root/contents.txt index e1468ad0..2d7ba8fb 100644 --- a/tests/root/contents.txt +++ b/tests/root/contents.txt @@ -11,6 +11,7 @@ Contents: :maxdepth: 2 :numbered: + extapi images subdir/images subdir/includes diff --git a/tests/root/extapi.txt b/tests/root/extapi.txt new file mode 100644 index 00000000..4728e3de --- /dev/null +++ b/tests/root/extapi.txt @@ -0,0 +1,10 @@ +Extension API tests +=================== + +Testing directives: + +.. funcdir:: + :opt: Foo + +.. clsdir:: + :opt: Bar diff --git a/tests/test_build_html.py b/tests/test_build_html.py index 7dfbef5b..dd89ff2e 100644 --- a/tests/test_build_html.py +++ b/tests/test_build_html.py @@ -66,6 +66,10 @@ HTML_XPATH = { ".//dt[@id='test_autodoc.function']/em": r'\*\*kwds', ".//dd": r'Return spam\.', }, + 'extapi.html': { + ".//strong": 'from function: Foo', + ".//strong": 'from class: Bar', + }, 'markup.html': { ".//title": 'set by title directive', ".//p/em": 'Section author: Georg Brandl', |
