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                 { 'left_bar' :ns['left_bar'] }
137             );
138             
139             langs.forEach(function(lang) {
140                 Gio.simple_write(outputdir +  '/'+ lang.name + '/' + ns_name + '.' + n + '.html', 
141                     lang.cls_template.process(odata)
142                 )
143             });
144             console.log(ns_name + '.' +n);
145         }); 
146     }
147     ns_idx.push(idx);
148     
149 });
150
151 var refs = '';
152 var html_file_path = '';
153 var html = ''
154
155 // output cross reference data..
156 langs.forEach(function(lang) {
157     
158     for (var i in NameSpace.references) {
159         
160         html_file_path = [ outputdir, lang.name, i + '.html'].join('/');
161       
162         if (i == 'undefined') {
163           console.log("Undefined name space - ignored");
164           continue;
165         }
166         
167         if (!File.isFile(html_file_path)) {
168           console.log("No HTML file " + html_file_path + " to insert references into - ignored");
169           continue;
170         }
171         
172         refs = lang.reference_template.process(NameSpace.references[i]);
173
174           // HTML to put refs into
175         html =  File.read(html_file_path);
176
177           // do the replacement
178         html = html.replace(/\<!--references--\>/, refs);
179
180           // write back to file
181         Gio.simple_write(html_file_path, html);
182
183     }
184 });
185
186 // set up index and resources.
187 langs.forEach(function(lang) {
188     var ix_template = new Template({
189         templateFile : __script_path__ + '/templates/' + lang.name + '/index.html',
190         Link : Link, // lang specifc?
191     });
192     Gio.simple_write(outputdir + '/' + lang.name +  '/index.html', ix_template.process(ns_idx));
193     File.silentRecursiveCopy(__script_path__ + '/templates/resources/', 
194         outputdir + '/'  + lang.name , Gio.FileCopyFlags.OVERWRITE);
195 });