1 //<script type="text/javscript">
3 XObject = imports.XObject.XObject;
4 console = imports.console.console;
5 Collapse = imports.Collapse.Collapse;
8 * this takes our collased file, and turns it into the config array..
10 * @see rconv.js (our tester file)
14 * - Pman.Tab.* appears to work.
15 * .. next up ..Dialog...
19 RooFile = XObject.define(
22 RooFile.superclass.constructor.call(this, ar);
23 // console.log("STARTING OUTPUT");
36 if (this.tokens[0].data == 'Pman.on') {
37 // then it's a layout style..
42 //console.dump(this.tokens);
43 // the list of statements inside of function..?
46 var stmts = this.tokens[1].items[1][2].items;
48 // look for register..
50 stmts.map( function(s, i) {
51 if (s[0].data == 'Pman.register') {
52 topp = brace = s[1].items[0][0].props;
56 console.dump(this.tokens);
57 throw "could not find top props...";
61 this.cfg = this.parseProps(topp);
62 this.cfg.name = this.tokens[3].data;
65 // ( { add { this.panel ( {
66 var cfg = this.tokens[7].items[0][0].props.add.val[2].items[2][3].items[0][0].props;
67 this.cfg.items = [ this.parseProps(cfg) ];
68 //console.dump(this.cfg);
73 //print(JSON.stringify(this.tokens,null,4)); Seed.quit();
77 // Standard Pman Dialog -
78 if (this.tokens[2].props && typeof(this.tokens[2].props.create) != 'undefined') {
79 //console.dump(this.tokens);
80 this.cfg.name = this.tokens[0].data;
84 var cfg = this.tokens[2].props.create.val[2].items[1][3].items[0][0].props;
85 //console.dump(this.tokens);
86 this.cfg.items = [ this.parseProps(cfg) ];
90 // perfect for dialogs...
93 var pos = this.lookFor( 'function');
98 if (pos > -1 && (this.tokens[pos-1].data == '=') && (this.tokens[pos-2].type == 'NAME')) {
101 '*class' : this.tokens[pos-2].data,
103 '//constructor' : this.tokens[pos-2].prefix,
104 '|constructor' : 'function ' + this.tokens[pos+1].toRaw() +
105 this.tokens[pos+2].toRaw()
113 // no function - we have a static one...
114 pos = this.lookFor( '=');
116 (this.tokens[pos-1].type == 'NAME') &&
117 (this.tokens[pos+1].data == '{')
120 '*class' : this.tokens[pos-1].data,
121 '//*class' : this.tokens[pos-1].prefix
125 XObject.extend(this.cfg, this.parseProps(this.tokens[pos+1].props));
136 var pos = this.lookFor( 'Roo.apply');
137 //console.dump(this.tokens);
142 (this.tokens[pos+1].items[0][0].data == this.cfg['*class'] + '.prototype')
144 // XXXXXx.prototype = {
148 XObject.extend(this.cfg, this.parseProps(this.tokens[pos+1].items[1][0].props));
154 var pos = this.lookFor('new');
157 (this.tokens[pos-2].type == 'NAME') &&
158 (this.tokens[pos-1].data == '=') &&
159 (this.tokens[pos+1].type == 'NAME') &&
160 (this.tokens[pos+2].data == '(')
164 '//*class' : this.tokens[pos-2].prefix,
165 '*class' : this.tokens[pos-2].data,
166 '*extends' : this.tokens[pos+1].data
169 XObject.extend(this.cfg, this.parseProps(this.tokens[pos+2].items[0][0].props));
175 ///Builder.Provider.ProjectManager = new Roo.Observable({
179 var pos = this.lookFor( 'Roo.extend');
182 this.cfg['*extends'] = this.tokens[pos+1].items[1][0].data;
183 XObject.extend(this.cfg, this.parseProps(this.tokens[pos+1].items[2][0].props));
191 var pos = this.lookFor( 'Roo.extend');
194 this.cfg['*extends'] = this.tokens[pos+1].items[1][0].data;
195 XObject.extend(this.cfg, this.parseProps(this.tokens[pos+1].items[2][0].props));
208 // other type of layout
209 // console.dump(this.tokens);
211 // this type of file..
212 // xxxx.xxx = function
213 // -> into |constructor..
214 // -> extend + prototype
221 parseProps: function(o)
223 print(JSON.stringify(o,null,4));
230 if (o[k].key.data == '}') {
231 // typo trailing comma in object def.
236 if (o[k].key.type == 'STRN') {
237 kv = o[k].key.toJS();
239 if (!o[k].val.length) {
243 //console.dump(o[k]);
244 if (o[k].val[0].data == "function") {
246 // console.dump(o[k].key.prefix);
247 var pr = typeof(o[k].key.prefix) == 'undefined' ? '' : o[k].key.prefix ;
248 pr = this.clean_prefix( pr) ;
253 ret['|' +kv ] = this.clean_body( this.expand(o[k].val));
258 if (o[k].val[0].data == "[") {
260 if (o[k].val[0].items[0][0].data == '{') {
261 // array of objects..
263 // this works for items..
265 // used elsewhere for buttons: -> in which case we have a fake xtype
269 // if K is not ITEMS - we need to add '*prop' -> and add it to the items array..
270 var add = this.parseArray(o[k].val[0].items);
276 xtype : 'Array.' + kv,
280 fakeItems.push(fake_array);
286 ret['|' +kv ] = this.clean_body(this.expand(o[k].val)); // remove ','...
289 if (o[k].val[0].data == "(") {
290 ret['|' +kv ] = this.expand(o[k].val);
293 // value is an object..
295 if (o[k].val[0].data == "{") {
297 // things that can be property of object type:
299 var add = this.parseProps(o[k].val[0].props);
303 if (kv == 'set' || kv =='listeners') {
307 if ((typeof(add.xtype) != 'undefined') || ['sortInfo', 'center', 'east', 'west', 'north', 'south'].indexOf(kv) > -1) {
314 ret[ '|' + kv ] = this.expand(o[k].val);
317 // this hsould be added to 'items', with a *prop element..
320 //console.dump(o[k].val);
322 if (o[k].val[1].data == ',' || o[k].val[1].data == '}') {
323 // single item piece of data...
325 switch(o[k].val[0].type) {
329 ret[ kv ] = t1.toJS();
332 ret[ '|' + kv ] = t1.data;
338 ret[ '|' + kv ] = this.expand(o[k].val);
341 if (!ret.items && fakeItems.length) {
344 fakeItems.forEach( function(e) {
352 parseArray: function(ar) {
356 ar.map(function (e) {
358 if (typeof(e[0].props) == 'undefined') {
363 ret.push( this.parseProps(e[0].props));
377 for(var i =0 ; i < ar.length -1; i++) {
378 ret += ar[i].toRaw();
387 clean_body : function(str)
389 var lns = str.split("\n");
391 lns.map( function(l, i) {
392 if (!i || !l.length || l.match(/^\s+$/)) {
396 var spc = l.match(/\s+/);
397 if (!spc || !spc[0].length) {
400 mindent = mindent < 0 ? spc[0].length : Math.min(spc[0].length, mindent);
403 //console.log(mindent + ":" + lns[0]);
408 lns.map( function(l,i) {
410 ar.push(l.replace(/^\s+/, ''));
413 ar.push(l.substring(mindent));
415 return ar.join("\n");
417 clean_prefix: function(str) {
424 var ret = str.replace(/^\s+/gm, "\n").replace(/\n+/gm, "\n");
425 return ret == "\n" ? '' : ret;