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..
17 RooFile = XObject.define(
20 RooFile.superclass.constructor.call(this, ar);
21 // console.log("STARTING OUTPUT");
34 if (this.tokens[0].data == 'Pman.on') {
35 // then it's a layout style..
40 //console.dump(this.tokens);
41 // the list of statements inside of function..?
44 var stmts = this.tokens[1].items[1][2].items;
46 // look for register..
48 stmts.map( function(s, i) {
49 if (s[0].data == 'Pman.register') {
50 topp = brace = s[1].items[0][0].props;
54 console.dump(this.tokens);
55 throw "could not find top props...";
59 this.cfg = this.parseProps(topp);
60 this.cfg.name = this.tokens[3].data;
63 // ( { add { this.panel ( {
64 var cfg = this.tokens[7].items[0][0].props.add.val[2].items[2][3].items[0][0].props;
65 this.cfg.items = [ this.parseProps(cfg) ];
66 console.dump(this.cfg);
71 if (this.tokens[2].props && typeof(this.tokens[2].props.create) != 'undefined') {
72 //console.dump(this.tokens);
73 this.cfg.name = this.tokens[0].data;
77 var cfg = this.tokens[2].props.create.val[2].items[1][3].items[0][0].props;
78 //console.dump(this.tokens);
79 this.cfg.items = [ this.parseProps(cfg) ];
82 // perfect for dialogs...
85 var pos = this.lookFor( 'function');
90 if (pos > -1 && (this.tokens[pos-1].data == '=') && (this.tokens[pos-2].type == 'NAME')) {
93 '*class' : this.tokens[pos-2].data,
95 '//constructor' : this.tokens[pos-2].prefix,
96 '|constructor' : 'function ' + this.tokens[pos+1].toRaw() +
97 this.tokens[pos+2].toRaw()
105 // no function - we have a static one...
106 pos = this.lookFor( '=');
108 (this.tokens[pos-1].type == 'NAME') &&
109 (this.tokens[pos+1].data == '{')
112 '*class' : this.tokens[pos-1].data,
113 '//*class' : this.tokens[pos-1].prefix
117 XObject.extend(this.cfg, this.parseProps(this.tokens[pos+1].props));
128 var pos = this.lookFor( 'Roo.apply');
129 //console.dump(this.tokens);
134 (this.tokens[pos+1].items[0][0].data == this.cfg['*class'] + '.prototype')
136 // XXXXXx.prototype = {
140 XObject.extend(this.cfg, this.parseProps(this.tokens[pos+1].items[1][0].props));
146 var pos = this.lookFor('new');
149 (this.tokens[pos-2].type == 'NAME') &&
150 (this.tokens[pos-1].data == '=') &&
151 (this.tokens[pos+1].type == 'NAME') &&
152 (this.tokens[pos+2].data == '(')
156 '//*class' : this.tokens[pos-2].prefix,
157 '*class' : this.tokens[pos-2].data,
158 '*extends' : this.tokens[pos+1].data
161 XObject.extend(this.cfg, this.parseProps(this.tokens[pos+2].items[0][0].props));
167 ///Builder.Provider.ProjectManager = new Roo.Observable({
171 var pos = this.lookFor( 'Roo.extend');
174 this.cfg['*extends'] = this.tokens[pos+1].items[1][0].data;
175 XObject.extend(this.cfg, this.parseProps(this.tokens[pos+1].items[2][0].props));
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));
200 // other type of layout
201 // console.dump(this.tokens);
203 // this type of file..
204 // xxxx.xxx = function
205 // -> into |constructor..
206 // -> extend + prototype
213 parseProps: function(o)
220 if (o[k].key.data == '}') {
221 // typo trailing comma in object def.
226 if (o[k].key.type == 'STRN') {
227 kv = o[k].key.toJS();
229 if (!o[k].val.length) {
232 //console.dump(o[k]);
233 if (o[k].val[0].data == "function") {
235 // console.dump(o[k].key.prefix);
236 var pr = typeof(o[k].key.prefix) == 'undefined' ? '' : o[k].key.prefix ;
237 pr = this.clean_prefix( pr) ;
242 ret['|' +kv ] = this.clean_body( this.expand(o[k].val));
245 if (o[k].val[0].data == "[") {
247 if (o[k].val[0].items[0][0].data == '{') {
248 // array of objects..
250 // this works for items..
252 // used elsewhere for buttons: -> in which case we have a fake xtype
256 // if K is not ITEMS - we need to add '*prop' -> and add it to the items array..
257 var add = this.parseArray(o[k].val[0].items);
263 xtype : 'Array.' + kv,
267 fakeItems.push(fake_array);
273 ret['|' +kv ] = this.clean_body(this.expand(o[k].val)); // remove ','...
276 if (o[k].val[0].data == "(") {
277 ret['|' +kv ] = this.expand(o[k].val);
280 if (o[k].val[0].data == "{") {
282 // things that can be property of object type:
284 var add = this.parseProps(o[k].val[0].props);
285 if (kv == 'set' || kv =='listeners') {
289 if ((typeof(add.xtype) != 'undefined') || ['sortInfo', 'center', 'east', 'west', 'north', 'south'].indexOf(kv) > -1) {
296 ret[ '|' + kv ] = this.expand(o[k].val);
299 // this hsould be added to 'items', with a *prop element..
302 //console.dump(o[k].val);
304 if (o[k].val[1].data == ',' || o[k].val[1].data == '}') {
305 // single item piece of data...
307 switch(o[k].val[0].type) {
311 ret[ kv ] = t1.toJS();
314 ret[ '|' + kv ] = t1.data;
320 ret[ '|' + kv ] = this.expand(o[k].val);
323 if (!ret.items && fakeItems.length) {
326 XObject.extend(fakeItems, function(e) {
334 parseArray: function(ar) {
338 ar.map(function (e) {
340 if (typeof(e[0].props) == 'undefined') {
345 ret.push( this.parseProps(e[0].props));
359 for(var i =0 ; i < ar.length -1; i++) {
360 ret += ar[i].toRaw();
369 clean_body : function(str)
371 var lns = str.split("\n");
373 lns.map( function(l, i) {
374 if (!i || !l.length || l.match(/^\s+$/)) {
378 var spc = l.match(/\s+/);
379 if (!spc || !spc[0].length) {
382 mindent = mindent < 0 ? spc[0].length : Math.min(spc[0].length, mindent);
385 //console.log(mindent + ":" + lns[0]);
390 lns.map( function(l,i) {
392 ar.push(l.replace(/^\s+/, ''));
395 ar.push(l.substring(mindent));
397 return ar.join("\n");
399 clean_prefix: function(str) {
406 var ret = str.replace(/^\s+/gm, "\n").replace(/\n+/gm, "\n");
407 return ret == "\n" ? '' : ret;