Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions lib/generators/component/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ var path = require('path');
var util = require('util');
var yeoman = require('yeoman-generator');

var generatorUtils = require('../generator-utils');

/**
* Module exports.
*/
Expand All @@ -22,6 +24,8 @@ function Generator() {
yeoman.generators.NamedBase.apply(this, arguments);

this.sourceRoot(path.join(__dirname, '../../templates/'));

this.option('capitalize');
}

util.inherits(Generator, yeoman.generators.Base);
Expand All @@ -34,9 +38,12 @@ util.inherits(Generator, yeoman.generators.Base);

Generator.prototype.createComponentFiles = function createComponentFiles() {
this.name = this.name || 'my_component';
this.template('component.js', 'app/js/component/' + this.name + '.js');
this.template('spec.js', 'test/spec/component/' + this.name + '.spec.js', {
'requirePath': 'component/' + this.name,

generatorUtils.mixinFullPath(this);

this.template('component.js', 'app/js/component/' + this.fullPath + '.js');
this.template('spec.js', 'test/spec/component/' + this.fullPath + '.spec.js', {
'requirePath': 'component/' + this.fullPath,
'type': 'component'
});
};
24 changes: 24 additions & 0 deletions lib/generators/generator-utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* Adds path support
*
* @api public
*/

function mixinFullPath (generator, fileNamePrefix) {
fileNamePrefix = fileNamePrefix || '';

var matches = generator.name.match(new RegExp('^(.*?)([^/]+)$'));
var path = matches[1];
var fileName = matches[2];

generator.name = fileNamePrefix + fileName;
generator.fullPath = path + generator.name;
}

/**
* Module exports.
*/

module.exports = {
mixinFullPath: mixinFullPath
};
12 changes: 9 additions & 3 deletions lib/generators/mixin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
var path = require('path');
var util = require('util');
var yeoman = require('yeoman-generator');
var generatorUtils = require('../generator-utils');

/**
* Module exports.
Expand All @@ -22,6 +23,8 @@ function Generator() {
yeoman.generators.NamedBase.apply(this, arguments);

this.sourceRoot(path.join(__dirname, '../../templates/'));

this.option('capitalize');
}

util.inherits(Generator, yeoman.generators.Base);
Expand All @@ -34,9 +37,12 @@ util.inherits(Generator, yeoman.generators.Base);

Generator.prototype.createMixinFiles = function createMixinFiles() {
this.name = this.name || 'my_component';
this.template('mixin.js', 'app/js/component/with_' + this.name + '.js');
this.template('spec.js', 'test/spec/component/with_' + this.name + '.spec.js', {
'requirePath': 'component/with_' + this.name,

generatorUtils.mixinFullPath(this, 'with_');

this.template('mixin.js', 'app/js/component/' + this.fullPath + '.js');
this.template('spec.js', 'test/spec/component/' + this.fullPath + '.spec.js', {
'requirePath': 'component/' + this.fullPath,
'type': 'mixin'
});
};
8 changes: 5 additions & 3 deletions lib/templates/component.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
define(function (require) {

<%
componentName = options['capitalize']? _.capitalize(name): name
%>
'use strict';

/**
Expand All @@ -12,13 +14,13 @@ define(function (require) {
* Module exports
*/

return defineComponent(<%= _.camelize(name) %>);
return defineComponent(<%= _.camelize(componentName) %>);

/**
* Module function
*/

function <%= _.camelize(name) %>() {
function <%= _.camelize(componentName) %>() {
this.attributes({

});
Expand Down
9 changes: 6 additions & 3 deletions lib/templates/mixin.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
define(function (require) {

<%
mixinName = _.camelize(name);
mixinName = options['capitalize']? _.capitalize(mixinName): mixinName;
%>
'use strict';

/**
* Module exports
*/

return with<%= _.classify(name) %>;
return <%= mixinName %>;

/**
* Module function
*/

function with<%= _.classify(name) %>() {
function <%= mixinName %>() {
this.attributes({

});
Expand Down
118 changes: 116 additions & 2 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,71 @@ describe('Flight generator test', function () {

it('creates expected files', function (cb) {
var expected = [
['app/js/component/my_component.js', /function myComponent()/],
['app/js/component/my_component.js', /function myComponent\(\)/],
['test/spec/component/my_component.spec.js', /describeComponent\('component\/my_component/]
];

helpers.assertGeneratorMakesExpected(flightComponent, expected, cb);
});
});

describe('flight:component with capitalize', function () {
var flightComponent;

beforeEach(function (cb) {
var deps = ['../../lib/generators/component'];
flightComponent = helpers.createGenerator(
'flight:component',
deps,
['my_component'],
{
capitalize: true
}
);
cb();
});

it('runs sucessfully', function () {
flightComponent.run();
});

it('creates expected files', function (cb) {
var expected = [
['app/js/component/my_component.js', /function MyComponent\(\)/],
['test/spec/component/my_component.spec.js', /describeComponent\('component\/my_component/]
];

helpers.assertGeneratorMakesExpected(flightComponent, expected, cb);
});
});

describe('flight:component with path', function () {
var flightComponent;

beforeEach(function (cb) {
var deps = ['../../lib/generators/component'];
flightComponent = helpers.createGenerator(
'flight:component',
deps,
['path/to/my_component']
);
cb();
});

it('runs sucessfully', function () {
flightComponent.run();
});

it('creates expected files', function (cb) {
var expected = [
['app/js/component/path/to/my_component.js', /function myComponent\(\)/],
['test/spec/component/path/to/my_component.spec.js', /describeComponent\('component\/path\/to\/my_component/]
];

helpers.assertGeneratorMakesExpected(flightComponent, expected, cb);
});
});

describe('flight:mixin', function () {
var flightMixin;

Expand All @@ -110,14 +167,71 @@ describe('Flight generator test', function () {

it('creates expected files', function (cb) {
var expected = [
['app/js/component/with_my_mixin.js', /function withMyMixin()/],
['app/js/component/with_my_mixin.js', /function withMyMixin\(\)/],
['test/spec/component/with_my_mixin.spec.js', /describeMixin\('component\/with_my_mixin/]
];

helpers.assertGeneratorMakesExpected(flightMixin, expected, cb);
});
});

describe('flight:mixin with capitalize', function () {
var flightMixin;

beforeEach(function (cb) {
var deps = ['../../lib/generators/mixin'];
flightMixin = helpers.createGenerator(
'flight:mixin',
deps,
['my_mixin'],
{
capitalize: true
}
);
cb();
});

it('runs sucessfully', function () {
flightMixin.run();
});

it('creates expected files', function (cb) {
var expected = [
['app/js/component/with_my_mixin.js', /function WithMyMixin\(\)/],
['test/spec/component/with_my_mixin.spec.js', /describeMixin\('component\/with_my_mixin/]
];

helpers.assertGeneratorMakesExpected(flightMixin, expected, cb);
});
});

describe('flight:mixin with path', function () {
var flightMixin;

beforeEach(function (cb) {
var deps = ['../../lib/generators/mixin'];
flightMixin = helpers.createGenerator(
'flight:mixin',
deps,
['path/to/my_mixin']
);
cb();
});

it('runs sucessfully', function () {
flightMixin.run();
});

it('creates expected files', function (cb) {
var expected = [
['app/js/component/path/to/with_my_mixin.js', /function withMyMixin\(\)/],
['test/spec/component/path/to/with_my_mixin.spec.js', /describeMixin\('component\/path\/to\/with_my_mixin/]
];

helpers.assertGeneratorMakesExpected(flightMixin, expected, cb);
});
});

describe('flight:page', function () {
var flightPage;

Expand Down