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