Review of JS domain. Adapt coding style a bit.

This commit is contained in:
Georg Brandl 2010-04-08 21:33:03 +02:00
parent 92027ce19f
commit b2a7db4a81
3 changed files with 36 additions and 29 deletions

View File

@ -107,6 +107,7 @@ In short:
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.
The Python Domain
-----------------
@ -546,6 +547,7 @@ any domain:
You can set this variable to select a paper size.
The JavaScript Domain
---------------------
@ -553,35 +555,35 @@ The JavaScript domain (name **js**) provides the following directives:
.. directive:: .. js:function:: name(signature)
Describes a JavaScript function, method or constructor. If you want to
describe arguments as optional use square brackets as
:ref:`documented <signatures>` for Python signatures.
Describes a JavaScript function, method or constructor. If you want to
describe arguments as optional use square brackets as :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])
.. 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
: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])
.. 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
: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
@ -589,7 +591,7 @@ The JavaScript domain (name **js**) provides the following directives:
.. 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:

View File

@ -248,5 +248,5 @@ BUILTIN_DOMAINS = {
'py': PythonDomain,
'c': CDomain,
'cpp': CPPDomain,
"js": JavaScriptDomain,
'js': JavaScriptDomain,
}

View File

@ -19,12 +19,14 @@ from sphinx.roles import XRefRole
from sphinx.util.nodes import make_refnode
from sphinx.util.docfields import Field, GroupedField, TypedField
js_sig_re = re.compile(
r'''([^ .]+\.)? # object name
([^ .]+\s*) # name
\((.*)\)$ # arguments
''', re.VERBOSE)
class JSObject(ObjectDescription):
"""
Description of a JavaScript object.
@ -120,12 +122,13 @@ class JSObject(ObjectDescription):
return _('%s (%s attribute)') % (name, obj)
return ''
class JSCallable(JSObject):
"""Description of a JavaScript function, method or constructor."""
has_arguments = True
doc_field_types = [
TypedField("arguments", label=l_('Arguments'),
TypedField('arguments', label=l_('Arguments'),
names=('argument', 'arg', 'parameter', 'param'),
typerolename='func', typenames=('paramtype', 'type')),
GroupedField('errors', label=l_('Throws'), rolename='err',
@ -135,6 +138,7 @@ class JSCallable(JSObject):
names=('returns', 'return')),
]
class JSXRefRole(XRefRole):
def process_link(self, env, refnode, has_explicit_title, title, target):
# basically what sphinx.domains.python.PyXRefRole does
@ -152,20 +156,21 @@ class JSXRefRole(XRefRole):
refnode['refspecific'] = True
return title, target
class JavaScriptDomain(Domain):
"""JavaScript language domain."""
name = 'js'
label= 'JavaScript'
label = 'JavaScript'
# if you add a new object type make sure to edit JSObject.get_index_string
object_types = {
'function' : ObjType(l_('js function'), 'func'),
'data' : ObjType(l_('js data'), 'data'),
'attribute' : ObjType(l_('js attribute'), 'attr'),
'function': ObjType(l_('JavaScript function'), 'func'),
'data': ObjType(l_('JavaScript data'), 'data'),
'attribute': ObjType(l_('JavaScript attribute'), 'attr'),
}
directives = {
'function' : JSCallable,
'data' : JSObject,
'attribute' : JSObject,
'function': JSCallable,
'data': JSObject,
'attribute': JSObject,
}
roles = {
'func': JSXRefRole(fix_parens=True),