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 | ```js
|
42 | fileinclude({
|
43 | prefix: '@@',
|
44 | basepath: '/home/'
|
45 | })
|
46 | ```
|
47 |
|
48 | ### example
|
49 |
|
50 | index.html
|
51 | ```html
|
52 | <!DOCTYPE html>
|
53 | <html>
|
54 | <body>
|
55 | @@include('./view.html')
|
56 | @@include('./var.html', {
|
57 | "name": "haoxin",
|
58 | "age": 12345
|
59 | })
|
60 | </body>
|
61 | </html>
|
62 | ```
|
63 |
|
64 | view.html
|
65 | ```html
|
66 | <h1>view</h1>
|
67 | ```
|
68 |
|
69 | var.html
|
70 | ```html
|
71 | <label>@@name</label>
|
72 | <label>@@age</label>
|
73 | ```
|
74 |
|
75 | gulpfile.js
|
76 | ```js
|
77 | var fileinclude = require('gulp-file-include'),
|
78 | gulp = require('gulp');
|
79 |
|
80 | gulp.task('fileinclude', function() {
|
81 | gulp.src(['index.html'])
|
82 | .pipe(fileinclude({
|
83 | prefix: '@@',
|
84 | basepath: '@file'
|
85 | }))
|
86 | .pipe(gulp.dest('./'));
|
87 | });
|
88 | ```
|
89 |
|
90 | and the result is:
|
91 | ```html
|
92 | <!DOCTYPE html>
|
93 | <html>
|
94 | <body>
|
95 | <h1>view</h1>
|
96 | <label>haoxin</label>
|
97 | <label>12345</label>
|
98 | </body>
|
99 | </html>
|
100 | ```
|
101 |
|
102 | ### filters
|
103 |
|
104 | ```html
|
105 | <!DOCTYPE html>
|
106 | <html>
|
107 | <body>
|
108 | @@include(markdown('view.md'))
|
109 | @@include('./var.html', {
|
110 | "name": "haoxin",
|
111 | "age": 12345
|
112 | })
|
113 | </body>
|
114 | </html>
|
115 | ```
|
116 |
|
117 | view.md
|
118 | ```html
|
119 | view
|
120 | ====
|
121 | ```
|
122 |
|
123 | ```js
|
124 | var fileinclude = require('gulp-file-include'),
|
125 | markdown = require('markdown'),
|
126 | gulp = require('gulp');
|
127 |
|
128 | gulp.task('fileinclude', function() {
|
129 | gulp.src(['index.html'])
|
130 | .pipe(fileinclude({
|
131 | filters: {
|
132 | markdown: markdown.parse
|
133 | }
|
134 | }))
|
135 | .pipe(gulp.dest('./'));
|
136 | });
|
137 | ```
|
138 |
|
139 | ### `if` statement
|
140 |
|
141 | ```js
|
142 | fileinclude({
|
143 | context: {
|
144 | name: 'test'
|
145 | }
|
146 | });
|
147 | ```
|
148 |
|
149 | ```html
|
150 | @@include('some.html', { "nav": true })
|
151 |
|
152 | @@if (name === 'test' && nav === true) {
|
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
|