diff --git a/README.md b/README.md index ee14ee1..5644265 100644 --- a/README.md +++ b/README.md @@ -288,6 +288,7 @@ If you have `gulp watch` running, gulp will automatically inject your new files **Important**: While we are particularly proud of this feature, please note that using modules is only useful in large projects. We recommend that you only use them, if you know why you want to use them in your project. In our experience for most projects using one module is just fine. 1. `yo m:module ` - create a new module +2. choose your template: `sidemenu`, `tabs` or `blank` 2. add your module to the `app/app.js`: ```js @@ -299,7 +300,9 @@ If you have `gulp watch` running, gulp will automatically inject your new files ]); ``` 3. restart your `gulp watch` task -3. navigate to `http://localhost:9000/#/` in your browser. +3. in your browser, depending on the template you chose, navigate to `http://localhost:9000/#` + - `/` for `blank` templates + - `//list` for `sidemenu` and `tabs` templates 4. **Done!** - see your new module in action! diff --git a/module/index.js b/module/index.js index 724ea6b..b15a258 100644 --- a/module/index.js +++ b/module/index.js @@ -30,14 +30,14 @@ var MGenerator = yeoman.generators.NamedBase.extend({ name: 'template', message: 'Choose a starter template', choices: [ - { - value: 'tabs', - name: 'tabs', - }, { value: 'sidemenu', name: 'sidemenu' }, + { + value: 'tabs', + name: 'tabs', + }, { value: 'blank', name: 'blank' @@ -93,8 +93,9 @@ var MGenerator = yeoman.generators.NamedBase.extend({ this.copy('env-prod.json', modulePath + '/constants/env-prod.json'); } - // sidemenu - if (this.answers.template === 'sidemenu') { + // both + if (this.answers.template !== 'blank') { + // yo@2x.png this.copy('yo.png', modulePath + '/assets/images/yo@2x.png'); // debug @@ -111,15 +112,6 @@ var MGenerator = yeoman.generators.NamedBase.extend({ options: { template: 'debug' } }); - // menu - this.composeWith('m:controller', { - arguments: this.menuCtrlName + ' ' + this.moduleName, - }); - this.composeWith('m:template', { - arguments: 'menu ' + this.moduleName, - options: { template: 'menu' } - }); - // other templates this.composeWith('m:template', { arguments: 'list ' + this.moduleName, @@ -130,19 +122,25 @@ var MGenerator = yeoman.generators.NamedBase.extend({ options: { template: 'list-detail' } }); } - // tabs - else if (this.answers.template === 'tabs') { - this.copy('yo.png', modulePath + '/assets/images/yo@2x.png'); + // sidemenu + if (this.answers.template === 'sidemenu') { + // menu + this.composeWith('m:controller', { + arguments: this.menuCtrlName + ' ' + this.moduleName, + }); + this.composeWith('m:template', { + arguments: 'menu ' + this.moduleName, + options: { template: 'menu' } + }); + } - var options = { - arguments: this.name + ' ' + this.moduleName, - options: { - sample: 'start' - } - }; - this.composeWith('m:template', options); - this.composeWith('m:service', options); - this.composeWith('m:controller', options); + // tabs + if (this.answers.template === 'tabs') { + // tabs + this.composeWith('m:template', { + arguments: 'tabs ' + this.moduleName, + options: { template: 'tabs' } + }); } } }); diff --git a/module/templates/_module.js b/module/templates/_module.js index 3c4b532..e050118 100644 --- a/module/templates/_module.js +++ b/module/templates/_module.js @@ -25,7 +25,8 @@ angular.module('<%= moduleName %>', [ template: '', // templateUrl: '<%= moduleFolder %>/templates/.html', // controller: 'SomeCtrl as ctrl' -<%} else if (answers.template === 'sidemenu') -%> + }); +<%} else if (answers.template === 'sidemenu') { -%> abstract: true, templateUrl: '<%= moduleFolder %>/templates/menu.html', controller: '<%= menuCtrlName %> as menu' @@ -57,4 +58,36 @@ angular.module('<%= moduleName %>', [ } } }); +<%} else if (answers.template === 'tabs') { -%> + abstract: true, + templateUrl: '<%= moduleFolder %>/templates/tabs.html' + }) + .state('<%= moduleName %>.list', { + url: '/list', + views: { + 'tab-list': { + templateUrl: '<%= moduleFolder %>/templates/list.html', + // controller: 'SomeCtrl as ctrl' + } + } + }) + .state('<%= moduleName %>.listDetail', { + url: '/list/detail', + views: { + 'tab-list': { + templateUrl: '<%= moduleFolder %>/templates/list-detail.html', + // controller: 'SomeCtrl as ctrl' + } + } + }) + .state('<%= moduleName %>.debug', { + url: '/debug', + views: { + 'tab-debug': { + templateUrl: '<%= moduleFolder %>/templates/debug.html', + controller: '<%= debugCtrlName %> as ctrl' + } + } + }); +<% } -%> }); diff --git a/template/index.js b/template/index.js index 2ba85a0..0100252 100644 --- a/template/index.js +++ b/template/index.js @@ -34,6 +34,9 @@ var MGenerator = yeoman.generators.NamedBase.extend({ else if (this.options.template === 'menu') { this.template('_menu.html', folder + this.fileName + '.html'); } + else if (this.options.template === 'tabs') { + this.template('_tabs.html', folder + this.fileName + '.html'); + } } }); diff --git a/template/templates/_tabs.html b/template/templates/_tabs.html new file mode 100644 index 0000000..42f0852 --- /dev/null +++ b/template/templates/_tabs.html @@ -0,0 +1,15 @@ + + + + + + + + + + + + + diff --git a/test/test-module.js b/test/test-module.js index afe4d88..8dae091 100644 --- a/test/test-module.js +++ b/test/test-module.js @@ -72,18 +72,119 @@ describe('m:module', function () { }); }; - // var tabsTests = function (moduleName, options) { - // var moduleFolder = utils.moduleFolder(moduleName); - // var modulePath = 'app/' + moduleFolder; - // console.log(options); - - // it('tabs tests', function () { - // assert.file([ - // modulePath + '/assets/images/yo@2x.png', - - // ]); - // }); - // }; + var tabsTests = function (moduleName, options) { + var moduleFolder = utils.moduleFolder(moduleName); + var modulePath = 'app/' + moduleFolder; + console.log(options); + + it('tabs tests', function () { + assert.file([ + modulePath + '/assets/images/yo@2x.png', + ]); + + var moduleFile = modulePath + '/' + moduleFolder + '.js'; + var serviceFile = modulePath + '/services/' + moduleFolder + '-serv.js'; + var serviceName = utils.serviceName(moduleName); + var debugCtrlFile, debugCtrlName; + var configName; + + // mainModule tests + if (options && options.mainModule) { + debugCtrlFile = modulePath + '/controllers/debug-ctrl.js'; + debugCtrlName = utils.controllerName('Debug'); + configName = utils.configName(); + + // module.js + assert.fileContent(moduleFile, 'otherwise(\'/' + moduleFolder + '/list'); + } + // no mainModule test + else { + debugCtrlFile = modulePath + '/controllers/' + moduleFolder + '-debug-ctrl.js'; + debugCtrlName = utils.controllerName(moduleName + 'Debug'); + configName = utils.configName(moduleName); + + // module.js + assert.noFileContent(moduleFile, 'otherwise(\'/'); + } + + // in any case + assert.fileContent([ + // module.js + [moduleFile, 'abstract: true'], + [moduleFile, 'templateUrl: \'' + moduleFolder + '/templates/tabs.html'], + [moduleFile, '.state(\'' + moduleName + '.list'], + [moduleFile, 'templateUrl: \'' + moduleFolder + '/templates/list.html'], + [moduleFile, '.state(\'' + moduleName + '.listDetail'], + [moduleFile, 'templateUrl: \'' + moduleFolder + '/templates/list-detail.html'], + [moduleFile, '.state(\'' + moduleName + '.debug'], + [moduleFile, 'templateUrl: \'' + moduleFolder + '/templates/debug.html'], + [moduleFile, 'controller: \'' + debugCtrlName + ' as ctrl'], + + // template files + [debugCtrlFile, 'controller(\'' + debugCtrlName], + [debugCtrlFile, serviceName + ', ' + configName], + [debugCtrlFile, 'this.someData = ' + serviceName], + [debugCtrlFile, 'this.ENV = ' + configName], + [debugCtrlFile, 'this.BUILD = ' + configName], + [serviceFile, 'service(\'' + serviceName], + ]); + + // templates + assert.fileContent([ + [modulePath + '/templates/debug.html', 'ctrl.someData.binding'], + [modulePath + '/templates/list-detail.html', 'I scaffold apps'], + [modulePath + '/templates/list.html', 'Learn more...'], + [modulePath + '/templates/list.html', moduleName + '.listDetail'], + [modulePath + '/templates/tabs.html', '