Skip to content
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

Added %d as an extended replacement for directory name #52

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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: 4 additions & 1 deletion lib/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@ Block.prototype.build = function () {
if (this.uniqueExts) {
var extname = path.extname(this.file.path);
var basename = path.basename(this.file.path, extname);

var dirname = path.dirname(this.file.path);
if (this.uniqueExts['%f']) {
this.uniqueExts['%f'].value = basename;
}
if (this.uniqueExts['%e']) {
this.uniqueExts['%e'].value = extname;
}
if (this.uniqueExts['%d']) {
this.uniqueExts['%d'].value = dirname.split(path.sep).pop();
}

Object.keys(this.uniqueExts).forEach(function (key) {
var unique = this.uniqueExts[key];
Expand Down
2 changes: 1 addition & 1 deletion lib/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ module.exports = {
parseTasks: function (options) {
options = options || {};

var utilExtensions = /%f|%e/g;
var utilExtensions = /%f|%e|%d/g;
var tasksByNames = {};

var tasksPromises = Object.keys(options).map(function (name) {
Expand Down
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ Valid extended replacements are:

* **%f** - this will be replaced with the filename, without an extension.
* **%e** - this will be replaced with the extension including the `.` character.
* **%d** - this will be replaced with the directory name.

###### Stream replacements:
Everywhere a string replacement can be given, a stream of vinyl is also accepted. The content of each file will be treated as UTF-8 text and used for replacement. If the stream produces more than a file the behavior is the same as when an array is given.
Expand Down