1 //<Script type="text/javascript">
3 const Gtk = imports.gi.Gtk;
4 const Gio = imports.gi.Gio;
5 const Gdk = imports.gi.Gdk;
6 const GLib = imports.gi.GLib;
10 const XObject = imports.XObject.XObject;
11 const File = imports.File.File;
12 const console = imports.console.console;
13 const Template = imports.JsTemplate.Template.Template;
15 // Introspecion specific..
16 const NameSpace = imports.Introspect.NameSpace.NameSpace;
17 const Link = imports.Introspect.Link.Link;
20 var isSeed = typeof(Seed) != 'undefined';
25 return ARGV[n-2]; // running gjs from gnome-shell 3 (~/binjhbuild run ..)
26 // make args shift 2 place
29 //var outputdir = Seed.argv[2];
30 var outputdir = argv(2);
33 name : "ArgumentError",
34 message: "No output directory specified on the command line\n" +
36 "\t<seed|gjs> docs.js <output_dir> [root_gir_name_list]\n" +
37 "\toutput_dir - ex: /var/www/seed \n" +
38 "\tgir_root_name_list - comma separated gir root name ex: Gtk,Gio, ...\n"
43 if (!File.isDirectory(outputdir)) {
44 console.log("Creating directory " + outputdir);
45 File.mkdir(outputdir);
49 // Which libraries to build.
50 var ns_list = NameSpace.namespaces();
51 //if (typeof(Seed.argv[3]) == 'string') {
52 if (typeof(argv(3)) == 'string') {
53 // console.log(Seed.argv.length);
54 // ns_list = Seed.argv[3].split(',');
55 ns_list = argv(3).split(',');
57 ns_list = ns_list.sort();
59 // let's try and load them, so we find out early what will fail.
60 //print("loading library to make sure it works.");
61 ns_list.forEach(function(ns_name)
63 var core = imports.gi[ns_name];
66 var script_path = GLib.get_current_dir();
68 // which languages do we want to output for.
70 //File.list(__script_path__ + '/templates/').forEach(function(f) {
71 File.list(script_path + '/templates/').forEach(function(f) {
73 //if (!File.isDirectory(__script_path__ + '/templates/' + f)) {
74 if (!File.isDirectory(script_path + '/templates/' + f)) {
79 if (f == 'resources') {
83 //console.log("lang: " + f);
86 cls_template : new Template({
87 //templateFile : __script_path__ + '/templates/' + f + '/class.html',
88 templateFile : script_path + '/templates/' + f + '/class.html',
89 Link : Link // links might be specific to languages..
91 cls_ix_template : new Template({
92 //templateFile : __script_path__ + '/templates/' + f + '/class_ix.html',
93 templateFile : script_path + '/templates/' + f + '/class_ix.html',
94 Link : Link // links might be specific to languages..
96 reference_template : new Template({
97 //templateFile : __script_path__ + '/templates/' + f + '/references.html',
98 templateFile : script_path + '/templates/' + f + '/references.html',
99 Link : Link // links might be specific to languages..
106 var cls_template = new Template(__script_path__ + '/templates/class.html');
107 var cls_ix_template = new Template(__script_path__ + '/templates/class_ix.html');
108 var reference_template = new Template(__script_path__ + '/templates/references.html');
111 print("Looping throught namespaces");
113 ns_list.forEach(function(ns_name)
116 //if (ns_idx.length) { return ;/* do one - for testing */ }
118 // need to load the lib before introspecting it later
119 //var core = imports.gi[ns_name];
121 var idx = {name: ns_name};
122 console.log("START:" + ns_name);
124 var ns = NameSpace.ns(ns_name);
126 // gir goes in top level...
127 if (File.exists(ns.gir_file)) {
128 console.log("gir_file: " + ns.gir_file);
129 File.copyFile(ns.gir_file, outputdir + '/'+ ns.gir_filename, Gio.FileCopyFlags.OVERWRITE);
132 langs.forEach(function(lang) {
134 //console.log("lang.name: " + lang.name);
136 //ns['left_bar'] = lang.cls_ix_template.process(ns);
137 ns.left_bar = lang.cls_ix_template.process(ns);
139 // create lang dir if needed
140 if (!File.isDirectory(outputdir + '/' + lang.name)) {
141 console.log("Creating directory: " + outputdir + '/' + lang.name);
142 File.mkdir(outputdir + '/' + lang.name);
145 // namespace template
146 //Gio.simple_write(outputdir + '/'+ lang.name + '/' + ns_name + '.html', lang.cls_template.process(ns));
147 File.write(outputdir + '/' + lang.name + '/' + ns_name + '.html', lang.cls_template.process(ns));
149 // left bar index of elements in namespace...
150 //Gio.simple_write(outputdir + '/'+ lang.name + '/_ix_'+ ns_name + '.shtml', lang.cls_ix_template.process(ns));
151 File.write(outputdir + '/' + lang.name + '/_ix_'+ ns_name + '.shtml', lang.cls_ix_template.process(ns));
156 'interfaces' : 'Interface',
157 'structs' : 'Struct',
162 for (var i in actions) {
163 // we flag GLib as a GObject lib...
164 idx[i]= ns_name == 'GLib' ? 1 : ns[i].length ;
166 ns[i].forEach( function(n) {
168 //print('NameSpace.factory(' + actions[i] +','+ns_name+','+n);
169 var odata = XObject.extend(
170 NameSpace.factory(actions[i], ns_name, n),
171 { 'left_bar' :ns['left_bar'] }
174 langs.forEach(function(lang) {
175 //Gio.simple_write(outputdir + '/'+ lang.name + '/' + ns_name + '.' + n + '.html',
176 // lang.cls_template.process(odata)
178 File.write(outputdir + '/'+ lang.name + '/' + ns_name + '.' + n + '.html',
179 lang.cls_template.process(odata)
182 console.log(ns_name + '.' +n);
189 var html_file_path = '';
192 // output cross reference data..
193 langs.forEach(function(lang) {
195 for (var i in NameSpace.references) {
197 html_file_path = [ outputdir, lang.name, i + '.html'].join('/');
199 if (i == 'undefined') {
200 console.log("Undefined name space - ignored");
204 if (!File.isFile(html_file_path)) {
205 console.log("No HTML file " + html_file_path + " to insert references into - ignored");
209 refs = lang.reference_template.process(NameSpace.references[i]);
211 // HTML to put refs into
212 html = File.read(html_file_path);
214 // do the replacement
215 html = html.replace(/\<!--references--\>/, refs);
217 // write back to file
218 //Gio.simple_write(html_file_path, html);
219 File.write(html_file_path, html);
224 // set up index and resources.
225 langs.forEach(function(lang) {
226 var ix_template = new Template({
227 //templateFile : __script_path__ + '/templates/' + lang.name + '/index.html',
228 templateFile : script_path + '/templates/' + lang.name + '/index.html',
229 Link : Link, // lang specifc?
232 //Gio.simple_write(outputdir + '/' + lang.name + '/index.html', ix_template.process(ns_idx));
233 File.write(outputdir + '/' + lang.name + '/index.html', ix_template.process(ns_idx));
234 //File.silentRecursiveCopy(__script_path__ + '/templates/resources/',
235 File.silentRecursiveCopy(script_path + '/templates/resources/',
236 outputdir + '/' + lang.name ,
237 Gio.FileCopyFlags.OVERWRITE);