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