-
Notifications
You must be signed in to change notification settings - Fork 87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Passes full file path to the replacement function #76
Conversation
index.js
Outdated
|
||
doReplace(); | ||
} | ||
}); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please do not change spaces to tabs in your PR, it makes it hard to review. Can you change it back and push a new commit?
package.json
Outdated
@@ -1,6 +1,6 @@ | |||
{ | |||
"name": "gulp-replace", | |||
"version": "0.5.4", | |||
"version": "0.5.5", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a new feature, so we should bump to 0.6.0
.
Resolved after performing |
@asins I'm not sure what you mean by:
Can you elaborate? |
demo:
add code for
|
I found that filepath was the first time the file was sent to multiple files, because the function was rewritten several times, and the internal value was not changed. |
index.js
Outdated
filePath: file.path | ||
}; | ||
userReplacement.apply(context, arguments); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is definitely a clever way to achieve this, but I wonder if users will ever use .bind()
on their replacement functions and therefore be unable to use passFilePath
.
index.js
Outdated
}; | ||
return userReplacement.apply(context, arguments); | ||
}; | ||
})(file.path); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it, I see why you did this.
package.json
Outdated
@@ -1,6 +1,6 @@ | |||
{ | |||
"name": "gulp-replace", | |||
"version": "0.5.4", | |||
"version": "0.6.2", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be 0.6.0 but don't worry about changing it here, I'll change it when I release.
@@ -69,11 +84,17 @@ An optional third argument, `options`, can be passed. | |||
Type: `Object` | |||
|
|||
##### options.skipBinary | |||
Type: `boolean` | |||
Type: `boolean` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These actually need two spaces or a line break after them, otherwise they appear on the same line
Type: `boolean` | ||
Default: `false` | ||
|
||
Passes full file path to the replacement function |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes the full file path available inside the replacement function as
this.filePath
gulp.task('templates', function(){ | ||
gulp.src(['file.txt']) | ||
.pipe(replace(/foo(.{3})/g, function($0, str){ | ||
return str + 'foo' + this.filePath; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return 'bar in' + this.filePath;
It is customary to replace foo
with bar
:) In this case, we can just tack the path onto the end.
"name": "gulp-replace", | ||
"version": "0.5.4", | ||
"name": "gulp-replace-fix", | ||
"version": "0.6.4", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the package name change and the version increment please.
// }; | ||
// return userReplacement.apply(context, arguments); | ||
// }; | ||
// })(file.path); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove commented out code please.
A couple notes:
Thoughts? |
Please provide tests in the |
I went ahead and used the approach in #80 for this. Thanks for your contribution; though it wasn't merged, it still helped define the API and the project is better for it. |
#67 finishing version