Skip to content
This repository has been archived by the owner on Jul 8, 2020. It is now read-only.

Commit

Permalink
work on #198 - module templates: test & implement tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
gruppjo committed Jun 25, 2015
1 parent 197bf22 commit bd1306e
Show file tree
Hide file tree
Showing 6 changed files with 194 additions and 41 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <moduleName>` - create a new module
2. choose your template: `sidemenu`, `tabs` or `blank`
2. add your module to the `app/app.js`:

```js
Expand All @@ -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/#/<module-name-in-kebap-case>` in your browser.
3. in your browser, depending on the template you chose, navigate to `http://localhost:9000/#`
- `/<module-name-in-kebap-case>` for `blank` templates
- `/<module-name-in-kebap-case>/list` for `sidemenu` and `tabs` templates
4. **Done!** - see your new module in action!


Expand Down
52 changes: 25 additions & 27 deletions module/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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') {
// [email protected]
this.copy('yo.png', modulePath + '/assets/images/[email protected]');

// debug
Expand All @@ -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,
Expand All @@ -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/[email protected]');
// 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' }
});
}
}
});
Expand Down
35 changes: 34 additions & 1 deletion module/templates/_module.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ angular.module('<%= moduleName %>', [
template: '<ion-view view-title="<%= moduleName %>"></ion-view>',
// templateUrl: '<%= moduleFolder %>/templates/<someTemplate>.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'
Expand Down Expand Up @@ -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'
}
}
});
<% } -%>
});
3 changes: 3 additions & 0 deletions template/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
});

Expand Down
15 changes: 15 additions & 0 deletions template/templates/_tabs.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<ion-tabs class="tabs-icon-top tabs-assertive">

<!-- List Tab -->
<ion-tab title="List" icon-off="ion-ios-pulse" icon-on="ion-ios-pulse-strong"
ui-sref="<%= moduleName %>.list">
<ion-nav-view name="tab-list"></ion-nav-view>
</ion-tab>

<!-- Debug Tab -->
<ion-tab title="Debug" icon-off="ion-ios-gear-outline" icon-on="ion-ios-gear"
ui-sref="<%= moduleName %>.debug">
<ion-nav-view name="tab-debug"></ion-nav-view>
</ion-tab>

</ion-tabs>
125 changes: 113 additions & 12 deletions test/test-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]',

// ]);
// });
// };
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/[email protected]',
]);

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', '<ion-tabs'],
[modulePath + '/templates/tabs.html', moduleName + '.list'],
[modulePath + '/templates/tabs.html', moduleName + '.debug'],
]);
});
};

describe('main (main, tabs)', function () {
var options = {
mainModule: true
};

before(function (done) {
helpers.run(path.join(__dirname, '../module'))
.withGenerators([ // configure path to subgenerators
path.join(__dirname, '../controller'),
path.join(__dirname, '../template'),
path.join(__dirname, '../service'),
path.join(__dirname, '../constant')
])
.withArguments('main')
.withPrompts({ template: 'tabs' })
.withOptions(options)
.on('end', done);
});

basicFilesTests('main', options);
mainModuleTests('main');
tabsTests('main', options);
});

describe('myModule (no main, tabs)', function () {

before(function (done) {
helpers.run(path.join(__dirname, '../module'))
.withGenerators([ // configure path to subgenerators
path.join(__dirname, '../controller'),
path.join(__dirname, '../template'),
path.join(__dirname, '../service'),
path.join(__dirname, '../constant')
])
.withArguments('myModule')
.withPrompts({ template: 'tabs' })
.on('end', done);
});

basicFilesTests('myModule');
noMainModuleTests('myModule');
tabsTests('myModule');
});

var sideMenuTests = function (moduleName, options) {
var moduleFolder = utils.moduleFolder(moduleName);
Expand Down

0 comments on commit bd1306e

Please sign in to comment.