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