docs.js
[gnome.introspection-doc-generator] / docs.js
1 //<Script type="text/javascript">
2
3 Gtk = imports.gi.Gtk;
4 Gio = imports.gi.Gio;
5 Gdk = imports.gi.Gdk;
6
7 imports['Object.js'].load(Object); 
8
9 File        = imports['File.js'].File; 
10 JSDOC       = imports['JSDOC.js'].JSDOC; 
11 console     = imports['console.js'].console; 
12 Introspect  = imports['JSDOC/Introspect.js'].Introspect; 
13
14 var outputdir = Seed.argv[2];
15
16 if (!outputdir) {
17     throw {
18         name: "ArgumentError", 
19         message: "No output directory specified on the command line\n" +
20           "Usage seed docs.js /var/www/seed  [Gtk] \n"
21     };
22 }
23
24 if (!File.isDirectory(outputdir)) {
25     console.log("Creating directory " + outputdir);
26     File.mkdir(outputdir);
27 };
28
29 // list namespace..
30 //var ns_list = [ 'GIRepository' ];
31
32
33
34 var ns_list = JSDOC.Introspect.namespaces();
35 if (typeof(Seed.argv[3]) == 'string') {
36     console.log(Seed.argv.length);
37     ns_list = Seed.argv[3].split(',');
38 }
39  
40 ns_list = ns_list.sort();
41
42 var cls_template = new JSDOC.Template(__script_path__ + '/docs/class.html');
43 var cls_ix_template = new JSDOC.Template(__script_path__ + '/docs/class_ix.html');
44 var reference_template = new JSDOC.Template(__script_path__ + '/docs/references.html');
45 var ns_idx = [];
46 ns_list.map(function(ns_name) 
47 {
48     var  core = imports.gi[ns_name];
49     var idx = { name: ns_name}; 
50     console.log("START:" + ns_name);
51    
52     var ns = Introspect.ns(ns_name);
53     ns['left_bar'] = cls_ix_template.process(ns);
54
55     Gio.simple_write(outputdir + '/'+ ns_name +  '.html', cls_template.process(ns));
56     
57     // left bar index of elements in namespace...
58     Gio.simple_write(outputdir + '/_ix_'+ ns_name +  '.shtml', cls_ix_template.process(ns));
59      
60     
61     var actions = {
62         'objects' : 'Class',
63         'interfaces' : 'Interface',
64         'structs' : 'Struct',
65         'unions' : 'Union',
66         'enums' : 'Enum'
67         
68     };
69     for (var i in actions) {
70         idx[i]= ns[i].length;
71         ns[i].map( function(n) {
72             Gio.simple_write(outputdir + '/'+ ns_name + '.' + n + '.html', 
73                 cls_template.process(
74                     Object.extend(
75                         Introspect.factory(actions[i], ns_name, n),
76                         { 'left_bar' :ns['left_bar'] }
77                     )
78                 )
79             )
80                        
81             console.log(ns_name + '.' +n);
82         }); 
83     }
84     ns_idx.push(idx);
85       
86 });
87
88 var refs = '';
89 var html_file_path = '';
90 var html = ''
91
92
93 for (var i in Introspect.references) {
94     html_file_path = File.join(outputdir, i + '.html');
95   
96     if (i == 'undefined') {
97       console.log("Undefined name space - ignored");
98       continue;
99     }
100     if (!File.isFile(html_file_path)) {
101       console.log("No HTML file " + html_file_path + " to insert references into - ignored");
102       continue;
103     }
104     
105     refs = reference_template.process(Introspect.references[i]);
106
107       // HTML to put refs into
108     html =  File.read(html_file_path);
109
110       // do the replacement
111     html = html.replace(/\<!--references--\>/, refs);
112
113       // write back to file
114     Gio.simple_write(html_file_path, html);
115
116 }
117
118 var ix_template = new JSDOC.Template(__script_path__ + '/docs/index.html');
119 Gio.simple_write(outputdir + '/index.html', ix_template.process(ns_idx));
120 File.silentRecursiveCopy(__script_path__ + '/docs/resources/', outputdir);
121
122
123