generate gjs documentation, run under gjs
[gnome.introspection-doc-generator] / Introspect / Base.js
1 //<script type="text/javascript">
2 //Gtk = imports.gi.Gtk;
3 const GI      = imports.gi.GIRepository;
4 const GLib    = imports.gi.GLib;
5 //xml     = imports.libxml;
6 const xml     = imports.gi.libxml2;
7 //GObject = imports.gi.GObject;
8
9 const XObject = imports.XObject.XObject;
10 const console = imports.console.console;
11
12 const NameSpace = imports.Introspect.NameSpace.NameSpace;
13 const Basic     = imports.Introspect.Basic.Basic;
14
15
16
17
18 /**
19  * Base  types methods/interfaces/structs/unions etc.
20  */
21
22
23
24  
25 var Base = XObject.define(
26    function(ns, name) {
27         // fake should not happen?
28         
29         
30         if (typeof(name) == 'undefined') {
31             var ar = ns.split('.');
32             ns = ar[0];
33             name = ar[1];
34         }
35         this.ns = ns;
36         this.name = name;
37         this.alias = ns + '.' + name;
38         //console.log("CREATE(Base) " + this.alias);
39         this._loaded = false;
40         
41         
42         // reset all of these..
43         this.signals = [];
44         this.methods = [];
45         this.constructors = [];
46         this.functions= [];
47        
48         this.values = []; // for enum;g;
49         this.constants = [];
50         
51         this.properties = [];
52         this.implementInterfaces = []; // obect - which interface it implements.
53         this.implementedBy = []; // interface - which object uses it.
54         this.extendsClasses = []; // what it extends...
55         this.childClasses = []; // what 
56          this.desc = NameSpace.doc(this.alias );
57         
58         
59         var gi = GI.Repository.get_default();
60         var ver = gi.get_version(ns);
61         var pth = GI.Repository.get_search_path ();
62         var gir_path = pth[0].replace(/lib\/girepository-1.0/, 'share\/gir-1.0');
63        //console.log(fn);
64         this.gir_file = gir_path + '/'+ ns + '-' + ver + '.gir';
65         this.gir_filename = ns + '-' + ver + '.gir';
66         
67     }, 
68     Basic, 
69     {
70         titleType: 'Unknown',
71         name :  '',
72         ns : '',
73        
74         signals : [],
75         methods : [],
76         constructors : [],
77         functions: [],
78        
79         values : [], // for enum
80         constants : [],
81         
82         properties : [],
83         implementInterfaces : [], // obect - which interface it implements.
84         implementedBy : [], // interface - which object uses it.
85         extendsClasses : [], // what it extends...
86         childClasses : [], // what 
87         
88         
89         
90         
91         getBI : function()  {
92             
93             var gi = GI.Repository.get_default();
94             return gi.find_by_name(this.ns, this.name);
95         },
96          // on, getwhat, simple list (name), variable to add to.
97         genericBuildList : function( onwhat, type, keylist, saveto)
98         {
99             
100             //console.log(this.alias +" - ADDING :" + type);
101             //if (this[saveto].length) {
102             //    Seed.print( "EROROR = it's alreayd loaded why?");
103                 //throw "oops";
104             //   }
105             var bb = this.getBI();
106             var _this = this;
107            //console.log("ADD " + type[0].toUpperCase() + type.substring(1));
108             var clname = type[0].toUpperCase() + type.substring(1);
109             //var cls = imports[clname][clname];
110             var cls = imports.Introspect[clname][clname];
111             if (!cls) {
112                 console.log("COULD NOT FIND Introspect: " + type[0].toUpperCase() + type.substring(1));
113                }
114                 
115             var plural = type + 's';
116             plural = plural == 'propertys' ? 'properties' : plural;
117             
118             
119             for(var i =0; i < GI[onwhat + '_info_get_n_' + plural ](bb); i++) {            
120                 var add= new cls(GI[onwhat + '_info_get_' + type ](bb,i), this, saveto, keylist);
121                 //console.log("CLS :" + this.alias + " EL: " + add.name);
122             }
123              
124             
125         },
126         // loop through and add stuff from extends..
127         genericExtends :  function(  keylist,  saveto)   
128         {
129             // do not overlay gobject props or methods etc.
130             
131             if (!this.extendsClasses.length) {
132                 return;
133             }
134             if (this.extendsClasses[0].alias == 'GObject.Object') {
135                 return;
136             }
137                 
138             
139             var _this = this;
140             
141             this.extendsClasses[0].load();
142             this.extendsClasses[0][saveto].map(function(prop) {
143                 if (keylist.indexOf(prop.name) < 0) {
144                     _this[saveto].push(prop);
145                     keylist.push(prop.name);
146                 }
147             },this);
148             
149         },
150         // loop through and add stuff from implements..
151         genericImplements :  function(  keylist,  saveto)   {
152         
153             var _this = this;
154             this.implementInterfaces.map(function(iface) {
155                 
156                 iface.load();
157                 
158                 iface[saveto].map( function(prop) {
159                     if (keylist.indexOf(prop.name) < 0) {
160                         _this[saveto].push(prop);
161                         keylist.push(prop.name);
162                     }
163                 },this);
164                 
165             }, this);
166             
167         },
168                 
169             
170         
171 });
172
173