Upgrade to ExtJS 4.0.1 - Released 05/18/2011
[extjs.git] / jsbuilder / src / generators / model / Model.js
1 /**
2  * @class Ext.generator.Model
3  * @extends Ext.generator.Base
4  * Generates a model file based on config
5  */
6 Ext.generator.Model = Ext.extend(Ext.generator.Base, {
7
8     generate: function() {
9         var modelFile   = 'app/models/' + this.name + '.js',
10             specFile    = 'test/unit/models/' + this.name + '.js',
11             fixtureFile = 'test/fixtures/' + this.name + '.js';
12         
13         this.headline("Generating the " + this.name + " model");
14         this.template("Model", this, modelFile);
15         this.template("ModelSpec", this, specFile);
16         this.template("Fixture", this, fixtureFile);
17         
18         this.insertInclude(modelFile, 'sencha-models');
19         
20         this.insertInclude('../../' + modelFile, 'app-models', 'test/unit/index.html');
21         this.insertInclude('models/' + this.name + '.js',  'spec-models', 'test/unit/index.html');
22         this.insertInclude('../fixtures/' + this.name + '.js',  'fixtures', 'test/unit/index.html');
23     },
24     
25     decodeArgs: function(args) {
26         this.name = args[0];
27         this.fields = args.slice(1);
28         
29         var length = this.fields.length,
30             field, i;
31         
32         for (i = 0; i < length; i++) {
33             field = this.fields[i].split(':');
34             
35             this.fields[i] = {
36                 name: field[0],
37                 type: field[1]
38             };
39         }
40     }
41 });
42
43 Ext.regGenerator('model', Ext.generator.Model);
44
45 load('src/generators/model/templates/ModelSpec.js');
46 load('src/generators/model/templates/Model.js');
47 load('src/generators/model/templates/Fixture.js');