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