JSDOC/Template.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
8 XObject = imports.XObject.XObject;
9
10
11 File        = imports.File.File; 
12 console     = imports.console.console; 
13 NameSpace   = imports.Introspect.NameSpace.NameSpace; 
14 Template    = imports.JSDOC.Template.Template; 
15
16
17 var outputdir = Seed.argv[2];
18
19 if (!outputdir) {
20     throw {
21         name: "ArgumentError", 
22         message: "No output directory specified on the command line\n" +
23           "Usage seed docs.js /var/www/seed  [Gtk] \n"
24     };
25 }
26
27
28 if (!File.isDirectory(outputdir)) {
29     console.log("Creating directory " + outputdir);
30     File.mkdir(outputdir);
31 };
32
33  
34 // Which libraries to build.
35
36 var ns_list = NameSpace.namespaces();
37 if (typeof(Seed.argv[3]) == 'string') {
38     console.log(Seed.argv.length);
39     ns_list = Seed.argv[3].split(',');
40 }
41
42 ns_list = ns_list.sort();
43
44
45 // which languages do we want to output for.
46 langs=[];
47 File.list(__script_path__ + '/templates/').forEach(function(f) {
48     if (!File.isDirectory(__script_path__ + '/templates/' + f)) {
49         continue;
50     }
51     if (f == 'resources') {
52         continue;
53     }
54     langs.push({
55         name : f,
56         cls_template       : new Template(__script_path__ + '/templates/' + f + '/class.html'),
57         cls_ix_template    : new Template(__script_path__ + '/templates/' + f + '/class_ix.html'),
58         reference_template : new Template(__script_path__ + '/templates/' + f + '/references.html'),
59     });
60 });
61
62
63 /*
64 var cls_template = new Template(__script_path__ + '/templates/class.html');
65 var cls_ix_template = new Template(__script_path__ + '/templates/class_ix.html');
66 var reference_template = new Template(__script_path__ + '/templates/references.html');
67 */
68
69
70 var ns_idx = [];
71 ns_list.forEach(function(ns_name) 
72 {
73     
74     //if (ns_idx.length) {         return ;/* do one - for testing */ } 
75     
76     var  core = imports.gi[ns_name];
77     var idx = { name: ns_name}; 
78     console.log("START:" + ns_name);
79    
80     var ns = NameSpace.ns(ns_name);
81     
82     // gir goes in top level...
83     if (File.exists(ns.gir_file)) {
84         File.copyFile(ns.gir_file, outputdir + '/'+ ns.gir_filename, Gio.FileCopyFlags.OVERWRITE);
85     }
86     
87     
88     ns['left_bar'] = cls_ix_template.process(ns);
89
90     langs.forEach(function(lang) {
91         // namespace template
92         Gio.simple_write(outputdir + '/'+ lang.name+ '/' +ns_name +  '.html', lang.cls_template.process(ns));
93         
94         // left bar index of elements in namespace...
95         Gio.simple_write(outputdir + '/'+ lang.name + '/_ix_'+ ns_name +  '.shtml', lang.cls_ix_template.process(ns));
96             
97     });
98      
99     
100     var actions = {
101         'objects' : 'Class',
102         'interfaces' : 'Interface',
103         'structs' : 'Struct',
104         'unions' : 'Union',
105         'enums' : 'Enum'
106         
107     };
108     for (var i in actions) {
109         // we flag GLib as a GObject lib...
110         idx[i]= ns_name == 'GLib' ? 1 : ns[i].length ;
111         ns[i].forEach( function(n) {
112             var odata = XObject.extend(
113                 NameSpace.factory(actions[i], ns_name, n),
114                 { 'left_bar' :ns['left_bar'] }
115             );
116             langs.forEach(function(lang) {
117                 Gio.simple_write(outputdir +  '/'+ lang.name + '/' + ns_name + '.' + n + '.html', 
118                     lang.cls_template.process(odata)
119                 )
120             });
121             console.log(ns_name + '.' +n);
122         }); 
123     }
124     ns_idx.push(idx);
125     
126 });
127
128 var refs = '';
129 var html_file_path = '';
130 var html = ''
131
132 // output cross reference data..
133 langs.forEach(function(lang) {
134     
135     for (var i in NameSpace.references) {
136         
137         html_file_path = [ outputdir, lang.name, i + '.html'].join('/');
138       
139         if (i == 'undefined') {
140           console.log("Undefined name space - ignored");
141           continue;
142         }
143         
144         if (!File.isFile(html_file_path)) {
145           console.log("No HTML file " + html_file_path + " to insert references into - ignored");
146           continue;
147         }
148         
149         refs = langs.reference_template.process(NameSpace.references[i]);
150
151           // HTML to put refs into
152         html =  File.read(html_file_path);
153
154           // do the replacement
155         html = html.replace(/\<!--references--\>/, refs);
156
157           // write back to file
158         Gio.simple_write(html_file_path, html);
159
160     }
161 );
162
163 // set up index and resources.
164 langs.forEach(function(lang) {
165     var ix_template = new Template(__script_path__ + '/templates/' + lang.name + '/index.html');
166     Gio.simple_write(outputdir + '/' + lang.name +  '/index.html', ix_template.process(ns_idx));
167     File.silentRecursiveCopy(__script_path__ + '/templates/resources/', outputdir + '/'  lang.name , Gio.FileCopyFlags.OVERWRITE);
168 });