1 //<Script type="text/javascript">
3 GIRepository = imports.gi.GIRepository;
4 GLib = imports.gi.GLib;
6 // we add this in, as it appears to get lost sometimes if we set it using the ENV. variable in builder.sh
7 GIRepository.Repository.prepend_search_path(GLib.get_home_dir() + '/.Builder/girepository-1.2');
16 XObject = imports.XObject.XObject;
17 File = imports.File.File;
18 console = imports.console.console;
19 Template = imports.JsTemplate.Template.Template;
21 // Introspecion specific..
22 NameSpace = imports.Introspect.NameSpace.NameSpace;
23 Link = imports.Introspect.Link.Link;
27 var outputdir = Seed.argv[2];
31 name: "ArgumentError",
32 message: "No output directory specified on the command line\n" +
33 "Usage seed docs.js /var/www/seed [Gtk] \n"
38 if (!File.isDirectory(outputdir)) {
39 console.log("Creating directory " + outputdir);
40 File.mkdir(outputdir);
44 // Which libraries to build.
46 var ns_list = NameSpace.namespaces();
47 if (typeof(Seed.argv[3]) == 'string') {
48 console.log(Seed.argv.length);
49 ns_list = Seed.argv[3].split(',');
53 ns_list = ns_list.sort();
54 // let's try and load them, so we find out early what will fail.
55 print("loading library to make sure it works.");
57 ns_list.forEach(function(ns_name)
61 var core = imports.gi[ns_name];
62 ns_list_clean.push(ns_name);
64 print(JSON.stringify(e));
68 ns_list = ns_list_clean;
72 // which languages do we want to output for.
74 File.list(__script_path__ + '/templates/').forEach(function(f) {
75 if (!File.isDirectory(__script_path__ + '/templates/' + f)) {
78 if (f == 'resources') {
83 cls_template : new Template( {
84 templateFile : __script_path__ + '/templates/' + f + '/class.html',
85 Link : Link // links might be specific to languages..
87 cls_ix_template : new Template( {
88 templateFile : __script_path__ + '/templates/' + f + '/class_ix.html',
89 Link : Link // links might be specific to languages..
91 reference_template : new Template({
92 templateFile : __script_path__ + '/templates/' + f + '/references.html',
93 Link : Link // links might be specific to languages..
100 var cls_template = new Template(__script_path__ + '/templates/class.html');
101 var cls_ix_template = new Template(__script_path__ + '/templates/class_ix.html');
102 var reference_template = new Template(__script_path__ + '/templates/references.html');
105 print("Looping throught namespaces");
107 ns_list.forEach(function(ns_name)
110 //if (ns_idx.length) { return ;/* do one - for testing */ }
112 var core = imports.gi[ns_name];
113 var idx = { name: ns_name};
114 console.log("START:" + ns_name);
116 var ns = NameSpace.ns(ns_name);
118 // gir goes in top level...
119 if (File.exists(ns.gir_file)) {
120 File.copyFile(ns.gir_file, outputdir + '/'+ ns.gir_filename, Gio.FileCopyFlags.OVERWRITE);
126 langs.forEach(function(lang) {
127 ns['left_bar'] = lang.cls_ix_template.process(ns);
128 // namespace template
130 if (!File.exists(outputdir + '/'+ lang.name)) {
131 File.mkdir(outputdir + '/'+ lang.name );
135 Gio.simple_write(outputdir + '/'+ lang.name+ '/' +ns_name + '.html', lang.cls_template.process(ns));
137 // left bar index of elements in namespace...
138 Gio.simple_write(outputdir + '/'+ lang.name + '/_ix_'+ ns_name + '.shtml', lang.cls_ix_template.process(ns));
145 'interfaces' : 'Interface',
146 'structs' : 'Struct',
152 for (var i in actions) {
153 // we flag GLib as a GObject lib...
154 idx[i]= ns_name == 'GLib' ? 1 : ns[i].length ;
156 ns[i].forEach( function(n) {
158 print('NameSpace.factory(' + actions[i] +','+ns_name+','+n);
159 var odata = XObject.extend(
160 NameSpace.factory(actions[i], ns_name, n),
161 { 'left_bar' :ns['left_bar'] }
164 langs.forEach(function(lang) {
165 Gio.simple_write(outputdir + '/'+ lang.name + '/' + ns_name + '.' + n + '.html',
166 lang.cls_template.process(odata)
169 console.log(ns_name + '.' +n);
177 var html_file_path = '';
180 // output cross reference data..
181 langs.forEach(function(lang) {
183 for (var i in NameSpace.references) {
185 html_file_path = [ outputdir, lang.name, i + '.html'].join('/');
187 if (i == 'undefined') {
188 console.log("Undefined name space - ignored");
192 if (!File.isFile(html_file_path)) {
193 console.log("No HTML file " + html_file_path + " to insert references into - ignored");
197 refs = lang.reference_template.process(NameSpace.references[i]);
199 // HTML to put refs into
200 html = File.read(html_file_path);
202 // do the replacement
203 html = html.replace(/\<!--references--\>/, refs);
205 // write back to file
206 Gio.simple_write(html_file_path, html);
211 // set up index and resources.
212 langs.forEach(function(lang) {
213 var ix_template = new Template({
214 templateFile : __script_path__ + '/templates/' + lang.name + '/index.html',
215 Link : Link, // lang specifc?
217 Gio.simple_write(outputdir + '/' + lang.name + '/index.html', ix_template.process(ns_idx));
218 File.silentRecursiveCopy(__script_path__ + '/templates/resources/',
219 outputdir + '/' + lang.name , Gio.FileCopyFlags.OVERWRITE);