Skip to content

Commit

Permalink
Upgrades handlebars to 4.0.5 to address bower#2195
Browse files Browse the repository at this point in the history
Adds test for template util methods
Upgrades handlebars
Fixes RangeError due to `length` attribute in rpad helper
  • Loading branch information
ManasJayanth committed Mar 5, 2016
1 parent 1357f63 commit 6fff6fa
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 10 deletions.
5 changes: 2 additions & 3 deletions lib/templates/helpers/rpad.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ var mout = require('mout');
function rpad(Handlebars) {
Handlebars.registerHelper('rpad', function (context) {
var hash = context.hash;
var length = parseInt(hash.length, 10);
var minLength = parseInt(hash.minLength, 10);
var chr = hash.char;

return mout.string.rpad(context.fn(this), length, chr);
return mout.string.rpad(context.fn(this), minLength, chr);
});
}

Expand Down
3 changes: 1 addition & 2 deletions lib/templates/std/help-generic.std
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Options:

{{#condense}}
{{#each options}}
{{#yellow}}{{#rpad length="23"}}{{#if shorthand}}{{shorthand}}, {{/if}}{{flag}}{{/rpad}}{{/yellow}} {{description}}
{{#yellow}}{{#rpad minLength="23"}}{{#if shorthand}}{{shorthand}}, {{/if}}{{flag}}{{/rpad}}{{/yellow}} {{description}}
{{/each}}
{{/condense}}

Expand All @@ -21,4 +21,3 @@ Options:
Description:

{{#indent level="4"}}{{description}}{{/indent}}

5 changes: 2 additions & 3 deletions lib/templates/std/help.std
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,16 @@ Commands:

{{#condense}}
{{#each commands}}
{{#rpad length="23"}}{{@key}}{{/rpad}} {{.}}
{{#rpad minLength="23"}}{{@key}}{{/rpad}} {{.}}
{{/each}}
{{/condense}}

Options:

{{#condense}}
{{#each options}}
{{#yellow}}{{#rpad length="23"}}{{#if shorthand}}{{shorthand}}, {{/if}}{{flag}}{{/rpad}}{{/yellow}} {{description}}
{{#yellow}}{{#rpad minLength="23"}}{{#if shorthand}}{{shorthand}}, {{/if}}{{flag}}{{/rpad}}{{/yellow}} {{description}}
{{/each}}
{{/condense}}

See 'bower help <command>' for more information on a specific command.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"github": "^0.2.3",
"glob": "^4.3.2",
"graceful-fs": "^3.0.5",
"handlebars": "^2.0.0",
"handlebars": "^4.0.5",
"inquirer": "0.10.0",
"is-root": "^1.0.0",
"junk": "^1.0.0",
Expand Down
1 change: 0 additions & 1 deletion test/renderers/StandardRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,6 @@ describe('StandardRenderer', function () {
Uninstalls a package locally from your bower_components directory
*/}));
});
});
Expand Down
53 changes: 53 additions & 0 deletions test/util/template.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
var expect = require('expect.js');
var template = require('../../lib/util/template');
var fs = require('fs');

describe('template: util template methods for templates in lib/templates', function () {
describe('.render() - Renders a handlebars template', function () {
var testTemplateName = 'test-template.tpl';
var testTemplatePath = __dirname + '/../../lib/templates/' + testTemplateName;
beforeEach(function () {
fs.writeFileSync(testTemplatePath, '{{foo}}');
console.log();
});
it('.render() returns a compiled test-template template', function () {
var compiledStr = template.render(
testTemplateName,
{ foo: 'foo value' }
);
expect(compiledStr).to.be.equal(
'foo value'
);
});
it('.render() throws when a non existent template is provided', function () {
expect(function () {
template.render(
'test-template.not-present.tpl',
{ foo: 'foo value' }
);
}).to.throwException();
});
afterEach(function () {
fs.unlinkSync(testTemplatePath);
});
});

describe('.exists() - Checks existence of a template', function () {
var testTemplateName = 'test-template.tpl';
var testTemplatePath = __dirname + '/../../lib/templates/' + testTemplateName;
beforeEach(function () {
fs.writeFileSync(testTemplatePath, '{{foo}}');
});
it('.exists() returns true for an existing template', function () {
var templateExists = template.exists(testTemplateName);
expect(templateExists).to.be.ok();
});
it('.exists() returns false for a non existing template', function () {
var templateExists = template.exists('test-template.not-present.tpl');
expect(templateExists).to.not.be.ok();
});
afterEach(function () {
fs.unlinkSync(testTemplatePath);
});
});
});

0 comments on commit 6fff6fa

Please sign in to comment.