X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/7a654f8d43fdb43d78b63d90528bed6e86b608cc..3789b528d8dd8aad4558e38e22d775bcab1cbd36:/jsbuilder/src/generators/model/Model.js?ds=sidebyside diff --git a/jsbuilder/src/generators/model/Model.js b/jsbuilder/src/generators/model/Model.js new file mode 100644 index 00000000..0fbc5155 --- /dev/null +++ b/jsbuilder/src/generators/model/Model.js @@ -0,0 +1,47 @@ +/** + * @class Ext.generator.Model + * @extends Ext.generator.Base + * Generates a model file based on config + */ +Ext.generator.Model = Ext.extend(Ext.generator.Base, { + + generate: function() { + var modelFile = 'app/models/' + this.name + '.js', + specFile = 'test/unit/models/' + this.name + '.js', + fixtureFile = 'test/fixtures/' + this.name + '.js'; + + this.headline("Generating the " + this.name + " model"); + this.template("Model", this, modelFile); + this.template("ModelSpec", this, specFile); + this.template("Fixture", this, fixtureFile); + + this.insertInclude(modelFile, 'sencha-models'); + + this.insertInclude('../../' + modelFile, 'app-models', 'test/unit/index.html'); + this.insertInclude('models/' + this.name + '.js', 'spec-models', 'test/unit/index.html'); + this.insertInclude('../fixtures/' + this.name + '.js', 'fixtures', 'test/unit/index.html'); + }, + + decodeArgs: function(args) { + this.name = args[0]; + this.fields = args.slice(1); + + var length = this.fields.length, + field, i; + + for (i = 0; i < length; i++) { + field = this.fields[i].split(':'); + + this.fields[i] = { + name: field[0], + type: field[1] + }; + } + } +}); + +Ext.regGenerator('model', Ext.generator.Model); + +load('src/generators/model/templates/ModelSpec.js'); +load('src/generators/model/templates/Model.js'); +load('src/generators/model/templates/Fixture.js'); \ No newline at end of file