author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Thu, 14 Oct 2010 00:10:07 +0200 | |
changeset 6486 | 2b3fa6fb647b |
parent 6120 | c000e41316ec |
permissions | -rw-r--r-- |
5470
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
1 |
Javascript docstrings |
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
2 |
===================== |
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
3 |
|
6120
c000e41316ec
[book] some more documentation and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5470
diff
changeset
|
4 |
Whereas in Python source code we only need to include a module docstrings |
c000e41316ec
[book] some more documentation and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5470
diff
changeset
|
5 |
using the directive `.. automodule:: mypythonmodule`, we will have to |
5470
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
6 |
explicitely define Javascript modules and functions in the doctrings since |
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
7 |
there is no native directive to include Javascript files. |
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
8 |
|
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
9 |
Rest generation |
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
10 |
--------------- |
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
11 |
|
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
12 |
`pyjsrest` is a small utility parsing Javascript doctrings and generating the |
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
13 |
corresponding Restructured file used by Sphinx to generate HTML documentation. |
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
14 |
This script will have the following structure:: |
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
15 |
|
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
16 |
=========== |
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
17 |
filename.js |
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
18 |
=========== |
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
19 |
.. module:: filename.js |
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
20 |
|
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
21 |
We use the `.. module::` directive to register a javascript library |
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
22 |
as a Python module for Sphinx. This provides an entry in the module index. |
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
23 |
|
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
24 |
The contents of the docstring found in the javascript file will be added as is |
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
25 |
following the module declaration. No treatment will be done on the doctring. |
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
26 |
All the documentation structure will be in the docstrings and will comply |
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
27 |
with the following rules. |
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
28 |
|
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
29 |
Docstring structure |
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
30 |
------------------- |
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
31 |
|
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
32 |
Basically we document javascript with RestructuredText docstring |
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
33 |
following the same convention as documenting Python code. |
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
34 |
|
6120
c000e41316ec
[book] some more documentation and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5470
diff
changeset
|
35 |
The doctring in Javascript files must be contained in standard |
5470
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
36 |
Javascript comment signs, starting with `/**` and ending with `*/`, |
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
37 |
such as:: |
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
38 |
|
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
39 |
/** |
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
40 |
* My comment starts here. |
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
41 |
* This is the second line prefixed with a `*`. |
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
42 |
* ... |
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
43 |
* ... |
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
44 |
* All the follwing line will be prefixed with a `*` followed by a space. |
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
45 |
* ... |
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
46 |
* ... |
6120
c000e41316ec
[book] some more documentation and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5470
diff
changeset
|
47 |
*/ |
5470
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
48 |
|
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
49 |
|
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
50 |
Comments line prefixed by `//` will be ignored. They are reserved for source |
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
51 |
code comments dedicated to developers. |
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
52 |
|
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
53 |
|
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
54 |
Javscript functions docstring |
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
55 |
----------------------------- |
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
56 |
|
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
57 |
By default, the `function` directive describes a module-level function. |
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
58 |
|
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
59 |
`function` directive |
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
60 |
~~~~~~~~~~~~~~~~~~~~ |
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
61 |
|
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
62 |
Its purpose is to define the function prototype such as:: |
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
63 |
|
6120
c000e41316ec
[book] some more documentation and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5470
diff
changeset
|
64 |
.. function:: loadxhtml(url, data, reqtype, mode) |
5470
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
65 |
|
6120
c000e41316ec
[book] some more documentation and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5470
diff
changeset
|
66 |
If any namespace is used, we should add it in the prototype for now, |
c000e41316ec
[book] some more documentation and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5470
diff
changeset
|
67 |
until we define an appropriate directive:: |
c000e41316ec
[book] some more documentation and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5470
diff
changeset
|
68 |
|
c000e41316ec
[book] some more documentation and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5470
diff
changeset
|
69 |
.. function:: jQuery.fn.loadxhtml(url, data, reqtype, mode) |
5470
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
70 |
|
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
71 |
Function parameters |
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
72 |
~~~~~~~~~~~~~~~~~~~ |
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
73 |
|
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
74 |
We will define function parameters as a bulleted list, where the |
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
75 |
parameter name will be backquoted and followed by its description. |
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
76 |
|
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
77 |
Example of a javascript function docstring:: |
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
78 |
|
6120
c000e41316ec
[book] some more documentation and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5470
diff
changeset
|
79 |
.. function:: loadxhtml(url, data, reqtype, mode) |
5470
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
80 |
|
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
81 |
cubicweb loadxhtml plugin to make jquery handle xhtml response |
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
82 |
|
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
83 |
fetches `url` and replaces this's content with the result |
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
84 |
|
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
85 |
Its arguments are: |
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
86 |
|
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
87 |
* `url` |
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
88 |
|
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
89 |
* `mode`, how the replacement should be done (default is 'replace') |
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
90 |
Possible values are : |
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
91 |
- 'replace' to replace the node's content with the generated HTML |
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
92 |
- 'swap' to replace the node itself with the generated HTML |
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
93 |
- 'append' to append the generated HTML to the node's content |
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
94 |
|
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
95 |
|
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
96 |
Optional parameter specification |
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
97 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
98 |
|
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
99 |
Javascript functions handle arguments not listed in the function signature. |
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
100 |
In the javascript code, they will be flagged using `/* ... */`. In the docstring, |
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
101 |
we flag those optional arguments the same way we would define it in |
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
102 |
Python:: |
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
103 |
|
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
104 |
.. function:: asyncRemoteExec(fname, arg1=None, arg2=None) |
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
105 |
|
fb004819cab4
[book] add generated js documentation to cw book
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
diff
changeset
|
106 |