diff --git a/js/apps/system/aardvark/foxxTemplates.js b/js/apps/system/aardvark/foxxTemplates.js index 433bb1f997..47b894caa9 100644 --- a/js/apps/system/aardvark/foxxTemplates.js +++ b/js/apps/system/aardvark/foxxTemplates.js @@ -55,7 +55,7 @@ controller.post("/generate", function(req, res) { var conf = req.params("configuration"); conf.set("applicationContext", applicationContext); conf.set("path", path); - templateEngine = new TemplateEngine(Configuration.forDB()); + templateEngine = new TemplateEngine(conf.forDB()); templateEngine.write(); }).bodyParam("configuration", { diff --git a/js/apps/system/aardvark/lib/foxxTemplateEngine.js b/js/apps/system/aardvark/lib/foxxTemplateEngine.js index 1ce634e070..4f77ffc072 100644 --- a/js/apps/system/aardvark/lib/foxxTemplateEngine.js +++ b/js/apps/system/aardvark/lib/foxxTemplateEngine.js @@ -53,15 +53,30 @@ _.each(collectionNames, function (collectionName) { var modelName = i.singularize(collectionName), - repositoryPath = 'repositories/' + collectionName + '.js', - modelPath = 'models/' + modelName + '.js'; + collectionStart, + repositoryBase = collectionName.substr(1), + repositoryName, + repositoryPath, + repositoryInstance, + modelPath; + collectionStart = collectionName.charAt(0); + if (collectionStart.match("[a-zA-Z]") === null) { + throw "Collection Name has to start with a letter"; + } + if (modelName === collectionName) { + repositoryBase += "_repo"; + } + repositoryName = collectionStart.toUpperCase() + repositoryBase; + repositoryInstance = collectionStart.toLowerCase() + repositoryBase; + repositoryPath = 'repositories/' + collectionName; + modelPath = 'models/' + modelName; this.collectionNames.push(collectionName); this.controllers.push({ url: '/' + collectionName, path: 'controllers/' + collectionName + '.js', - repositoryInstance: collectionName, - repository: i.titleize(collectionName), + repositoryInstance: repositoryName, + repository: repositoryInstance, repositoryPath: repositoryPath, model: i.titleize(modelName), modelPath: modelPath, @@ -69,10 +84,10 @@ collectionName: collectionName }); this.repositories.push({ - path: repositoryPath + path: repositoryPath + '.js' }); this.models.push({ - path: modelPath + path: modelPath + '.js' }); }, this); }, @@ -90,8 +105,8 @@ controllers: {}, - setup: "", - teardown: "" + // setup: "", + // teardown: "" }; _.each(this.controllers, function (controller) { diff --git a/js/apps/system/aardvark/templates/controller.js.tmpl b/js/apps/system/aardvark/templates/controller.js.tmpl index 8c6f2e80ec..7ea112af58 100644 --- a/js/apps/system/aardvark/templates/controller.js.tmpl +++ b/js/apps/system/aardvark/templates/controller.js.tmpl @@ -6,7 +6,7 @@ <%= model %> = require('<%= modelPath %>').Model, _ = require('underscore'), controller, - todos; + <%= repositoryInstance %>; controller = new Foxx.Controller(applicationContext);