diff --git a/Readme.md b/Readme.md index 91cbe8f..e82da27 100644 --- a/Readme.md +++ b/Readme.md @@ -28,6 +28,11 @@ fileinclude('@@') - filters: `object`, filters of include content - context: `object`, context of `if` statement - indent: `boolean`, default `false` + - getPath: `function`, default: `null`, a optional callback to modify the include path + + function (path) { + return path.replace('__LANG__', 'de'); + } * options.basepath - type: `string`, it could be - `@root`, include file relative to the dir where `gulp` running in diff --git a/lib/index.js b/lib/index.js index b2fb1d1..473e402 100644 --- a/lib/index.js +++ b/lib/index.js @@ -22,7 +22,8 @@ module.exports = function(opts) { suffix: '', context: {}, filters: false, - indent: false + indent: false, + getPath: null }, opts); if (opts.basepath !== '@file') { @@ -118,6 +119,12 @@ module.exports = function(opts) { if (args) { var includePath = path.resolve(filebase, args[1]); + + // check for path modifier callback + if (typeof opts.getPath === 'function') { + includePath = opts.getPath(includePath) + } + // for checking if we are not including the current file again if (currentFilename.toLowerCase() === includePath.toLowerCase()) { throw new Error('recursion detected in file: ' + currentFilename); @@ -176,6 +183,12 @@ module.exports = function(opts) { if (arr) { var includePath = path.resolve(filebase, args[1]); + + // check for path modifier callback + if (typeof opts.getPath === 'function') { + includePath = opts.getPath(includePath) + } + // for checking if we are not including the current file again if (currentFilename.toLowerCase() === includePath.toLowerCase()) { throw new Error('recursion detected in file: ' + currentFilename);