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 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
27 if (!File.isDirectory(outputdir)) {
28     console.log("Creating directory " + outputdir);
29     File.mkdir(outputdir);
30 };
31
32  
33 // Which libraries to build.
34
35 var ns_list = Introspect.namespaces();
36 if (typeof(Seed.argv[3]) == 'string') {
37     console.log(Seed.argv.length);
38     ns_list = Seed.argv[3].split(',');
39 }
40
41 ns_list = ns_list.sort();
42
43
44 // which languages do we want to output for.
45 langs=[];
46 File.list(__script_path__ + '/templates/').forEach(function(f) {
47     if (!File.isDirectory(__script_path__ + '/templates/' + f)) {
48         continue;
49     }
50     if (f == 'resources') {
51         continue;
52     }
53     langs.push({
54         name : f,
55         cls_template       : new Template(__script_path__ + '/templates/' + f + '/class.html'),
56         cls_ix_template    : new Template(__script_path__ + '/templates/' + f + '/class_ix.html'),
57         reference_template : new Template(__script_path__ + '/templates/' + f + '/references.html'),
58     });
59 });
60
61
62 /*
63 var cls_template = new Template(__script_path__ + '/templates/class.html');
64 var cls_ix_template = new Template(__script_path__ + '/templates/class_ix.html');
65 var reference_template = new Template(__script_path__ + '/templates/references.html');
66 */
67
68
69 var ns_idx = [];
70 ns_list.forEach(function(ns_name) 
71 {
72     
73     //if (ns_idx.length) {         return ;/* do one - for testing */ } 
74     
75     var  core = imports.gi[ns_name];
76     var idx = { name: ns_name}; 
77     console.log("START:" + ns_name);
78    
79     var ns = Introspect.ns(ns_name);
80     
81     // gir goes in top level...
82     if (File.exists(ns.gir_file)) {
83         File.copyFile(ns.gir_file, outputdir + '/'+ ns.gir_filename, Gio.FileCopyFlags.OVERWRITE);
84     }
85     
86     
87     ns['left_bar'] = cls_ix_template.process(ns);
88
89     langs.forEach(function(lang) {
90         // namespace template
91         Gio.simple_write(outputdir + '/'+ lang.name+ '/' +ns_name +  '.html', lang.cls_template.process(ns));
92         
93         // left bar index of elements in namespace...
94         Gio.simple_write(outputdir + '/'+ lang.name + '/_ix_'+ ns_name +  '.shtml', lang.cls_ix_template.process(ns));
95             
96     });
97      
98     
99     var actions = {
100         'objects' : 'Class',
101         'interfaces' : 'Interface',
102         'structs' : 'Struct',
103         'unions' : 'Union',
104         'enums' : 'Enum'
105         
106     };
107     for (var i in actions) {
108         // we flag GLib as a GObject lib...
109         idx[i]= ns_name == 'GLib' ? 1 : ns[i].length ;
110         ns[i].forEach( function(n) {
111             
112             
113             Gio.simple_write(outputdir + '/'+ ns_name + '.' + n + '.html', 
114                 cls_template.process(
115                     XObject.extend(
116                         Introspect.factory(actions[i], ns_name, n),
117                         { 'left_bar' :ns['left_bar'] }
118                     )
119                 )
120             )
121                        
122             console.log(ns_name + '.' +n);
123         }); 
124     }
125     ns_idx.push(idx);
126     
127 });
128
129 var refs = '';
130 var html_file_path = '';
131 var html = ''
132
133
134 for (var i in Introspect.references) {
135     html_file_path = File.join(outputdir, i + '.html');
136   
137     if (i == 'undefined') {
138       console.log("Undefined name space - ignored");
139       continue;
140     }
141     if (!File.isFile(html_file_path)) {
142       console.log("No HTML file " + html_file_path + " to insert references into - ignored");
143       continue;
144     }
145     
146     refs = reference_template.process(Introspect.references[i]);
147
148       // HTML to put refs into
149     html =  File.read(html_file_path);
150
151       // do the replacement
152     html = html.replace(/\<!--references--\>/, refs);
153
154       // write back to file
155     Gio.simple_write(html_file_path, html);
156
157 }
158
159 var ix_template = new Template(__script_path__ + '/templates/index.html');
160 Gio.simple_write(outputdir + '/index.html', ix_template.process(ns_idx));
161 File.silentRecursiveCopy(__script_path__ + '/templates/resources/', outputdir, Gio.FileCopyFlags.OVERWRITE);