Skip to content

Commit

Permalink
Merge branch 'fix-register-partials'
Browse files Browse the repository at this point in the history
  • Loading branch information
jwilm committed Jan 7, 2014
2 parents 6f87885 + cf78a22 commit 9cd6554
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 9 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ Hbs.prototype.createRenderer = function() {

// Initialization... move these actions into another function to remove
// unnecessary checks
if(!hbs.partialsRegistered)
if(!hbs.partialsRegistered && hbs.partialsPath !== '')
yield hbs.registerPartials();

if(!hbs.layoutTemplate)
Expand Down Expand Up @@ -232,7 +232,7 @@ Hbs.prototype.registerPartials = function () {
rname = /^[a-zA-Z_-]+/, readdir;

if(this.partialsPath == '')
return;
throw new Error('registerPartials requires partialsPath');

if(!(this.partialsPath instanceof Array))
this.partialsPath = [this.partialsPath];
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "koa-hbs",
"version": "0.4.0",
"version": "0.4.1",
"description": "Handlebars Templates via Generators for Koa",
"main": "index.js",
"repository": {
Expand Down
14 changes: 8 additions & 6 deletions test/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@ describe('without required options', function() {

describe('rendering', function() {
var app;
before(function() {

it('should render into the response body', function(done) {
app = testApp.create({
viewPath: __dirname + '/app/assets',
partialsPath: __dirname + '/app/assets/partials'
viewPath: __dirname + '/app/assets'
});
});

it('should put html in koa response body', function(done) {
request(app.listen())
.get('/')
.expect(200)
Expand All @@ -32,7 +30,11 @@ describe('rendering', function() {
});

describe('with partials', function() {
it('should render the partials', function(done) {
it('should render into the response body', function(done) {
app = testApp.create({
viewPath: __dirname + '/app/assets',
partialsPath: __dirname + '/app/assets/partials'
});
request(app.listen())
.get('/partials')
.expect(200)
Expand Down
23 changes: 23 additions & 0 deletions test/unit.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var assert = require('assert');
var path = require('path');
var co = require('co');

describe('unit tests', function() {
describe('getLayoutPath', function() {
Expand All @@ -18,4 +19,26 @@ describe('unit tests', function() {
assert.equal(hbs.getLayoutPath('default'), layoutPath);
});
});

describe('registerPartials', function() {
var hbs;
before(function() {
hbs = require('..').create();
hbs.middleware({
viewPath: __dirname + '/app/assets'
});
});

it('should throw an error when partialsPath is not set', function(done) {
co(function*() {
try {
yield hbs.registerPartials();
done(new Error('did not throw error'));
} catch (e) {
assert.ok(/partialsPath/.test(e.message));
done();
}
})();
});
});
});

0 comments on commit 9cd6554

Please sign in to comment.