Anonymous avatar Anonymous committed 3e798e7

Added a :js:attribute:: directive as well as a :js:attr: role to describe attributes of javascript objects.

Comments (0)

Files changed (3)

 
 .. directive:: .. js:function:: name(signature)
 
-   Describe 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
    :ref:`documented <signatures>` for Python signatures.
 
 .. directive:: .. js:data:: name
 
-   Describe a global variable or constant.
+   Describes a global variable or constant.
+
+.. directive:: .. js:attribute:: object.name
+
+   Describes the attribute `name` of `object`.
 
 These roles are provided to refer to the described objects:
 
 .. role:: js:func
           js:data
+          js:attr

sphinx/domains/javascript.py

         \((.*)\)$ # 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:
         signode['object'] = objectname
         signode['fullname'] = fullname
 
-
         signode += addnodes.desc_name(name, name)
+        if self.has_arguments:
+            signode += addnodes.desc_parameterlist()
         if not arglist:
-            signode += addnodes.desc_parameterlist()
-            return name
+            return fullname, nameprefix
 
         stack = [signode[-1]]
         for token in js_paramlist_re.split(arglist):
                 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()
     }

tests/root/objects.txt

 .. documenting the method of any object
 .. js:function:: bar.baz()
 
+.. js:attribute:: bar.spam
+
 
 References
 ==========
 :js:func:`bar.baz()`
 :js:func:`bar.baz`
 
+:js:attr:`bar.baz`
+
 
 Others
 ======
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.