New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

express-partials

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-partials - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

History.md

42

index.js

@@ -1,3 +0,2 @@

var ejs = require('ejs')
, path = require('path')
var path = require('path')
, exists = path.existsSync

@@ -21,2 +20,3 @@ , resolve = path.resolve

* app.use(partials());
* partials.register('coffee',require('coffeekup').render);
* app.get('/',function(req,res,next){

@@ -75,4 +75,35 @@ * res.render('index.ejs') // renders layout.ejs with index.ejs as `body`.

/***
* Allow to register a specific rendering
* function for a given extension.
* (Similar to Express 2.x register() function.)
*/
var register = function(ext,render) {
if(ext[0] !== '.') {
ext = '.' + ext;
}
register[ext] = render;
};
module.exports.register = register;
/**
* Automatically assign a render() function
* from a module of the same name if none
* has been registered.
*/
var renderer = function(ext) {
if(ext[0] !== '.') {
ext = '.' + ext;
}
return register[ext] != null
? register[ext]
: register[ext] = require(ext.slice(1)).render;
};
module.exports.renderer = renderer;
/**
* Memory cache for resolved object names.

@@ -221,3 +252,3 @@ */

var root = this.app.get('views') || process.cwd() + '/views'
, ext = extname(view) || '.' + (this.app.get('view engine') || 'ejs')
, ext = extname(view) || '.' + (this.app.get('view engine')||'ejs')
, file = lookup(root, view, ext);

@@ -238,4 +269,3 @@

}
// TODO Support other templates (but it's sync now...)
return ejs.render(source, options);
return renderer(ext)(source, options);
}

@@ -282,2 +312,2 @@

}
}
}

7

package.json

@@ -5,3 +5,3 @@ {

"description": "Express 3.x Layout & Partial support.",
"version": "0.0.2",
"version": "0.0.3",
"repository": {

@@ -14,3 +14,2 @@ "url": "https://github.com/publicclass/express-partials"

"dependencies": {
"ejs": "*"
},

@@ -20,3 +19,5 @@ "devDependencies": {

"mocha": "*",
"should": "*"
"should": "*",
"ejs": "*",
"jade": "*"
},

@@ -23,0 +24,0 @@ "scripts": {

@@ -20,2 +20,5 @@ # express-partials

app.use(partials());
// optionally register a template engine (defaults to ejs)
partials.register('.jade',require('jade').render);

@@ -39,5 +42,6 @@ app.get('/',function(req,res,next){

## Template Support
## Template Support (tested)
- `ejs` (actually hard coded right now, but feel free to __fork and help!__)
- [ejs](https://github.com/visionmedia/ejs)
- [jade](https://github.com/visionmedia/jade)

@@ -48,3 +52,3 @@

- More Tests!
- More templates.
- More template engines.

@@ -51,0 +55,0 @@

@@ -45,2 +45,12 @@ var express = require('express')

partials.register('.j',require('jade').render);
app.get('/register/no-layout',function(req,res,next){
res.render('index.j',{hello:'world',layout:false})
})
app.engine('.j',require('jade').__express);
app.get('/register',function(req,res,next){
res.render('index.j',{hello:'world'})
})
describe('app',function(){

@@ -142,3 +152,27 @@ describe('GET /',function(){

})
})
describe('GET /register/no-layout',function(){
it('should render index.j as a Jade template',function(done){
request(app)
.get('/register/no-layout')
.end(function(res){
res.should.have.status(200);
res.body.should.equal('<h2>Jade says hello world</h2>');
done();
})
})
})
describe('GET /register',function(){
it('should render index.j as a Jade template with layout.j as Jade layout',function(done){
request(app)
.get('/register')
.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();
})
})
})
})
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc