Skip to content

Commit

Permalink
Add methods to join paths to the destination/source root
Browse files Browse the repository at this point in the history
Fix #687
  • Loading branch information
SBoudrias committed Nov 3, 2014
1 parent 18cb22b commit 152246a
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
22 changes: 22 additions & 0 deletions lib/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,28 @@ Base.prototype.sourceRoot = function (rootPath) {
return this._sourceRoot;
};

/**
* Join a path to the source root.
* @param {...String} path
* @return {String} joined path
*/

Base.prototype.templatePath = function () {
var args = [this.sourceRoot()].concat(_.toArray(arguments));
return path.join.apply(path, args);
};

/**
* Join a path to the destination root.
* @param {...String} path
* @return {String} joined path
*/

Base.prototype.destinationPath = function () {
var args = [this.destinationRoot()].concat(_.toArray(arguments));
return path.join.apply(path, args);
};

/**
* Return a file Env validation filter checking for collision
*/
Expand Down
26 changes: 26 additions & 0 deletions test/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,32 @@ describe('generators.Base', function () {
});
});

describe('#templatePath()', function () {
it('joins path to the source root', function () {
assert.equal(
this.dummy.templatePath('bar.js'),
path.join(this.dummy.sourceRoot(), 'bar.js')
);
assert.equal(
this.dummy.templatePath('dir/', 'bar.js'),
path.join(this.dummy.sourceRoot(), '/dir/bar.js')
);
});
});

describe('#destinationPath()', function () {
it('joins path to the source root', function () {
assert.equal(
this.dummy.destinationPath('bar.js'),
path.join(this.dummy.destinationRoot(), 'bar.js')
);
assert.equal(
this.dummy.destinationPath('dir/', 'bar.js'),
path.join(this.dummy.destinationRoot(), '/dir/bar.js')
);
});
});

describe('Events', function () {
before(function () {
var Generator = this.Generator = function () {
Expand Down

0 comments on commit 152246a

Please sign in to comment.