mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Added doc_field_types
to :class:JSCallable
, arguments, errors and the return value of JavaScript functions/methods/constructors can now be documented using fields.
This commit is contained in:
parent
f03f8356d1
commit
ae0d464fb1
@ -554,9 +554,35 @@ The JavaScript domain (name **js**) provides the following directives:
|
|||||||
.. directive:: .. js:function:: name(signature)
|
.. directive:: .. js:function:: name(signature)
|
||||||
|
|
||||||
Describes a JavaScript function, method or constructor. If you want to
|
Describes a JavaScript function, method or constructor. If you want to
|
||||||
document optional arguments use square brackets as
|
describe arguments as optional use square brackets as
|
||||||
:ref:`documented <signatures>` for Python signatures.
|
:ref:`documented <signatures>` for Python signatures.
|
||||||
|
|
||||||
|
You can use fields to give more details about arguments and their expected
|
||||||
|
types, errors which may be thrown by the function, and the value being
|
||||||
|
returned::
|
||||||
|
|
||||||
|
.. js:function:: $.getJSON(href, callback[, errback])
|
||||||
|
|
||||||
|
:param string href: An URI to the location of the resource.
|
||||||
|
:param callback: Get's called with the object.
|
||||||
|
:param errback:
|
||||||
|
Get's called in case the request fails. And a lot of other
|
||||||
|
text so we need multiple lines
|
||||||
|
:throws SomeError: For whatever reason in that case.
|
||||||
|
:returns: Something
|
||||||
|
|
||||||
|
This is rendered as:
|
||||||
|
|
||||||
|
.. js:function:: $.getJSON(href, callback[, errback])
|
||||||
|
|
||||||
|
:param string href: An URI to the location of the resource.
|
||||||
|
:param callback: Get's called with the object.
|
||||||
|
:param errback:
|
||||||
|
Get's called in case the request fails. And a lot of other
|
||||||
|
text so we need multiple lines.
|
||||||
|
:throws SomeError: For whatever reason in that case.
|
||||||
|
:returns: Something
|
||||||
|
|
||||||
.. directive:: .. js:data:: name
|
.. directive:: .. js:data:: name
|
||||||
|
|
||||||
Describes a global variable or constant.
|
Describes a global variable or constant.
|
||||||
|
@ -17,6 +17,7 @@ from sphinx.directives import ObjectDescription
|
|||||||
from sphinx.domains.python import py_paramlist_re as js_paramlist_re
|
from sphinx.domains.python import py_paramlist_re as js_paramlist_re
|
||||||
from sphinx.roles import XRefRole
|
from sphinx.roles import XRefRole
|
||||||
from sphinx.util.nodes import make_refnode
|
from sphinx.util.nodes import make_refnode
|
||||||
|
from sphinx.util.docfields import Field, GroupedField, TypedField
|
||||||
|
|
||||||
js_sig_re = re.compile(
|
js_sig_re = re.compile(
|
||||||
r'''([^ .]+\.)? # object name
|
r'''([^ .]+\.)? # object name
|
||||||
@ -122,6 +123,17 @@ class JSCallable(JSObject):
|
|||||||
"""Description of a JavaScript function, method or constructor."""
|
"""Description of a JavaScript function, method or constructor."""
|
||||||
has_arguments = True
|
has_arguments = True
|
||||||
|
|
||||||
|
doc_field_types = [
|
||||||
|
TypedField("arguments", label=l_('Arguments'),
|
||||||
|
names=('argument', 'arg', 'parameter', 'param'),
|
||||||
|
typerolename='func', typenames=('paramtype', 'type')),
|
||||||
|
GroupedField('errors', label=l_('Throws'), rolename='err',
|
||||||
|
names=('throws', ),
|
||||||
|
can_collapse=True),
|
||||||
|
Field('returnvalue', label=l_('Returns'), has_arg=False,
|
||||||
|
names=('returns', 'return')),
|
||||||
|
]
|
||||||
|
|
||||||
class JSXRefRole(XRefRole):
|
class JSXRefRole(XRefRole):
|
||||||
def process_link(self, env, refnode, has_explicit_title, title, target):
|
def process_link(self, env, refnode, has_explicit_title, title, target):
|
||||||
# basically what sphinx.domains.python.PyXRefRole does
|
# basically what sphinx.domains.python.PyXRefRole does
|
||||||
@ -143,6 +155,7 @@ class JavaScriptDomain(Domain):
|
|||||||
"""JavaScript language domain."""
|
"""JavaScript language domain."""
|
||||||
name = 'js'
|
name = 'js'
|
||||||
label= 'JavaScript'
|
label= 'JavaScript'
|
||||||
|
# if you add a new object type make sure to edit JSObject.get_index_string
|
||||||
object_types = {
|
object_types = {
|
||||||
'function' : ObjType(l_('js function'), 'func'),
|
'function' : ObjType(l_('js function'), 'func'),
|
||||||
'data' : ObjType(l_('js data'), 'data'),
|
'data' : ObjType(l_('js data'), 'data'),
|
||||||
|
@ -81,11 +81,15 @@ Javascript items
|
|||||||
.. js:data:: bar
|
.. js:data:: bar
|
||||||
|
|
||||||
.. documenting the method of any object
|
.. documenting the method of any object
|
||||||
.. js:function:: bar.baz()
|
.. js:function:: bar.baz(href, callback[, errback])
|
||||||
|
|
||||||
|
:param string href: The location of the resource.
|
||||||
|
:param callback: Get's called with the data returned by the resource.
|
||||||
|
:throws InvalidHref: If the `href` is invalid.
|
||||||
|
:returns: `undefined`
|
||||||
|
|
||||||
.. js:attribute:: bar.spam
|
.. js:attribute:: bar.spam
|
||||||
|
|
||||||
|
|
||||||
References
|
References
|
||||||
==========
|
==========
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user