Socket
Socket
Sign inDemoInstall

ejs

Package Overview
Dependencies
0
Maintainers
1
Versions
75
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.8.3 to 0.8.4

examples/functions.ejs

7

History.md
0.8.4 / 2013-05-08
==================
* fix support for colons in filter arguments
* fix double callback when the callback throws
* rename escape option
0.8.3 / 2012-09-13

@@ -3,0 +10,0 @@ ==================

43

lib/ejs.js

@@ -23,3 +23,3 @@

* Filters.
*
*
* @type Object

@@ -32,3 +32,3 @@ */

* Intermediate js cache.
*
*
* @type Object

@@ -61,3 +61,3 @@ */

, name = parts.shift()
, args = parts.shift() || '';
, args = parts.join(':') || '';
if (args) args = ', ' + args;

@@ -95,5 +95,5 @@ return 'filters.' + name + '(' + js + args + ')';

err.path = filename;
err.message = (filename || 'ejs') + ':'
+ lineno + '\n'
+ context + '\n\n'
err.message = (filename || 'ejs') + ':'
+ lineno + '\n'
+ context + '\n\n'
+ err.message;

@@ -121,3 +121,3 @@

buf.push('var buf = [];');
if (false !== options._with) buf.push('\nwith (locals || {}) {');
if (false !== options._with) buf.push('\nwith (locals || {}) { (function(){ ');
buf.push('\n buf.push(\'');

@@ -165,3 +165,3 @@

include = read(path, 'utf8');
include = exports.parse(include, { filename: path, _with: false, open: open, close: close });
include = exports.parse(include, { filename: path, _with: false, open: open, close: close, compileDebug: compileDebug });
buf.push("' + (function(){" + include + "})() + '");

@@ -184,3 +184,3 @@ js = '';

} else if (str.substr(i, 1) == "\r") {
buf.push(" ");
// ignore
} else if (str.substr(i, 1) == "\n") {

@@ -198,3 +198,3 @@ if (consumeEOL) {

if (false !== options._with) buf.push("');\n}\nreturn buf.join('');")
if (false !== options._with) buf.push("'); })();\n} \nreturn buf.join('');")
else buf.push("');\nreturn buf.join('');");

@@ -216,2 +216,3 @@

options = options || {};
var escape = options.escape || utils.escape;

@@ -241,5 +242,14 @@ var input = JSON.stringify(str)

if (options.debug) console.log(str);
if (client) str = 'escape = escape || ' + utils.escape.toString() + ';\n' + str;
if (client) str = 'escape = escape || ' + escape.toString() + ';\n' + str;
var fn = new Function('locals, filters, escape', str);
try {
var fn = new Function('locals, filters, escape', str);
} catch (err) {
if ('SyntaxError' == err.name) {
err.message += options.filename
? ' in ' + filename
: ' while compiling ejs';
}
throw err;
}

@@ -249,3 +259,3 @@ if (client) return fn;

return function(locals){
return fn.call(this, locals, filters, utils.escape);
return fn.call(this, locals, filters, escape);
}

@@ -309,11 +319,12 @@ };

var str;
try {
var str = options.cache
str = options.cache
? cache[key] || (cache[key] = read(path, 'utf8'))
: read(path, 'utf8');
fn(null, exports.render(str, options));
} catch (err) {
fn(err);
return;
}
fn(null, exports.render(str, options));
};

@@ -320,0 +331,0 @@

{
"name": "ejs",
"description": "Embedded JavaScript templates",
"version": "0.8.3",
"version": "0.8.4",
"author": "TJ Holowaychuk <tj@vision-media.ca>",

@@ -12,3 +12,6 @@ "keywords": ["template", "engine", "ejs"],

"main": "./lib/ejs.js",
"repository": "git://github.com/visionmedia/ejs.git"
}
"repository": "git://github.com/visionmedia/ejs.git",
"scripts": {
"test": "mocha --require should --reporter spec"
}
}

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

[![build status](https://secure.travis-ci.org/visionmedia/ejs.png)](http://travis-ci.org/visionmedia/ejs)
# EJS

@@ -7,2 +5,4 @@

[![Build Status](https://travis-ci.org/visionmedia/ejs.png)](https://travis-ci.org/visionmedia/ejs)
## Installation

@@ -30,3 +30,7 @@

<% } %>
## Try out a live example now
<a href="https://runnable.com/ejs" target="_blank"><img src="https://runnable.com/external/styles/assets/runnablebtn.png" style="width:67px;height:25px;"></a>
## Usage

@@ -146,2 +150,15 @@

## Layouts
Currently EJS has no notion of blocks, only compile-time `include`s,
however you may still utilize this feature to implement "layouts" by
simply including a header and footer like so:
```html
<% include head %>
<h1>Title</h1>
<p>My page</p>
<% include foot %>
```
## client-side support

@@ -148,0 +165,0 @@

@@ -8,3 +8,3 @@ /**

, read = fs.readFileSync
, assert = require('assert');
, assert = require('should');

@@ -16,3 +16,3 @@ /**

function fixture(name) {
return read('test/fixtures/' + name, 'utf8');
return read('test/fixtures/' + name, 'utf8').replace(/\r/g, '');
}

@@ -35,2 +35,19 @@

it('should throw if there are syntax errors', function(){
try {
ejs.compile(fixture('fail.ejs'));
} catch (err) {
err.message.should.include('compiling ejs');
try {
ejs.compile(fixture('fail.ejs'), { filename: 'fail.ejs' });
} catch (err) {
err.message.should.include('fail.ejs');
return;
}
}
assert(false, 'compiling a file with invalid syntax should throw an exception');
})
it('should allow customizing delimiters', function(){

@@ -96,2 +113,21 @@ var fn = ejs.compile('<p>{= name }</p>', { open: '{', close: '}' });

})
it('should not catch err threw by callback', function(done){
var options = { name: 'tj', open: '{', close: '}' };
var counter = 0;
try {
ejs.renderFile('test/fixtures/user.ejs', options, function(err, html){
counter++;
if (err) {
err.message.should.not.equal('Exception in callback');
return done(err);
}
throw new Error('Exception in callback');
});
} catch (err) {
counter.should.equal(1);
err.message.should.equal('Exception in callback');
done();
}
})
})

@@ -166,2 +202,7 @@

})
it('should accept arguments containing :', function(){
ejs.render('<%=: users | map:"name" | join:"::" %>', { users: users })
.should.equal('tobi::loki::jane');
})
})

@@ -211,2 +252,13 @@

})
it('should pass compileDebug to include', function(){
var file = 'test/fixtures/include.ejs';
var fn = ejs.compile(fixture('include.ejs'), { filename: file, open: '[[', close: ']]', compileDebug: false, client: true })
var str = fn.toString();
eval('var preFn = ' + str);
str.should.not.match(/__stack/);
(function() {
preFn({ pets: users });
}).should.not.throw();
})
})

@@ -213,0 +265,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc