tidy up template
[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         // we flag GLib as a GObject lib...
71         idx[i]= ns_name == 'GLib' ? 1 : ns[i].length ;
72         ns[i].map( function(n) {
73             Gio.simple_write(outputdir + '/'+ ns_name + '.' + n + '.html', 
74                 cls_template.process(
75                     Object.extend(
76                         Introspect.factory(actions[i], ns_name, n),
77                         { 'left_bar' :ns['left_bar'] }
78                     )
79                 )
80             )
81                        
82             console.log(ns_name + '.' +n);
83         }); 
84     }
85     ns_idx.push(idx);
86       
87 });
88
89 var refs = '';
90 var html_file_path = '';
91 var html = ''
92
93
94 for (var i in Introspect.references) {
95     html_file_path = File.join(outputdir, i + '.html');
96   
97     if (i == 'undefined') {
98       console.log("Undefined name space - ignored");
99       continue;
100     }
101     if (!File.isFile(html_file_path)) {
102       console.log("No HTML file " + html_file_path + " to insert references into - ignored");
103       continue;
104     }
105     
106     refs = reference_template.process(Introspect.references[i]);
107
108       // HTML to put refs into
109     html =  File.read(html_file_path);
110
111       // do the replacement
112     html = html.replace(/\<!--references--\>/, refs);
113
114       // write back to file
115     Gio.simple_write(html_file_path, html);
116
117 }
118
119 var ix_template = new JSDOC.Template(__script_path__ + '/docs/index.html');
120 Gio.simple_write(outputdir + '/index.html', ix_template.process(ns_idx));
121 File.silentRecursiveCopy(__script_path__ + '/docs/resources/', outputdir);
122
123
124