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