Skip to content

Commit

Permalink
Merge pull request #7 from taion/filename-relative-path
Browse files Browse the repository at this point in the history
Take paths relative to project root
  • Loading branch information
bazilio91 committed Oct 6, 2015
2 parents f4e2891 + 4df41c2 commit 24b2b7d
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
7 changes: 4 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
var ejs = require('ejs'),
uglify = require('uglify-js'),
utils = require('loader-utils'),
path = require('path');
path = require('path'),
process = require('process');


module.exports = function (source) {
Expand All @@ -15,8 +16,8 @@ module.exports = function (source) {
opts.compileDebug = false;
}

// Use filenames relative to the context (in most cases the project root)
opts.filename = path.relative(this.context, this.resourcePath);
// Use filenames relative to working dir, which should be project root
opts.filename = path.relative(process.cwd(), this.resourcePath);

var template = ejs.compile(source, opts);

Expand Down
3 changes: 3 additions & 0 deletions test/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ console.log(tpl({noun: "World"}));

var tpl2 = require("!!../?delimiter=?!./template2.ejs");
console.log( tpl2({hobbies: ["food", "code"]}).trimRight() );

var tpl3 = require("./subdir/parent.ejs");
console.log(tpl3({foo: "foo"}));
1 change: 1 addition & 0 deletions test/subdir/child.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
child: <%= foo %>
1 change: 1 addition & 0 deletions test/subdir/parent.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
parent: <% include child %>

0 comments on commit 24b2b7d

Please sign in to comment.