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