Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mikehazell/gulp-inject-string

Inject snippets in build
https://github.com/mikehazell/gulp-inject-string

Last synced: 16 days ago
JSON representation

Inject snippets in build

Awesome Lists containing this project

README

        

# gulp-inject-string

[![Build Status](https://travis-ci.org/mikehazell/gulp-inject-string.svg?branch=master)](https://travis-ci.org/mikehazell/gulp-inject-string)
[![NPM version](https://badge.fury.io/js/gulp-inject-string.svg)](http://badge.fury.io/js/gulp-inject-string)

Inject snippets in build

## Methods

```js
append(str) // Appends the string
prepend(str) // Prepends the string
wrap(start, end) // Wraps file contents in between *start* and *end*
before(search, str) // Inserts the string before the first occurence of *search*
after(search, str) // Inserts the string after the first occurence of *search*
beforeEach(search, str) // Inserts the string before each occurence of *search*
afterEach(search, str) // Inserts the string after each occurence of *search*
replace(search, str) // Replaces each occurence of *search* with *str*
```

## Examples

See [examples/build](https://github.com/mikehazell/gulp-inject-string/tree/master/examples/build) for output.

```js

var gulp = require('gulp'),
rename = require('gulp-rename'),
inject = require('gulp-inject-string');

gulp.task('inject:append', function(){
gulp.src('src/example.html')
.pipe(inject.append('\n'))
.pipe(rename('append.html'))
.pipe(gulp.dest('build'));
});

gulp.task('inject:prepend', function(){
gulp.src('src/example.html')
.pipe(inject.prepend('\n'))
.pipe(rename('prepend.html'))
.pipe(gulp.dest('build'));
});

gulp.task('inject:wrap', function(){
gulp.src('src/example.html')
.pipe(inject.wrap('\n', ''))
.pipe(rename('wrap.html'))
.pipe(gulp.dest('build'));
});

gulp.task('inject:before', function(){
gulp.src('src/example.html')
.pipe(inject.before('\n'))
.pipe(rename('before.html'))
.pipe(gulp.dest('build'));
});

gulp.task('inject:after', function(){
gulp.src('src/example.html')
.pipe(inject.after('', '\n\n'))
.pipe(rename('after.html'))
.pipe(gulp.dest('build'));
});

gulp.task('inject:beforeEach', function(){
gulp.src('src/example.html')
.pipe(inject.beforeEach('