1 | [![NPM version][npm-img]][npm-url]
|
2 | [![Build status][travis-img]][travis-url]
|
3 | [![Test coverage][coveralls-img]][coveralls-url]
|
4 | [![License][license-img]][license-url]
|
5 | [![Dependency status][david-img]][david-url]
|
6 |
|
7 | ### gulp-file-include
|
8 | a plugin of gulp for file include
|
9 |
|
10 | ### install
|
11 | ```bash
|
12 | npm install gulp-file-include
|
13 | ```
|
14 |
|
15 | ### options
|
16 |
|
17 | * options - type: `string`, just as prefix, default `@@`, and basepath is default `@file`
|
18 |
|
19 | ```js
|
20 | fileinclude('@@')
|
21 | ```
|
22 |
|
23 | * options - type: `object`
|
24 | - prefix: `string`, default `@@`
|
25 | - basepath: `string`, default `@file`, it could be `@root`, `@file`, `your-basepath`
|
26 | - filters: `object`, filters of include content
|
27 | - context: `object`, context of `if` statement
|
28 |
|
29 | * options.basepath - type: `string`, it could be
|
30 | - `@root`, include file relative to the dir where `gulp` running in
|
31 | - `@file`, include file relative to the dir where `file` in [example](example)
|
32 | - `your-basepath` include file relative to the basepath you give
|
33 |
|
34 | ```js
|
35 | fileinclude({
|
36 | prefix: '@@',
|
37 | basepath: '@file'
|
38 | })
|
39 | ```
|
40 |
|
41 | **important**: `@file` is relative to the `file` pass to gulp, not the file `include expression` in, see [example](example)
|
42 |
|
43 | ```js
|
44 | fileinclude({
|
45 | prefix: '@@',
|
46 | basepath: '/home/'
|
47 | })
|
48 | ```
|
49 |
|
50 | ### example
|
51 |
|
52 | index.html
|
53 | ```html
|
54 | <!DOCTYPE html>
|
55 | <html>
|
56 | <body>
|
57 | @@include('./view.html')
|
58 | @@include('./var.html', {
|
59 | "name": "haoxin",
|
60 | "age": 12345
|
61 | })
|
62 | </body>
|
63 | </html>
|
64 | ```
|
65 |
|
66 | view.html
|
67 | ```html
|
68 | <h1>view</h1>
|
69 | ```
|
70 |
|
71 | var.html
|
72 | ```html
|
73 | <label>@@name</label>
|
74 | <label>@@age</label>
|
75 | ```
|
76 |
|
77 | gulpfile.js
|
78 | ```js
|
79 | var fileinclude = require('gulp-file-include'),
|
80 | gulp = require('gulp');
|
81 |
|
82 | gulp.task('fileinclude', function() {
|
83 | gulp.src(['index.html'])
|
84 | .pipe(fileinclude({
|
85 | prefix: '@@',
|
86 | basepath: '@file'
|
87 | }))
|
88 | .pipe(gulp.dest('./'));
|
89 | });
|
90 | ```
|
91 |
|
92 | and the result is:
|
93 | ```html
|
94 | <!DOCTYPE html>
|
95 | <html>
|
96 | <body>
|
97 | <h1>view</h1>
|
98 | <label>haoxin</label>
|
99 | <label>12345</label>
|
100 | </body>
|
101 | </html>
|
102 | ```
|
103 |
|
104 | ### filters
|
105 |
|
106 | ```html
|
107 | <!DOCTYPE html>
|
108 | <html>
|
109 | <body>
|
110 | @@include(markdown('view.md'))
|
111 | @@include('./var.html', {
|
112 | "name": "haoxin",
|
113 | "age": 12345
|
114 | })
|
115 | </body>
|
116 | </html>
|
117 | ```
|
118 |
|
119 | view.md
|
120 | ```html
|
121 | view
|
122 | ====
|
123 | ```
|
124 |
|
125 | ```js
|
126 | var fileinclude = require('gulp-file-include'),
|
127 | markdown = require('markdown'),
|
128 | gulp = require('gulp');
|
129 |
|
130 | gulp.task('fileinclude', function() {
|
131 | gulp.src(['index.html'])
|
132 | .pipe(fileinclude({
|
133 | filters: {
|
134 | markdown: markdown.parse
|
135 | }
|
136 | }))
|
137 | .pipe(gulp.dest('./'));
|
138 | });
|
139 | ```
|
140 |
|
141 | ### `if` statement
|
142 |
|
143 | ```js
|
144 | fileinclude({
|
145 | context: {
|
146 | name: 'test'
|
147 | }
|
148 | });
|
149 | ```
|
150 |
|
151 | ```html
|
152 | @if (context.name === 'test') {
|
153 | @@include('test.html')
|
154 | }
|
155 | ```
|
156 |
|
157 | ### License
|
158 | MIT
|
159 |
|
160 | [npm-img]: https://img.shields.io/npm/v/gulp-file-include.svg?style=flat-square
|
161 | [npm-url]: https://npmjs.org/package/gulp-file-include
|
162 | [travis-img]: https://img.shields.io/travis/coderhaoxin/gulp-file-include.svg?style=flat-square
|
163 | [travis-url]: https://travis-ci.org/coderhaoxin/gulp-file-include
|
164 | [coveralls-img]: https://img.shields.io/coveralls/coderhaoxin/gulp-file-include.svg?style=flat-square
|
165 | [coveralls-url]: https://coveralls.io/r/coderhaoxin/gulp-file-include?branch=master
|
166 | [license-img]: http://img.shields.io/badge/license-MIT-green.svg?style=flat-square
|
167 | [license-url]: http://opensource.org/licenses/MIT
|
168 | [david-img]: https://img.shields.io/david/coderhaoxin/gulp-file-include.svg?style=flat-square
|
169 | [david-url]: https://david-dm.org/coderhaoxin/gulp-file-include
|