I should preface this by saying that I have never contributed to open source, and am very excited to start with ejs.
So I decided it was high time to update EJS's include methodology.
I decided to start by first adding the ability to include files from a relative or a absolute path, but I'm a little stuck because I am unsure how to access the app engine's (in this case express's) view root (in case it is different from "/views/"
So far, I have edited the resolveInclude function near line 280 in node_modules/ejs/lib/ejs.js and added 2 other functions. One that splits the path at the view root, which is currently only static, at "/views/"... obviously this needs to be dynamic, and set to the app engine's view root. Hence, my predicament...
/**
* Resolve include `name` relative to `filename`.
*
* @param {String} name
* @param {String} filename
* @return {String}
* @api private
*/
function resolveInclude(name, filename) {
var path;
if (0 == name.trim().indexOf('./')) path = dirname(filename);
else path = resolveFromViewsRoot(dirname(filename), '/views/');
path = join(path, name);
return addExtension(path);
}
/**
* Resolve include `name` relative to `root in '/views/ folder'`.
*
* @param {String} path
* @param {String} root
* @return {String}
* @api private
*/
function resolveFromViewsRoot(path, root) {
path = path.split(root);
var nuPath = path.shift();
nuPath = nuPath + root;
return nuPath;
}
/**
* Add ejs extension to file name
*
* @param {String} path
* @return {String}
* @api private
*/
function addExtension(path) {
if (!extname(path)) return path + '.ejs';
}
any help would be greatly appreciated.