Allow you to parse a list of files and replace tokens based on specifics patterns.
Allow you to parse a list of files and replace tokens based on specifics patterns. Inspired by alanshaw / grunt-include-replace.
This plugin requires Grunt
If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
npm install grunt-pattern-replace --save-dev
The task allow you to specify a list of tokens (a multi level dictionary), which allow you to replace in several files placeholder "variable". Your placeholder variables can be prefixed and suffixed, by example : [[alpha]]. You can use a dot separated variable, it allow you to group your keys logically : [[alpha.beta]] will match with the child key beta of the object alpha.
At the moment, only single file examples are provided. More tests will come soon.
In your project's Gruntfile, add a section named
patternReplace to the data object passed into
gruntinitConfigpatternReplace:options:// Task-specific options go here.your_target:// Target-specific file lists and/or options go here.
A list of tokens available for replacement in all files.
Variable/include directive prefix.
Variable/include directive suffix.
Default value: Relative to including file
Directory where includes will be resolved.
Default prefix and suffix are
It allows you to define placeholder variables like
In this example,
[[falcon]] would be replaced by
gruntinitConfigpatternReplace:options :tokens :falcon : "punch"bankai :ichigo : "Tenza Zengetsu"expand : truecwd : "source/folder/"dest : "dest/folder"src : "file";
Same example while replacing default prefix and suffix.
Placeholder variables would be now
gruntinitConfigpatternReplace:options :prefix : "\\(\\("suffix : "\\)\\)"tokens :falcon : "punch"bankai :ichigo : "Tenza Zengetsu"expand : truecwd : "source/folder/"dest : "dest/folder"src : "file";
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.