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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ The simple case:

```javascript
var express = require('express')
, partials = require('express-partials')
, partials = require('express-partials')()
, app = express();

// load the express-partials middleware
app.use(partials());
app.use(partials);

app.get('/',function(req,res,next){
res.render('index.ejs')
Expand Down Expand Up @@ -96,4 +96,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
18 changes: 10 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var path = require('path')
*/

module.exports = function(){
return function(req,res,next){
var r = function(req,res,next){
// res.partial(view,options) -> res.render() (ignores any layouts)
res.partial = res.render;

Expand Down Expand Up @@ -76,8 +76,7 @@ module.exports = function(){

// done
next();
}
}
};

/***
* Allow to register a specific rendering
Expand All @@ -104,7 +103,7 @@ var register = function(ext,render) {
}
};

module.exports.register = register;
r.register = register;

/**
* Automatically assign a render() function
Expand All @@ -121,7 +120,7 @@ var renderer = function(ext) {
: register[ext] = require(ext.slice(1)).render;
};

module.exports.renderer = renderer;
r.renderer = renderer;

/**
* Memory cache for resolved object names.
Expand All @@ -143,7 +142,7 @@ var cache = {};
* @api private
*/

function resolveObjectName(view){
var resolveObjectName = function(view){
return cache[view] || (cache[view] = view
.split('/')
.slice(-1)[0]
Expand Down Expand Up @@ -171,7 +170,7 @@ function resolveObjectName(view){
* @api private
*/

function lookup(root, view, ext){
var lookup = function(root, view, ext){
var name = resolveObjectName(view);

// Try _ prefix ex: ./views/_<name>.jade
Expand Down Expand Up @@ -219,7 +218,7 @@ function lookup(root, view, ext){
* @api public
*/

function partial(view, options){
var partial = function(view, options){
var collection
, object
, locals
Expand Down Expand Up @@ -325,4 +324,7 @@ function partial(view, options){
} else {
return render();
}
};

return r;
}
1 change: 1 addition & 0 deletions test/fixtures/ejs/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h2>ejs says hello <%- hello -%></h2>
1 change: 1 addition & 0 deletions test/fixtures/ejs/layout.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<html><head><title>ejs layout</title></head><body><%- body %></body></html>
1 change: 1 addition & 0 deletions test/fixtures/jade/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
h2= 'Jade says hello ' + hello
5 changes: 5 additions & 0 deletions test/fixtures/jade/layout.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
html
head
title Jade layout
body
!= body
55 changes: 55 additions & 0 deletions test/test.parallel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
var express = require('express')
, request = require('./support/http')
, express_partials = require('../');

/* app1: .html files are ejs files */
var app1 = express();
var partials1 = express_partials();
app1.use(partials1);
app1.set('views',__dirname + '/fixtures/ejs')
app1.set('view engine','html')
app1.engine('html',require('ejs').__express)
partials1.register('html','ejs')

app1.get('/',function(req,res,next){
res.render('index.html',{hello:'world'})
})

/* app2: .html files are jade files */
var app2 = express();
var partials2 = express_partials();
app2.use(partials2);
app2.set('views',__dirname + '/fixtures/jade')
app2.set('view engine','html')
app2.engine('html',require('jade').__express)
partials2.register('html','jade')
app2.get('/',function(req,res,next){
res.render('index.html',{hello:'world'})
})

describe('app',function(){
describe('GET app1 /',function(){
it('should render using ejs',function(done){
request(app1)
.get('/')
.end(function(res){
res.should.have.status(200);
res.body.should.equal('<html><head><title>ejs layout</title></head><body><h2>ejs says hello world</h2></body></html>\n');
done();
})
})
})

describe('GET app2 /',function(){
it('should render using Jade',function(done){
request(app2)
.get('/')
.end(function(res){
res.should.have.status(200);
res.body.should.equal('<html><head><title>Jade layout</title></head><body><h2>Jade says hello world</h2></body></html>');
done();
})
})
})

})
4 changes: 2 additions & 2 deletions test/test.partials.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
var express = require('express')
, request = require('./support/http')
, partials = require('../');
, partials = require('../')();

var app = express();
app.use(partials());
app.use(partials);
app.set('views',__dirname + '/fixtures')

app.locals.use(function(req,res){
Expand Down