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 //print(JSON.stringify(cfg,null,4)); Seed.quit();
88 // print("Trying standard dialog");Seed.quit();;
90 this.cfg.items = [ this.parseProps(cfg) ];
94 // perfect for dialogs...
97 var pos = this.lookFor( 'function');
102 if (pos > -1 && (this.tokens[pos-1].data == '=') && (this.tokens[pos-2].type == 'NAME')) {
105 '*class' : this.tokens[pos-2].data,
107 '//constructor' : this.tokens[pos-2].prefix,
108 '|constructor' : 'function ' + this.tokens[pos+1].toRaw() +
109 this.tokens[pos+2].toRaw()
117 // no function - we have a static one...
118 pos = this.lookFor( '=');
120 (this.tokens[pos-1].type == 'NAME') &&
121 (this.tokens[pos+1].data == '{')
124 '*class' : this.tokens[pos-1].data,
125 '//*class' : this.tokens[pos-1].prefix
129 XObject.extend(this.cfg, this.parseProps(this.tokens[pos+1].props));
140 var pos = this.lookFor( 'Roo.apply');
141 //console.dump(this.tokens);
146 (this.tokens[pos+1].items[0][0].data == this.cfg['*class'] + '.prototype')
148 // XXXXXx.prototype = {
152 XObject.extend(this.cfg, this.parseProps(this.tokens[pos+1].items[1][0].props));
158 var pos = this.lookFor('new');
161 (this.tokens[pos-2].type == 'NAME') &&
162 (this.tokens[pos-1].data == '=') &&
163 (this.tokens[pos+1].type == 'NAME') &&
164 (this.tokens[pos+2].data == '(')
168 '//*class' : this.tokens[pos-2].prefix,
169 '*class' : this.tokens[pos-2].data,
170 '*extends' : this.tokens[pos+1].data
173 XObject.extend(this.cfg, this.parseProps(this.tokens[pos+2].items[0][0].props));
179 ///Builder.Provider.ProjectManager = new Roo.Observable({
183 var pos = this.lookFor( 'Roo.extend');
186 this.cfg['*extends'] = this.tokens[pos+1].items[1][0].data;
187 XObject.extend(this.cfg, this.parseProps(this.tokens[pos+1].items[2][0].props));
195 var pos = this.lookFor( 'Roo.extend');
198 this.cfg['*extends'] = this.tokens[pos+1].items[1][0].data;
199 XObject.extend(this.cfg, this.parseProps(this.tokens[pos+1].items[2][0].props));
212 // other type of layout
213 // console.dump(this.tokens);
215 // this type of file..
216 // xxxx.xxx = function
217 // -> into |constructor..
218 // -> extend + prototype
225 parseProps: function(o)
227 //print(JSON.stringify(o,null,4));
233 //print( "parsing prop: " + k);
234 if (o[k].key.data == '}') {
235 // typo trailing comma in object def.
240 if (o[k].key.type == 'STRN') {
241 kv = o[k].key.toJS();
243 if (!o[k].val.length) {
247 //console.dump(o[k]);
248 if (o[k].val[0].data == "function") {
250 // console.dump(o[k].key.prefix);
251 var pr = typeof(o[k].key.prefix) == 'undefined' ? '' : o[k].key.prefix ;
252 pr = this.clean_prefix( pr) ;
256 //print("running expand");
257 ret['|' +kv ] = this.clean_body( this.expand(o[k].val));
262 if (o[k].val[0].data == "[") {
264 if (o[k].val[0].items[0][0].data == '{') {
265 // array of objects..
267 // this works for items..
269 // used elsewhere for buttons: -> in which case we have a fake xtype
273 // if K is not ITEMS - we need to add '*prop' -> and add it to the items array..
274 var add = this.parseArray(o[k].val[0].items);
280 xtype : 'Array.' + kv,
284 fakeItems.push(fake_array);
290 ret['|' +kv ] = this.clean_body(this.expand(o[k].val)); // remove ','...
293 if (o[k].val[0].data == "(") {
294 ret['|' +kv ] = this.expand(o[k].val);
297 // value is an object..
299 if (o[k].val[0].data == "{") {
301 // things that can be property of object type:
303 var add = this.parseProps(o[k].val[0].props);
307 if (kv == 'set' || kv =='listeners') {
311 if ((typeof(add.xtype) != 'undefined') || ['sortInfo', 'center', 'east', 'west', 'north', 'south'].indexOf(kv) > -1) {
318 ret[ '|' + kv ] = this.expand(o[k].val);
321 // this hsould be added to 'items', with a *prop element..
324 //console.dump(o[k].val);
326 if (o[k].val[1].data == ',' || o[k].val[1].data == '}') {
327 // single item piece of data...
329 switch(o[k].val[0].type) {
333 ret[ kv ] = t1.toJS();
336 ret[ '|' + kv ] = t1.data;
342 ret[ '|' + kv ] = this.expand(o[k].val);
345 if (!ret.items && fakeItems.length) {
348 fakeItems.forEach( function(e) {
356 parseArray: function(ar) {
360 ar.map(function (e) {
362 if (typeof(e[0].props) == 'undefined') {
367 ret.push( this.parseProps(e[0].props));
379 print(JSON.stringify(ar,null,4));
381 for(var i =0 ; i < ar.length -1; i++) {
382 ret += ar[i].toRaw();
389 clean_body : function(str)
391 var lns = str.split("\n");
393 lns.map( function(l, i) {
394 if (!i || !l.length || l.match(/^\s+$/)) {
398 var spc = l.match(/\s+/);
399 if (!spc || !spc[0].length) {
402 mindent = mindent < 0 ? spc[0].length : Math.min(spc[0].length, mindent);
405 //console.log(mindent + ":" + lns[0]);
410 lns.map( function(l,i) {
412 ar.push(l.replace(/^\s+/, ''));
415 ar.push(l.substring(mindent));
417 return ar.join("\n");
419 clean_prefix: function(str) {
426 var ret = str.replace(/^\s+/gm, "\n").replace(/\n+/gm, "\n");
427 return ret == "\n" ? '' : ret;