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