Skip to content
Open
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
21 changes: 17 additions & 4 deletions lib/ejs.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/*!
* EJS
* Copyright(c) 2012 TJ Holowaychuk <[email protected]>
Expand Down Expand Up @@ -43,6 +42,20 @@ exports.clearCache = function(){
cache = {};
};

/**
* Render an EJS file at the given `path` (easton changed)
* @param {String} path
* @param {String} encoding
* @api private
*/
function readEJSFile(path, encoding) {
var buffer = read(path);
if (buffer[0] == 239 && buffer[1] == 187 && buffer[2] == 191) {
buffer = buffer.slice(3);
}
return buffer.toString(encoding);
}

/**
* Translate filtered code into function calls.
*
Expand Down Expand Up @@ -161,7 +174,7 @@ var parse = exports.parse = function(str, options){
var name = js.trim().slice(7).trim();
if (!filename) throw new Error('filename option is required for includes');
var path = resolveInclude(name, filename);
include = read(path, 'utf8');
include = readEJSFile(path, 'utf8');
include = exports.parse(include, { filename: path, _with: false, open: open, close: close, compileDebug: compileDebug });
buf += "' + (function(){" + include + "})() + '";
js = '';
Expand Down Expand Up @@ -314,8 +327,8 @@ exports.renderFile = function(path, options, fn){
var str;
try {
str = options.cache
? cache[key] || (cache[key] = read(path, 'utf8'))
: read(path, 'utf8');
? cache[key] || (cache[key] = readEJSFile(path, 'utf8'))
: readEJSFile(path, 'utf8');
} catch (err) {
fn(err);
return;
Expand Down