diff options
author | Daniel Neuhäuser <ich@danielneuhaeuser.de> | 2010-03-30 22:22:57 +0000 |
---|---|---|
committer | Daniel Neuhäuser <ich@danielneuhaeuser.de> | 2010-03-30 22:22:57 +0000 |
commit | 5831add5bbc8039be34499d0283efcc026d1f65d (patch) | |
tree | 9e3f25902a2ec0d75679ef65d3abcefc3bf72f1d /sphinx/domains/javascript.py | |
parent | 8cbdf1ec34cfce4bb6de8fbbf613ffc8f211233b (diff) | |
download | sphinx-git-5831add5bbc8039be34499d0283efcc026d1f65d.tar.gz |
Added a :js:attribute:: directive as well as a :js:attr: role to describe attributes of javascript objects.
Diffstat (limited to 'sphinx/domains/javascript.py')
-rw-r--r-- | sphinx/domains/javascript.py | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/sphinx/domains/javascript.py b/sphinx/domains/javascript.py index 64280120a..ffa3fb26d 100644 --- a/sphinx/domains/javascript.py +++ b/sphinx/domains/javascript.py @@ -23,10 +23,12 @@ js_sig_re = re.compile( \((.*)\)$ # arguments ''', re.VERBOSE) -class JSCallable(ObjectDescription): +class JSObject(ObjectDescription): """ - Description of a JavaScript function. + Description of a JavaScript object. """ + has_arguments = False + def handle_signature(self, sig, signode): match = js_sig_re.match(sig) if match is None: @@ -50,11 +52,11 @@ class JSCallable(ObjectDescription): signode['object'] = objectname signode['fullname'] = fullname - signode += addnodes.desc_name(name, name) - if not arglist: + if self.has_arguments: signode += addnodes.desc_parameterlist() - return name + if not arglist: + return fullname, nameprefix stack = [signode[-1]] for token in js_paramlist_re.split(arglist): @@ -74,26 +76,28 @@ class JSCallable(ObjectDescription): stack[-1] += addnodes.desc_parameter(token, token) if len(stack) != 1: raise ValueError() - return name + return fullname, nameprefix -class JSData(ObjectDescription): - """Describes a global variable or constant.""" - def handle_signature(self, sig, signode): - return sig.strip() +class JSCallable(JSObject): + """Description of a JavaScript function, method or constructor.""" + has_arguments = True class JavaScriptDomain(Domain): """JavaScript language domain.""" name = "js" label= "JavaScript" object_types = { - "function": ObjType(l_("js function"), "func"), - "data": ObjType(l_("js data"), "data"), + "function" : ObjType(l_("js function"), "func"), + "data" : ObjType(l_("js data"), "data"), + "attribute" : ObjType(l_("js attribute"), "attr"), } directives = { - "function": JSCallable, - "data": JSData, + "function" : JSCallable, + "data" : JSObject, + "attribute" : JSObject, } roles = { "func": XRefRole(fix_parens=True), "data": XRefRole(), + "attr": XRefRole() } |