diff options
| author | Georg Brandl <georg@python.org> | 2010-04-08 21:33:03 +0200 |
|---|---|---|
| committer | Georg Brandl <georg@python.org> | 2010-04-08 21:33:03 +0200 |
| commit | 8d364b9412fd250d870d61687f8de23df424a6c8 (patch) | |
| tree | daac2723608eedb5664347ca4f8626849a21437a | |
| parent | f81045bdbe33f45810ddb208df986ad702596a30 (diff) | |
| download | sphinx-8d364b9412fd250d870d61687f8de23df424a6c8.tar.gz | |
Review of JS domain. Adapt coding style a bit.
| -rw-r--r-- | doc/domains.rst | 42 | ||||
| -rw-r--r-- | sphinx/domains/__init__.py | 2 | ||||
| -rw-r--r-- | sphinx/domains/javascript.py | 21 |
3 files changed, 36 insertions, 29 deletions
diff --git a/doc/domains.rst b/doc/domains.rst index f48c9516..851a7124 100644 --- a/doc/domains.rst +++ b/doc/domains.rst @@ -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: diff --git a/sphinx/domains/__init__.py b/sphinx/domains/__init__.py index 50c36f4a..7f9b9ea0 100644 --- a/sphinx/domains/__init__.py +++ b/sphinx/domains/__init__.py @@ -248,5 +248,5 @@ BUILTIN_DOMAINS = { 'py': PythonDomain, 'c': CDomain, 'cpp': CPPDomain, - "js": JavaScriptDomain, + 'js': JavaScriptDomain, } diff --git a/sphinx/domains/javascript.py b/sphinx/domains/javascript.py index d04c101d..3924456b 100644 --- a/sphinx/domains/javascript.py +++ b/sphinx/domains/javascript.py @@ -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), |
