Skip to content
This repository was archived by the owner on Feb 21, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 14 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ module.exports = function(opts) {
suffix: '',
context: {},
filters: false,
indent: false
indent: false,
getPath: null
}, opts);

if (opts.basepath !== '@file') {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down