Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added relative path loading to include

  • Loading branch information...
commit 0d0a5b0943ccd8b0be37ef552731d2a3a2f394b3 1 parent 451069a
@tj authored
View
1  lib/Parser.js
@@ -44,6 +44,7 @@ Parser.prototype.use = function(fn){
*/
Parser.prototype.read = function(path){
+ this.path = path;
return this.parse(fs.readFileSync(path, 'utf8'));
};
View
11 lib/plugins/include.js
@@ -1,5 +1,13 @@
/**
+ * Module dependencies.
+ */
+
+var path = require('path')
+ , dirname = path.dirname
+ , join = path.join;
+
+/**
* Include another JSON file,
* for example "include: config/permissions.json".
*/
@@ -7,5 +15,6 @@
module.exports = function(key, val, parser){
var m = /^include: *(.+)$/.exec(val);
if (!m) return;
- return parser.read(m[1]);
+ var path = join(dirname(parser.path), m[1] + '.json');
+ return parser.read(path);
}
View
4 test/fixtures/include.json
@@ -1,4 +1,4 @@
["foo",
- "include: test/fixtures/config.json",
+ "include: config",
"bar",
- "include: test/fixtures/config.json"]
+ "include: config"]
Please sign in to comment.
Something went wrong with that request. Please try again.