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