From d93a5946718571512743ccf70278fbbf4feee251 Mon Sep 17 00:00:00 2001 From: Alan Knowles Date: Thu, 31 Mar 2011 13:21:19 +0800 Subject: [PATCH] Update to sync with working copy * string trimming moved to File (so it does not depend on String) * updated to use latest GIR and GI interface --- File.js | 33 ++++++++++-- Introspect/Base.js | 7 ++- Introspect/Basic.js | 14 ++--- Introspect/Callback.js | 2 +- Introspect/Class.js | 23 ++++++-- Introspect/Constant.js | 2 +- Introspect/Enum.js | 2 +- Introspect/Field.js | 8 +-- Introspect/Method.js | 6 +-- Introspect/NameSpace.js | 104 ++++++++++++++++++++---------------- Introspect/Property.js | 2 +- Introspect/Signal.js | 2 +- JSDOC/Packer.js | 37 ++++++++++++- docs.js | 19 +++++-- templates/resources/page.js | 15 +++++- templates/seed/class.html | 4 +- 16 files changed, 195 insertions(+), 85 deletions(-) diff --git a/File.js b/File.js index 77777ba..7cbed3d 100755 --- a/File.js +++ b/File.js @@ -21,22 +21,45 @@ var File = { SEPARATOR : '/', + // fixme - this needs a bitter location.. + // they where in a string class before, but overriding String methods is not a good normally a good idea.. + + rtrim : function (s,toTrim) { + if (s.substr(s.length - toTrim.length) == toTrim) { + return s.slice(0, s.length - toTrim.length); + } + + return s; + }, + trim : function (s,toTrim) { + var out = this.ltrim(s,toTrim); + out = this.rtrim(out,toTrim); + return out; + }, + + ltrim : function (s, toTrim) { + if (s.substr(0, toTrim.length) == toTrim) { + return s.slice(toTrim.length); + } + + return s; + }, + join : function () { var out = ""; for (var i = 0; i < arguments.length; i++) { if (i == 0) { - out += arguments[i].rtrim(File.SEPARATOR); + out += this.rtrim(arguments[i], File.SEPARATOR); } else if (i == arguments.length - 1) { - out += File.SEPARATOR + arguments[i].ltrim(File.SEPARATOR); + out += File.SEPARATOR + this.ltrim(arguments[i], File.SEPARATOR); } else { - out += File.SEPARATOR + arguments[i].trim(File.SEPARATOR); + out += File.SEPARATOR + this.trim(arguments[i], File.SEPARATOR); } } return out; - }, - + }, read : function (path) { var out = {}; GLib.file_get_contents(path, out, null, null); diff --git a/Introspect/Base.js b/Introspect/Base.js index 9876fb5..916ebda 100644 --- a/Introspect/Base.js +++ b/Introspect/Base.js @@ -55,15 +55,14 @@ Base = XObject.define( this.desc = NameSpace.doc(this.alias ); - var gi = GI.IRepository.get_default(); + var gi = GI.Repository.get_default(); var ver = gi.get_version(ns); - var pth = GI.IRepository.get_search_path (); + var pth = GI.Repository.get_search_path (); var gir_path = pth[0].replace(/lib\/girepository-1.0/, 'share\/gir-1.0'); //console.log(fn); this.gir_file = gir_path + '/'+ ns + '-' + ver + '.gir'; this.gir_filename = ns + '-' + ver + '.gir'; - }, Basic, { @@ -90,7 +89,7 @@ Base = XObject.define( getBI : function() { - var gi = GI.IRepository.get_default(); + var gi = GI.Repository.get_default(); return gi.find_by_name(this.ns, this.name); }, // on, getwhat, simple list (name), variable to add to. diff --git a/Introspect/Basic.js b/Introspect/Basic.js index 50f58b9..00cc18e 100644 --- a/Introspect/Basic.js +++ b/Introspect/Basic.js @@ -32,7 +32,7 @@ Basic = XObject.define( // array of what!?!? var param_type = GI.type_info_get_param_type (type_info, 0); var atype = GI.type_info_get_tag(param_type); - if (atype == GI.ITypeTag.UINT8) { + if (atype == GI.TypeTag.UINT8) { return 'utf8'; } @@ -44,17 +44,17 @@ Basic = XObject.define( } var interface_info = GI.type_info_get_interface (type_info); var interface_type = GI.base_info_get_type (interface_info); - if (interface_type == GI.IInfoType.CALLBACK) { + if (interface_type == GI.InfoType.CALLBACK) { // callback.. var Callback = imports.Callback.Callback ; var ret= new Callback(interface_info, this, false, false); - ret.alias = GI.base_info_get_namespace(interface_info) + '.' + GI.base_info_get_name(interface_info); + ret.alias = interface_info.get_namespace() + '.' + interface_info.get_name(); return ret; } - return GI.base_info_get_namespace(interface_info) + '.' + GI.base_info_get_name(interface_info); + return interface_info.get_namespace() + '.' + interface_info.get_name(); }, @@ -86,12 +86,12 @@ Basic = XObject.define( var direction = this.directions[GI.arg_info_get_direction(arg)]; var add = { - name : GI.base_info_get_name(arg), - ns : GI.base_info_get_namespace(arg), + name : arg.get_name(), + ns : arg.get_namespace(), type : this.typeToName(GI.arg_info_get_type(arg)), direction : direction, be_null : GI.arg_info_may_be_null(arg) || GI.arg_info_is_optional(arg), - desc : GI.base_info_get_attribute(arg, 'doc') || '' + desc : arg.get_attribute('doc') || '' }; diff --git a/Introspect/Callback.js b/Introspect/Callback.js index d9a7318..021b4d3 100644 --- a/Introspect/Callback.js +++ b/Introspect/Callback.js @@ -30,7 +30,7 @@ Callback = XObject.define( */ XObject.extend(this,{ - name : GI.base_info_get_name(sig), + name : sig.get_name(), params : params, //memberOf : memberOf.alias, exceptions : [], diff --git a/Introspect/Class.js b/Introspect/Class.js index dba5f90..90348ec 100644 --- a/Introspect/Class.js +++ b/Introspect/Class.js @@ -25,6 +25,7 @@ Base = imports.Base.Base; Class = XObject.define( function(ns, name) { Base.call(this, ns, name); + print("Class ctr - parent called"); this.loadExtends(); this.loadImplements(); //console.log("CREATED(Class) " + this.alias); @@ -39,13 +40,13 @@ Class = XObject.define( var pi = GI.object_info_get_parent(bi); this.extendsClasses = []; - if (!pi) { + if (!pi || (pi.get_namespace() == this.ns && pi.get_name() == this.name )) { return; - } + } this.parent = NameSpace.factory( 'Class', - GI.base_info_get_namespace(pi), - GI.base_info_get_name(pi) + pi.get_namespace(), + pi.get_name() ); this.extendsClasses = [ this.parent ]; @@ -55,9 +56,21 @@ Class = XObject.define( this.extendsClasses.push(p); },this); + if (this.parent) { + this.parent.addChildClass(this.alias); + } }, + + addChildClass : function (n) { + this.childClasses.push(n); + if (this.parent) { + this.parent.addChildClass(n); + } + }, + + loadImplements : function() { var bb = this.getBI(); @@ -71,7 +84,7 @@ Class = XObject.define( var iface = NameSpace.factory( 'Interface', - GI.base_info_get_namespace(prop) , GI.base_info_get_name(prop) + prop.get_namespace() , prop.get_name() ); diff --git a/Introspect/Constant.js b/Introspect/Constant.js index bad3f6d..4021197 100644 --- a/Introspect/Constant.js +++ b/Introspect/Constant.js @@ -22,7 +22,7 @@ Basic = imports.Basic.Basic; Constant = XObject.define( function(prop, memberOf, saveto, keylist) { - this.name = GI.base_info_get_name(prop); + this.name = prop.get_name(); var tif = GI.constant_info_get_type(prop); var ty = GI.type_tag_to_string( GI.type_info_get_tag(tif)); this.type = this.typeToName(GI.constant_info_get_type(prop)); diff --git a/Introspect/Enum.js b/Introspect/Enum.js index 1dddc21..aaae157 100644 --- a/Introspect/Enum.js +++ b/Introspect/Enum.js @@ -41,7 +41,7 @@ Enum = XObject.define( this.values.push({ - name : GI.base_info_get_name(prop).toUpperCase() , + name : prop.get_name().toUpperCase() , type : GI.type_tag_to_string(GI.enum_info_get_storage_type(bi)), value: GI.value_info_get_value(prop) , memberOf : this.alias diff --git a/Introspect/Field.js b/Introspect/Field.js index ee59e3a..f2e24f8 100644 --- a/Introspect/Field.js +++ b/Introspect/Field.js @@ -22,10 +22,10 @@ Basic = imports.Basic.Basic; Field = XObject.define( function(prop, memberOf, saveto, keylist) { - this.name = GI.base_info_get_name(prop) , - this.type = this.typeToName(GI.field_info_get_type(prop)), - this.flags = GI.field_info_get_flags(prop), - this.memberOf = memberOf.alias + this.name = prop.get_name() ; + this.type = this.typeToName(GI.field_info_get_type(prop)); + this.flags = GI.field_info_get_flags(prop); + this.memberOf = memberOf.alias; memberOf[saveto].push(this); keylist.push(this.name); diff --git a/Introspect/Method.js b/Introspect/Method.js index 2c44879..0b1ad48 100644 --- a/Introspect/Method.js +++ b/Introspect/Method.js @@ -22,7 +22,7 @@ Method = XObject.define( this.propertyType = 'Method'; var flags = GI.function_info_get_flags (m); - var n = GI.base_info_get_name(m); + var n = m.get_name(); var n_original = n + ''; // posibly add: sink, if (n.match(/_(ref|unref)$/) || n.match(/^(ref|unref|weakref|weakunref)$/)) { @@ -66,8 +66,8 @@ Method = XObject.define( name : n, params: args, returns : retval, - isConstructor : flags & GI.IFunctionInfoFlags.IS_CONSTRUCTOR, - isStatic : !(flags & GI.IFunctionInfoFlags.IS_METHOD), + isConstructor : flags & GI.FunctionInfoFlags.IS_CONSTRUCTOR, + isStatic : !(flags & GI.FunctionInfoFlags.IS_METHOD), memberOf : memberOf.alias, exceptions : [], desc : NameSpace.doc(memberOf.alias + '.' + n_original) diff --git a/Introspect/NameSpace.js b/Introspect/NameSpace.js index a169d1b..44a387d 100644 --- a/Introspect/NameSpace.js +++ b/Introspect/NameSpace.js @@ -3,13 +3,31 @@ GI = imports.gi.GIRepository; GLib = imports.gi.GLib; xml = imports.libxml; - +File = imports.File.File; XObject = imports.XObject.XObject; console = imports.console.console; - +// BC/FC +if (!GI.Repository) { + GI.Repository = GI.IRepository; + GI.FunctionInfoFlags = GI.IFunctionInfoFlags ; + GI.InfoType = GI.IInfoType; + GI.TypeTag= GI.ITypeTag; + + GI.IBaseInfo.prototype.get_name = function(n) { + return GI.base_info_get_name(this, n); + } + GI.IBaseInfo.prototype.get_namespace = function(n) { + return GI.base_info_get_namespace(this, n); + } + GI.IBaseInfo.prototype.get_attribute = function( n) { + return GI.base_info_get_attribute(this, n); + } +} + + NameSpace = { @@ -27,31 +45,22 @@ NameSpace = { if (!GLib.file_test(dir, GLib.FileTest.EXISTS)) { return; } - var gdir = GLib.dir_open(dir,0); - - while (true) { - - var fn = gdir.read_name ? gdir.read_name () : GLib.dir_read_name(gdir); - // console.log('trying ' + fn); - if (!fn) { - gdir.close ? gdir.close() : GLib.dir_close(gdir); - return;; - } - if (!fn.match(/.typelib$/)) { - continue; + File.list(dir).forEach(function(fn) + { + if (!fn.match(/\.typelib$/)) { + return; } var par = fn.split('-').shift(); //console.log('trying ' + par); if (ret.indexOf(par) > -1) { - continue; + return; } ret.push(par); - - - } + }); } - var gi = GI.IRepository.get_default(); - var pth = GI.IRepository.get_search_path (); + + var gi = GI.Repository.get_default(); + var pth = GI.Repository.get_search_path(); scanGir(pth[0]); ret.sort(); @@ -62,7 +71,7 @@ NameSpace = { ns: function(ns) { - var gi = GI.IRepository.get_default(); + var gi = GI.Repository.get_default(); ret = { titleType: 'Namespace', ns: ns, @@ -89,39 +98,41 @@ NameSpace = { for (var i=0; i < gi.get_n_infos (ns); i++ ) { var info = gi.get_info (ns, i); - + // print("NAME: " + info.get_name()); + //continue; var info_type = GI.base_info_get_type (info); + // print("Type: " + info_type); switch(info_type) { - case GI.IInfoType.OBJECT: - ret.objects.push(GI.base_info_get_name(info)); - this.clsGatherInterfaces(ns , GI.base_info_get_name(info)); + case GI.InfoType.OBJECT: + ret.objects.push(info.get_name()); + this.clsGatherInterfaces(ns , info.get_name()); continue; - case GI.IInfoType.INTERFACE: - ret.interfaces.push(GI.base_info_get_name(info)); + case GI.InfoType.INTERFACE: + ret.interfaces.push(info.get_name()); continue; - case GI.IInfoType.FUNCTION: + case GI.InfoType.FUNCTION: new imports.Method.Method(info, ret, 'functions', []); continue; - case GI.IInfoType.CALLBACK: + case GI.InfoType.CALLBACK: // new Introspect.Callback(info, ret, 'callbacks', []); continue; - case GI.IInfoType.ENUM: - case GI.IInfoType.FLAGS: - ret.enums.push(GI.base_info_get_name(info)); + case GI.InfoType.ENUM: + case GI.InfoType.FLAGS: + ret.enums.push(info.get_name()); continue; - case GI.IInfoType.STRUCT: + case GI.InfoType.STRUCT: if (GI.struct_info_is_gtype_struct (info)) { continue; } - ret.structs.push(GI.base_info_get_name(info)); + ret.structs.push(info.get_name()); continue; - case GI.IInfoType.UNION: - ret.unions.push(GI.base_info_get_name(info)); + case GI.InfoType.UNION: + ret.unions.push(info.get_name()); continue; - case GI.IInfoType.CONSTANT: + case GI.InfoType.CONSTANT: new imports.Constant.Constant(info, ret, 'values', []); continue; @@ -131,11 +142,11 @@ NameSpace = { continue; } } - + //print ("SCAN NAMESPACES ALL DONE"); - var gi = GI.IRepository.get_default(); + var gi = GI.Repository.get_default(); var ver = gi.get_version(ns); - var pth = GI.IRepository.get_search_path (); + var pth = GI.Repository.get_search_path (); var gir_path = pth[0].replace(/lib\/girepository-1.0/, 'share\/gir-1.0'); //console.log(fn); ret.gir_file = gir_path + '/'+ ns + '-' + ver + '.gir'; @@ -147,12 +158,13 @@ NameSpace = { }, - + // store all the interfaces, so we can show a list of them later... // called when you list the namespace clsGatherInterfaces : function(ns, cls) { - var gi = GI.IRepository.get_default(); + // print("clsGatherInterfaces: " + ns + ", " + cls); + var gi = GI.Repository.get_default(); var bb = gi.find_by_name(ns, cls); var fullname = ns+'.'+cls; this.ifaceList = this.ifaceList || { }; @@ -162,7 +174,7 @@ NameSpace = { var prop = GI.object_info_get_interface(bb,i); - var add = GI.base_info_get_namespace(prop) +'.' + GI.base_info_get_name(prop); + var add = prop.get_namespace() +'.' + prop.get_name(); this.ifaceList[add] = this.ifaceList[add] || []; if (this.ifaceList[add].indexOf(fullname) < 0) { this.ifaceList[add].push(fullname); @@ -178,7 +190,9 @@ NameSpace = { doc : function(what) { + //print ("DOC: + " +what); var ns = what.split('.').shift(); + return ''; this.commentLoad(ns); return typeof(this.comments[ns][what]) == 'undefined' ? '' : this.comments[ns][what]; @@ -196,7 +210,7 @@ NameSpace = { } console.log("LOAD DOCS: " + ns); - var gi = GI.IRepository.get_default(); + var gi = GI.Repository.get_default(); var ver = gi.get_version(ns); if (!ver) { this.comments[ns] = {}; @@ -254,7 +268,7 @@ NameSpace = { } } - var pth = GI.IRepository.get_search_path (); + var pth = GI.Repository.get_search_path (); var gir_path = pth[0].replace(/lib\/girepository-1.0/, 'share\/gir-1.0'); diff --git a/Introspect/Property.js b/Introspect/Property.js index 832152f..7997796 100644 --- a/Introspect/Property.js +++ b/Introspect/Property.js @@ -20,7 +20,7 @@ Basic = imports.Basic.Basic; Property = XObject.define( function(prop, memberOf, saveto, keylist) { this.propertyType = 'Property'; - var n_original = GI.base_info_get_name(prop); + var n_original = prop.get_name(); this.name = n_original.replace(/\-/g, '_') , this.type = this.typeToName(GI.property_info_get_type(prop)), this.flags = GI.property_info_get_flags(prop), diff --git a/Introspect/Signal.js b/Introspect/Signal.js index 9524512..0c1a9d5 100644 --- a/Introspect/Signal.js +++ b/Introspect/Signal.js @@ -25,7 +25,7 @@ Signal = XObject.define( be_null : false }); - var n_original = GI.base_info_get_name(sig); + var n_original = sig.get_name(); XObject.extend(this,{ name : n_original.replace(/-/g,'_'), diff --git a/JSDOC/Packer.js b/JSDOC/Packer.js index 933156d..b4a41fa 100644 --- a/JSDOC/Packer.js +++ b/JSDOC/Packer.js @@ -83,10 +83,45 @@ Packer = function(cfg) throw "No Files"; } - + var link = false; + if (cfg.autoBuild) { + + function dateString(d){ + function pad(n){return n<10 ? '0'+n : n} + return d.getFullYear() + + pad(d.getMonth()+1)+ + pad(d.getDate())+'_'+ + pad(d.getHours())+ + pad(d.getMinutes())+ + pad(d.getSeconds()); + } + + + + var version = 0; + this.files.forEach(function(f) { + version = Math.max(File.mtime(f), version); + }); + var version = dateString(new Date(version)); + + var dirname = GLib.path_get_dirname(this.files[0]); + var outname = this.module ? this.module : GLib.path_get_basename(dirname); + this.target = dirname + '/compiled/' + outname + '-' + version + '.js'; + if (File.exists(this.target)) { + print("Target file already exists: " + this.target); + Seed.quit(); + } + this.prefix = dirname +'/'; + this.translateJSON = dirname + '/compiled/_translation_.js'; + + } + + print(this.translateJSON); this.timer = new Date() * 1; this.packAll(); + + } Packer.prototype = { diff --git a/docs.js b/docs.js index a34e3ef..7a2a233 100644 --- a/docs.js +++ b/docs.js @@ -41,7 +41,15 @@ if (typeof(Seed.argv[3]) == 'string') { ns_list = Seed.argv[3].split(','); } + ns_list = ns_list.sort(); +// let's try and load them, so we find out early what will fail. +print("loading library to make sure it works."); +ns_list.forEach(function(ns_name) +{ + var core = imports.gi[ns_name]; +}); + // which languages do we want to output for. @@ -77,7 +85,7 @@ var cls_ix_template = new Template(__script_path__ + '/templates/class_ix.html') var reference_template = new Template(__script_path__ + '/templates/references.html'); */ - +print("Looping throught namespaces"); var ns_idx = []; ns_list.forEach(function(ns_name) { @@ -117,14 +125,19 @@ ns_list.forEach(function(ns_name) 'enums' : 'Enum' }; + for (var i in actions) { // we flag GLib as a GObject lib... idx[i]= ns_name == 'GLib' ? 1 : ns[i].length ; + ns[i].forEach( function(n) { + + print('NameSpace.factory(' + actions[i] +','+ns_name+','+n); var odata = XObject.extend( NameSpace.factory(actions[i], ns_name, n), { 'left_bar' :ns['left_bar'] } ); + langs.forEach(function(lang) { Gio.simple_write(outputdir + '/'+ lang.name + '/' + ns_name + '.' + n + '.html', lang.cls_template.process(odata) @@ -158,7 +171,7 @@ langs.forEach(function(lang) { continue; } - refs = langs.reference_template.process(NameSpace.references[i]); + refs = lang.reference_template.process(NameSpace.references[i]); // HTML to put refs into html = File.read(html_file_path); @@ -181,4 +194,4 @@ langs.forEach(function(lang) { Gio.simple_write(outputdir + '/' + lang.name + '/index.html', ix_template.process(ns_idx)); File.silentRecursiveCopy(__script_path__ + '/templates/resources/', outputdir + '/' + lang.name , Gio.FileCopyFlags.OVERWRITE); -}); \ No newline at end of file +}); diff --git a/templates/resources/page.js b/templates/resources/page.js index 3d7c49c..2aee037 100644 --- a/templates/resources/page.js +++ b/templates/resources/page.js @@ -126,8 +126,21 @@ RooDocsPage = { } return d.getAttributeNS(ns, name) || d.getAttribute(ns+":"+name) || d.getAttribute(name) || d[name]; + }, + vis : '', + toggle : function() + { + this.vis = this.vis == '' ? 'none' : ''; + var vis = this.vis; + // new browsers only... + Array.prototype.slice.call( + document.getElementsByClassName('expandable') + ).forEach(function(e) { + if (!e.className.match(/notInherited/)) { + e.style.display= vis; + } + }) } - } diff --git a/templates/seed/class.html b/templates/seed/class.html index 3b729a3..d4bc71e 100644 --- a/templates/seed/class.html +++ b/templates/seed/class.html @@ -11,7 +11,7 @@ JsDoc Reference - {+data.name+} - + c @@ -114,7 +114,7 @@ GIR File: - {+data.gir_filename+} + {+data.gir_filename+} C documentation: -- 2.39.2