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