From 00b7a9e3551c60f2c593731e2c99a45c05d9a818 Mon Sep 17 00:00:00 2001 From: Joseph Tuskan Date: Wed, 7 Sep 2016 17:16:48 -0400 Subject: [PATCH] Added %d as an extended replacement for directory name --- lib/block.js | 5 ++++- lib/common.js | 2 +- readme.md | 1 + 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/block.js b/lib/block.js index 636f59f..9b5b58b 100644 --- a/lib/block.js +++ b/lib/block.js @@ -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]; diff --git a/lib/common.js b/lib/common.js index e5cf75c..ddecf32 100644 --- a/lib/common.js +++ b/lib/common.js @@ -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) { diff --git a/readme.md b/readme.md index 69c0798..31215bc 100644 --- a/readme.md +++ b/readme.md @@ -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.