mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Review of JS domain. Adapt coding style a bit.
This commit is contained in:
parent
92027ce19f
commit
b2a7db4a81
@ -107,6 +107,7 @@ In short:
|
|||||||
component of the target. For example, ``:py:meth:`~Queue.Queue.get``` will
|
component of the target. For example, ``:py:meth:`~Queue.Queue.get``` will
|
||||||
refer to ``Queue.Queue.get`` but only display ``get`` as the link text.
|
refer to ``Queue.Queue.get`` but only display ``get`` as the link text.
|
||||||
|
|
||||||
|
|
||||||
The Python Domain
|
The Python Domain
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
@ -546,6 +547,7 @@ any domain:
|
|||||||
|
|
||||||
You can set this variable to select a paper size.
|
You can set this variable to select a paper size.
|
||||||
|
|
||||||
|
|
||||||
The JavaScript Domain
|
The JavaScript Domain
|
||||||
---------------------
|
---------------------
|
||||||
|
|
||||||
@ -553,35 +555,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
|
||||||
describe arguments as optional use square brackets as
|
describe arguments as optional use square brackets as :ref:`documented
|
||||||
:ref:`documented <signatures>` for Python signatures.
|
<signatures>` for Python signatures.
|
||||||
|
|
||||||
You can use fields to give more details about arguments and their expected
|
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
|
types, errors which may be thrown by the function, and the value being
|
||||||
returned::
|
returned::
|
||||||
|
|
||||||
.. js:function:: $.getJSON(href, callback[, errback])
|
.. js:function:: $.getJSON(href, callback[, errback])
|
||||||
|
|
||||||
:param string href: An URI to the location of the resource.
|
:param string href: An URI to the location of the resource.
|
||||||
:param callback: Get's called with the object.
|
:param callback: Get's called with the object.
|
||||||
:param errback:
|
:param errback:
|
||||||
Get's called in case the request fails. And a lot of other
|
Get's called in case the request fails. And a lot of other
|
||||||
text so we need multiple lines
|
text so we need multiple lines
|
||||||
:throws SomeError: For whatever reason in that case.
|
:throws SomeError: For whatever reason in that case.
|
||||||
:returns: Something
|
:returns: Something
|
||||||
|
|
||||||
This is rendered as:
|
This is rendered as:
|
||||||
|
|
||||||
.. js:function:: $.getJSON(href, callback[, errback])
|
.. js:function:: $.getJSON(href, callback[, errback])
|
||||||
|
|
||||||
:param string href: An URI to the location of the resource.
|
:param string href: An URI to the location of the resource.
|
||||||
:param callback: Get's called with the object.
|
:param callback: Get's called with the object.
|
||||||
:param errback:
|
:param errback:
|
||||||
Get's called in case the request fails. And a lot of other
|
Get's called in case the request fails. And a lot of other
|
||||||
text so we need multiple lines.
|
text so we need multiple lines.
|
||||||
:throws SomeError: For whatever reason in that case.
|
:throws SomeError: For whatever reason in that case.
|
||||||
:returns: Something
|
:returns: Something
|
||||||
|
|
||||||
.. directive:: .. js:data:: name
|
.. directive:: .. js:data:: name
|
||||||
|
|
||||||
@ -589,7 +591,7 @@ The JavaScript domain (name **js**) provides the following directives:
|
|||||||
|
|
||||||
.. directive:: .. js:attribute:: object.name
|
.. directive:: .. js:attribute:: object.name
|
||||||
|
|
||||||
Describes the attribute `name` of `object`.
|
Describes the attribute *name* of *object*.
|
||||||
|
|
||||||
These roles are provided to refer to the described objects:
|
These roles are provided to refer to the described objects:
|
||||||
|
|
||||||
|
@ -248,5 +248,5 @@ BUILTIN_DOMAINS = {
|
|||||||
'py': PythonDomain,
|
'py': PythonDomain,
|
||||||
'c': CDomain,
|
'c': CDomain,
|
||||||
'cpp': CPPDomain,
|
'cpp': CPPDomain,
|
||||||
"js": JavaScriptDomain,
|
'js': JavaScriptDomain,
|
||||||
}
|
}
|
||||||
|
@ -19,12 +19,14 @@ 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
|
from sphinx.util.docfields import Field, GroupedField, TypedField
|
||||||
|
|
||||||
|
|
||||||
js_sig_re = re.compile(
|
js_sig_re = re.compile(
|
||||||
r'''([^ .]+\.)? # object name
|
r'''([^ .]+\.)? # object name
|
||||||
([^ .]+\s*) # name
|
([^ .]+\s*) # name
|
||||||
\((.*)\)$ # arguments
|
\((.*)\)$ # arguments
|
||||||
''', re.VERBOSE)
|
''', re.VERBOSE)
|
||||||
|
|
||||||
|
|
||||||
class JSObject(ObjectDescription):
|
class JSObject(ObjectDescription):
|
||||||
"""
|
"""
|
||||||
Description of a JavaScript object.
|
Description of a JavaScript object.
|
||||||
@ -120,12 +122,13 @@ class JSObject(ObjectDescription):
|
|||||||
return _('%s (%s attribute)') % (name, obj)
|
return _('%s (%s attribute)') % (name, obj)
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
|
|
||||||
class JSCallable(JSObject):
|
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 = [
|
doc_field_types = [
|
||||||
TypedField("arguments", label=l_('Arguments'),
|
TypedField('arguments', label=l_('Arguments'),
|
||||||
names=('argument', 'arg', 'parameter', 'param'),
|
names=('argument', 'arg', 'parameter', 'param'),
|
||||||
typerolename='func', typenames=('paramtype', 'type')),
|
typerolename='func', typenames=('paramtype', 'type')),
|
||||||
GroupedField('errors', label=l_('Throws'), rolename='err',
|
GroupedField('errors', label=l_('Throws'), rolename='err',
|
||||||
@ -135,6 +138,7 @@ class JSCallable(JSObject):
|
|||||||
names=('returns', 'return')),
|
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
|
||||||
@ -152,20 +156,21 @@ class JSXRefRole(XRefRole):
|
|||||||
refnode['refspecific'] = True
|
refnode['refspecific'] = True
|
||||||
return title, target
|
return title, target
|
||||||
|
|
||||||
|
|
||||||
class JavaScriptDomain(Domain):
|
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
|
# 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_('JavaScript function'), 'func'),
|
||||||
'data' : ObjType(l_('js data'), 'data'),
|
'data': ObjType(l_('JavaScript data'), 'data'),
|
||||||
'attribute' : ObjType(l_('js attribute'), 'attr'),
|
'attribute': ObjType(l_('JavaScript attribute'), 'attr'),
|
||||||
}
|
}
|
||||||
directives = {
|
directives = {
|
||||||
'function' : JSCallable,
|
'function': JSCallable,
|
||||||
'data' : JSObject,
|
'data': JSObject,
|
||||||
'attribute' : JSObject,
|
'attribute': JSObject,
|
||||||
}
|
}
|
||||||
roles = {
|
roles = {
|
||||||
'func': JSXRefRole(fix_parens=True),
|
'func': JSXRefRole(fix_parens=True),
|
||||||
|
Loading…
Reference in New Issue
Block a user