forked from lazd/gulp-replace
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
193 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/node_modules | ||
/*.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
language: node_js | ||
node_js: | ||
- 0.6 | ||
- 0.7 | ||
- 0.8 | ||
- 0.9 | ||
- 0.10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,45 @@ | ||
gulp-replacer | ||
============= | ||
# gulp-replace [![NPM version][npm-image]][npm-url] [![Build status][travis-image]][travis-url] | ||
> A string replace plugin for gulp 3 | ||
A Gulp plugin that replaces strings | ||
## Usage | ||
|
||
First, install `gulp-replace` as a development dependency: | ||
|
||
```shell | ||
npm install --save-dev gulp-replace | ||
``` | ||
|
||
Then, add it to your `gulpfile.js`: | ||
|
||
```javascript | ||
var jshint = require('gulp-replace'); | ||
|
||
gulp.task('templates', function(){ | ||
gulp.src(['file.txt']) | ||
.pipe(replace(/foo(.{3})/g, '$1foo')) | ||
.pipe(gulp.dest('build/file.txt')); | ||
}); | ||
``` | ||
|
||
## API | ||
|
||
### replace(search, replace) | ||
|
||
#### search | ||
Type: `RegExp` | ||
|
||
The regex pattern to search for. See the [MDN documentation for RegExp] for details. | ||
|
||
#### replace | ||
Type: `String` or `Function` | ||
|
||
The replacement string or function. See the [MDN documentation for String.replace] for details. | ||
|
||
|
||
[MDN documentation for RegExp]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp | ||
[MDN documentation for String.replace]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#Specifying_a_string_as_a_parameter | ||
|
||
[travis-url]: http://travis-ci.org/lazd/gulp-replace | ||
[travis-image]: https://secure.travis-ci.org/lazd/gulp-replace.png?branch=master | ||
[npm-url]: https://npmjs.org/package/gulp-replace | ||
[npm-image]: https://badge.fury.io/js/gulp-replace.png |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
var es = require('event-stream'); | ||
|
||
module.exports = function(search, replace) { | ||
var doRegexReplace = function(file, callback) { | ||
var result = String(file.contents).replace(search, replace); | ||
|
||
file.contents = new Buffer(result); | ||
|
||
callback(null, file); | ||
}; | ||
|
||
return es.map(doRegexReplace); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"name": "gulp-replace", | ||
"version": "0.1.0", | ||
"description": "A string replace plugin for gulp", | ||
"main": "index.js", | ||
"dependencies": { | ||
"event-stream": "~3.0.18" | ||
}, | ||
"devDependencies": { | ||
"should": "~2.1.1", | ||
"mocha": "~1.15.1", | ||
"gulp-util": "~2.0.0" | ||
}, | ||
"scripts": { | ||
"test": "./node_modules/.bin/mocha" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/lazd/gulp-replace.git" | ||
}, | ||
"keywords": [ | ||
"gulpplugin", | ||
"replace" | ||
], | ||
"author": "Larry Davis <[email protected]>", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/lazd/gulp-replace/issues" | ||
}, | ||
"engines": { | ||
"node": ">=0.8" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
define(['handlebars'], function(Handlebars) {return Handlebars.template(function (Handlebars,depth0,helpers,partials,data) { | ||
this.compilerInfo = [4,'>= 1.0.0']; | ||
helpers = this.merge(helpers, Handlebars.helpers); data = data || {}; | ||
|
||
|
||
|
||
return "Basic template"; | ||
});}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Handlebars.template(function (Handlebars,depth0,helpers,partials,data) { | ||
this.compilerInfo = [4,'>= 1.0.0']; | ||
helpers = this.merge(helpers, Handlebars.helpers); data = data || {}; | ||
|
||
|
||
|
||
return "Basic template"; | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
function (Handlebars,depth0,helpers,partials,data) { | ||
this.compilerInfo = [4,'>= 1.0.0']; | ||
helpers = this.merge(helpers, Handlebars.helpers); data = data || {}; | ||
|
||
|
||
|
||
return "Basic template"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
this["Basic"] = Handlebars.template(function (Handlebars,depth0,helpers,partials,data) { | ||
this.compilerInfo = [4,'>= 1.0.0']; | ||
helpers = this.merge(helpers, Handlebars.helpers); data = data || {}; | ||
|
||
|
||
|
||
return "Basic template"; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module.exports = function(Handlebars) {return Handlebars.template(function (Handlebars,depth0,helpers,partials,data) { | ||
this.compilerInfo = [4,'>= 1.0.0']; | ||
helpers = this.merge(helpers, Handlebars.helpers); data = data || {}; | ||
|
||
|
||
|
||
return "Basic template"; | ||
});}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
(function(g) {var Handlebars = g.Handlebars || require('handlebars');var template = Handlebars.template(function (Handlebars,depth0,helpers,partials,data) { | ||
this.compilerInfo = [4,'>= 1.0.0']; | ||
helpers = this.merge(helpers, Handlebars.helpers); data = data || {}; | ||
|
||
|
||
|
||
return "Basic template"; | ||
});if (typeof exports === 'object' && exports) module.exports = template;this["Basic"] = template;}(typeof window !== 'undefined' ? window : global)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
var Handlebars = global.Handlebars || require('handlebars');module.exports = Handlebars.template(function (Handlebars,depth0,helpers,partials,data) { | ||
this.compilerInfo = [4,'>= 1.0.0']; | ||
helpers = this.merge(helpers, Handlebars.helpers); data = data || {}; | ||
|
||
|
||
|
||
return "Basic template"; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Basic template |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
var replacePlugin = require('../'); | ||
var path = require('path'); | ||
var should = require('should'); | ||
var gutil = require('gulp-util'); | ||
require('mocha'); | ||
|
||
var makeFile = function(contents) { | ||
return new gutil.File({ | ||
path: 'test/file.txt', | ||
cwd: 'test/', | ||
base: 'test/', | ||
contents: contents | ||
}); | ||
}; | ||
|
||
describe('gulp-replace', function() { | ||
describe('replacePlugin()', function() { | ||
it('should replace regular expression', function(done) { | ||
var file = makeFile('foobar foobaz'); | ||
|
||
var stream = replacePlugin(/foo(.{3})/g, '$1foo'); | ||
stream.on('data', function(newFile) { | ||
should.exist(newFile); | ||
should.exist(newFile.contents); | ||
String(newFile.contents).should.equal('barfoo bazfoo'); | ||
}); | ||
|
||
stream.once('end', function() { | ||
done(); | ||
}); | ||
|
||
stream.write(file); | ||
stream.end(); | ||
}); | ||
|
||
}); | ||
}); |