mirror of
https://github.com/CryptKeeperZK/ejs.git
synced 2026-01-07 22:53:52 -05:00
Make relative paths in include work for cli
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
let path = require('path');
|
||||
|
||||
let program = require('jake').program;
|
||||
delete global.jake; // NO NOT WANT
|
||||
@@ -149,9 +150,6 @@ function run() {
|
||||
}
|
||||
}
|
||||
|
||||
// Default to having views relative from the current working directory
|
||||
opts.views = ['.'];
|
||||
|
||||
// Ensure there's a template to render
|
||||
if (!templatePath) {
|
||||
throw new Error('Please provide a template path. (Run ejs -h for help)');
|
||||
@@ -197,7 +195,8 @@ function run() {
|
||||
vals[p] = pVals[p];
|
||||
}
|
||||
|
||||
let template = fs.readFileSync(templatePath).toString();
|
||||
opts.filename = path.resolve(process.cwd(), templatePath);
|
||||
let template = fs.readFileSync(opts.filename).toString();
|
||||
let output = ejs.render(template, vals, opts);
|
||||
if (pOpts.outputFile) {
|
||||
fs.writeFileSync(pOpts.outputFile, output);
|
||||
|
||||
@@ -54,4 +54,12 @@ suite('cli', function () {
|
||||
assert.equal(o.replace(/\n/g, lf), c);
|
||||
});
|
||||
|
||||
test('relative path in nested include', function () {
|
||||
let x = path.join('./bin/cli.js');
|
||||
let u = path.join('test/fixtures/include-simple.ejs');
|
||||
let o = run(os+x+' '+u);
|
||||
let c = fs.readFileSync('test/fixtures/include-simple.html', 'utf-8');
|
||||
assert.equal(o, c);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user