1 | # gulp-wrap [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][depstat-image]][depstat-url]
|
2 |
|
3 | > A gulp plugin to wrap the stream contents with a lodash template. [gulp](https://github.com/gulpjs/gulp)
|
4 |
|
5 | ## Usage
|
6 |
|
7 | First, install `gulp-wrap` as a development dependency:
|
8 |
|
9 | ```shell
|
10 | npm install --save-dev gulp-wrap
|
11 | ```
|
12 |
|
13 | Then, add it to your `gulpfile.js`:
|
14 |
|
15 | **Wrap the contents with an inline template:**
|
16 |
|
17 | ```javascript
|
18 | var wrap = require("gulp-wrap");
|
19 |
|
20 | gulp.src("./src/*.json")
|
21 | .pipe(wrap('angular.module(\'text\', []).value(<%= contents %>);'))
|
22 | .pipe(gulp.dest("./dist"));
|
23 | ```
|
24 |
|
25 | **Wrap the contents with a template from file:**
|
26 |
|
27 | ```javascript
|
28 | var wrap = require("gulp-wrap");
|
29 |
|
30 | gulp.src("./src/*.json")
|
31 | .pipe(wrap({ src: 'path/to/template.txt'}))
|
32 | .pipe(gulp.dest("./dist"));
|
33 | ```
|
34 |
|
35 | **Provide additional data and options for template processing:**
|
36 |
|
37 | ```javascript
|
38 | var wrap = require("gulp-wrap");
|
39 |
|
40 | gulp.src("./src/*.json")
|
41 | .pipe(wrap('BEFORE <%= data.contents %> <%= data.someVar %> AFTER', { someVar: 'someVal'}, { variable: 'data' }))
|
42 | .pipe(gulp.dest("./dist"));
|
43 | ```
|
44 |
|
45 | ## API
|
46 |
|
47 | ### wrap(template\[,data\]\[,options\])
|
48 |
|
49 | #### template
|
50 | Type: `String` or `Object
|
51 |
|
52 | The template to used. When a `String` then it will be used as the template. When an `Object` then the template will be loaded from file.
|
53 |
|
54 | #### template.src
|
55 | Type: `String`
|
56 |
|
57 | The file location of the template.
|
58 |
|
59 | #### data
|
60 | Type: `Object`
|
61 |
|
62 | The data object that is passed on to the [lodash](http://lodash.com/docs#template) template call.
|
63 |
|
64 | #### options
|
65 | Type: `Object`
|
66 |
|
67 | The options object that is passed on to the [lodash](http://lodash.com/docs#template) template call.
|
68 |
|
69 | ## License
|
70 |
|
71 | [MIT License](http://en.wikipedia.org/wiki/MIT_License)
|
72 |
|
73 | [npm-url]: https://npmjs.org/package/gulp-wrap
|
74 | [npm-image]: https://badge.fury.io/js/gulp-wrap.png
|
75 |
|
76 | [travis-url]: http://travis-ci.org/adamayres/gulp-wrap
|
77 | [travis-image]: https://secure.travis-ci.org/adamayres/gulp-wrap.png?branch=master
|
78 |
|
79 | [depstat-url]: https://david-dm.org/adamayres/gulp-wrap
|
80 | [depstat-image]: https://david-dm.org/adamayres/gulp-wrap.png
|