From 8cbdf1ec34cfce4bb6de8fbbf613ffc8f211233b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Neuh=C3=A4user?= Date: Tue, 30 Mar 2010 21:50:48 +0000 Subject: [PATCH] It is now possible to use the js:function:: directive for methods. --- doc/domains.rst | 6 +++--- sphinx/domains/javascript.py | 20 +++++++++++++++++++- tests/root/objects.txt | 5 +++++ 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/doc/domains.rst b/doc/domains.rst index 602f2e414..93ad61501 100644 --- a/doc/domains.rst +++ b/doc/domains.rst @@ -553,9 +553,9 @@ The JavaScript domain (name **js**) provides the following directives: .. directive:: .. js:function:: name(signature) - Describe a JavaScript function. If you want to document optional - arguments use square brackets as :ref:`documented ` for Python - signatures. + Describe a JavaScript function, method or constructor. If you want to + document optional arguments use square brackets as + :ref:`documented ` for Python signatures. .. directive:: .. js:data:: name diff --git a/sphinx/domains/javascript.py b/sphinx/domains/javascript.py index 184ab88af..64280120a 100644 --- a/sphinx/domains/javascript.py +++ b/sphinx/domains/javascript.py @@ -31,7 +31,25 @@ class JSCallable(ObjectDescription): match = js_sig_re.match(sig) if match is None: raise ValueError() - obj, name, arglist = match.groups() + nameprefix, name, arglist = match.groups() + + objectname = self.env.temp_data.get('js:object') + if objectname and nameprefix: + # someone documenting the method of an attribute of the current + # object? shouldn't happen but who knows... + fullname = objectname + '.' + nameprefix + name + elif objectname: + fullname = objectname + '.' + name + elif nameprefix: + fullname = nameprefix + '.' + name + else: + # just a function or constructor + objectname = '' + fullname = '' + + signode['object'] = objectname + signode['fullname'] = fullname + signode += addnodes.desc_name(name, name) if not arglist: diff --git a/tests/root/objects.txt b/tests/root/objects.txt index 37de5f603..00af91014 100644 --- a/tests/root/objects.txt +++ b/tests/root/objects.txt @@ -80,6 +80,9 @@ Javascript items .. js:data:: bar +.. documenting the method of any object +.. js:function:: bar.baz() + References ========== @@ -96,6 +99,8 @@ Without target: :c:func:`CFunction`. :c:func:`!malloc`. :js:func:`foo` :js:data:`bar` +:js:func:`bar.baz()` +:js:func:`bar.baz` Others