1 //<script type="text/javscript">
3 XObject = imports.XObject.XObject;
4 console = imports.console.console;
5 TokenStream = imports.TokenStream.TokenStream;
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..?
42 var stmts = this.tokens[1].items[1][2].items;
43 // look for register..
45 stmts.map( function(s, i) {
46 if (s[0].data == 'Pman.register') {
47 topp = brace = s[1].items[0][0].props;
51 console.dump(this.tokens);
52 throw "could not find top props...";
56 this.cfg = this.parseProps(topp);
57 this.cfg.name = this.tokens[3].data;
60 // ( { add { this.panel ( {
61 var cfg = this.tokens[7].items[0][0].props.add.val[2].items[2][3].items[0][0].props;
62 this.cfg.items = [ this.parseProps(cfg) ];
63 // console.dump(this.cfg);
68 if (this.tokens[2].props && typeof(this.tokens[2].props.create) != 'undefined') {
69 //console.dump(this.tokens);
70 this.cfg.name = this.tokens[0].data;
74 var cfg = this.tokens[2].props.create.val[2].items[1][3].items[0][0].props;
75 //console.dump(this.tokens);
76 this.cfg.items = [ this.parseProps(cfg) ];
79 // perfect for dialogs...
82 var pos = this.lookFor( 'function');
87 if (pos > -1 && (this.tokens[pos-1].data == '=') && (this.tokens[pos-2].type == 'NAME')) {
90 '*class' : this.tokens[pos-2].data,
92 '//constructor' : this.tokens[pos-2].prefix,
93 '|constructor' : 'function ' + this.tokens[pos+1].toRaw() +
94 this.tokens[pos+2].toRaw(),
102 // no function - we have a static one...
103 pos = this.lookFor( '=');
105 (this.tokens[pos-1].type == 'NAME') &&
106 (this.tokens[pos+1].data == '{')
109 '*class' : this.tokens[pos-1].data,
110 '//*class' : this.tokens[pos-1].prefix,
114 XObject.extend(this.cfg, this.parseProps(this.tokens[pos+1].props));
125 var pos = this.lookFor( 'Roo.apply');
126 //console.dump(this.tokens);
131 (this.tokens[pos+1].items[0][0].data == this.cfg['*class'] + '.prototype')
133 // XXXXXx.prototype = {
137 XObject.extend(this.cfg, this.parseProps(this.tokens[pos+1].items[1][0].props));
143 var pos = this.lookFor('new');
146 (this.tokens[pos-2].type == 'NAME') &&
147 (this.tokens[pos-1].data == '=') &&
148 (this.tokens[pos+1].type == 'NAME') &&
149 (this.tokens[pos+2].data == '(')
153 '//*class' : this.tokens[pos-2].prefix,
154 '*class' : this.tokens[pos-2].data,
155 '*extends' : this.tokens[pos+1].data
158 XObject.extend(this.cfg, this.parseProps(this.tokens[pos+2].items[0][0].props));
164 ///Builder.Provider.ProjectManager = new Roo.Observable({
168 var pos = this.lookFor( 'Roo.extend');
171 this.cfg['*extends'] = this.tokens[pos+1].items[1][0].data;
172 XObject.extend(this.cfg, this.parseProps(this.tokens[pos+1].items[2][0].props));
180 var pos = this.lookFor( 'Roo.extend');
183 this.cfg['*extends'] = this.tokens[pos+1].items[1][0].data;
184 XObject.extend(this.cfg, this.parseProps(this.tokens[pos+1].items[2][0].props));
197 // other type of layout
198 // console.dump(this.tokens);
200 // this type of file..
201 // xxxx.xxx = function
202 // -> into |constructor..
203 // -> extend + prototype
210 parseProps: function(o)
217 if (o[k].key.data == '}') {
218 // typo trailing comma in object def.
223 if (o[k].key.type == 'STRN') {
224 kv = o[k].key.toJS();
226 if (!o[k].val.length) {
229 //console.dump(o[k]);
230 if (o[k].val[0].data == "function") {
232 // console.dump(o[k].key.prefix);
233 var pr = typeof(o[k].key.prefix) == 'undefined' ? '' : o[k].key.prefix ;
234 pr = this.clean_prefix( pr) ;
239 ret['|' +kv ] = this.clean_body( this.expand(o[k].val));
242 if (o[k].val[0].data == "[") {
244 if (o[k].val[0].items[0][0].data == '{') {
245 // array of objects..
247 // this works for items..
249 // used elsewhere for buttons: -> in which case we have a fake xtype
253 // if K is not ITEMS - we need to add '*prop' -> and add it to the items array..
254 var add = this.parseArray(o[k].val[0].items);
260 xtype : 'Array.' + kv,
264 fakeItems.push(fake_array);
270 ret['|' +kv ] = this.clean_body(this.expand(o[k].val)); // remove ','...
273 if (o[k].val[0].data == "(") {
274 ret['|' +kv ] = this.expand(o[k].val);
277 if (o[k].val[0].data == "{") {
279 // things that can be property of object type:
281 var add = this.parseProps(o[k].val[0].props);
282 if (kv == 'set' || kv =='listeners') {
286 if ((typeof(add.xtype) != 'undefined') || ['sortInfo', 'center', 'east', 'west', 'north', 'south'].indexOf(kv) > -1) {
293 ret[ '|' + kv ] = this.expand(o[k].val);
296 // this hsould be added to 'items', with a *prop element..
299 //console.dump(o[k].val);
301 if (o[k].val[1].data == ',' || o[k].val[1].data == '}') {
302 // single item piece of data...
304 switch(o[k].val[0].type) {
308 ret[ kv ] = t1.toJS();
311 ret[ '|' + kv ] = t1.data;
317 ret[ '|' + kv ] = this.expand(o[k].val);
320 if (!ret.items && fakeItems.length) {
323 XObject.extend(fakeItems, function(e) {
331 parseArray: function(ar) {
335 ar.map(function (e) {
337 if (typeof(e[0].props) == 'undefined') {
342 ret.push( this.parseProps(e[0].props));
356 for(var i =0 ; i < ar.length -1; i++) {
357 ret += ar[i].toRaw();
366 clean_body : function(str)
368 var lns = str.split("\n");
370 lns.map( function(l, i) {
371 if (!i || !l.length || l.match(/^\s+$/)) {
375 var spc = l.match(/\s+/);
376 if (!spc || !spc[0].length) {
379 mindent = mindent < 0 ? spc[0].length : Math.min(spc[0].length, mindent);
382 //console.log(mindent + ":" + lns[0]);
387 lns.map( function(l,i) {
389 ar.push(l.replace(/^\s+/, ''));
392 ar.push(l.substring(mindent));
394 return ar.join("\n");
396 clean_prefix: function(str) {
403 var ret = str.replace(/^\s+/gm, "\n").replace(/\n+/gm, "\n");
404 return ret == "\n" ? '' : ret;