@@title
@@text
A gulp plugin for file include
npm install gulp-file-include[![NPM version][npm-img]][npm-url]
[![Build status][travis-img]][travis-url]
[![Test coverage][coveralls-img]][coveralls-url]
[![License][license-img]][license-url]
[![Dependency status][david-img]][david-url]
[![Gitter][gitter-img]][gitter-url]
``bash`
npm install --save-dev gulp-file-include
`js`
const fileinclude = require('gulp-file-include');
#### prefix
Type: string'@@'
Default:
#### options
Type: object
##### options.prefix
Type: string'@@'
Default:
##### options.suffix
Type: string''
Default:
##### options.basepath
Type: string'@file'
Default:
Possible values:
- '@file': include file relative to the dir in which file resides (example)'@root'
- : include file relative to the dir in which gulp is runningpath/to/dir
- : include file relative to the basepath you provide
##### options.filters
Type: objectfalse
Default:
Filters of include content.
##### options.context
Type: object{}
Default:
Context of if statement.
##### options.indent
Type: booleanfalse
Default:
index.html
`html`
@@include('./view.html')
@@include('./var.html', {
"name": "haoxin",
"age": 12345,
"socials": {
"fb": "facebook.com/include",
"tw": "twitter.com/include"
}
})
view.html
`html`view
var.html
`html`
@@socials.fb
@@socials.tw
gulpfile.js
`js
const fileinclude = require('gulp-file-include');
const gulp = require('gulp');
gulp.task('fileinclude', function() {
gulp.src(['index.html'])
.pipe(fileinclude({
prefix: '@@',
basepath: '@file'
}))
.pipe(gulp.dest('./'));
});
`
result:
`html`
view
facebook.com/include
twitter.com/include
index.html
`html`
@@include_once('./view.html')
@@include_once('./var.html', {
"name": "haoxin",
"age": 12345,
"socials": {
"fb": "facebook.com/include",
"tw": "twitter.com/include"
}
})
@@include_once('./var.html', {
"name": "haoxin",
"age": 12345,
"socials": {
"fb": "facebook.com/include",
"tw": "twitter.com/include"
}
})
view.html
`html`view
var.html
`html`
@@socials.fb
@@socials.tw
gulpfile.js
`js
const fileinclude = require('gulp-file-include');
const gulp = require('gulp');
gulp.task('fileinclude', function() {
gulp.src(['index.html'])
.pipe(fileinclude({
prefix: '@@',
basepath: '@file'
}))
.pipe(gulp.dest('./'));
});
`
result:
`html
view
facebook.com/include
twitter.com/include
`
index.html
`html`
@@include(markdown('view.md'))
@@include('./var.html', {
"name": "haoxin",
"age": 12345
})
view.md
`html`
view
====
gulpfile.js
`js
const fileinclude = require('gulp-file-include');
const markdown = require('markdown');
const gulp = require('gulp');
gulp.task('fileinclude', function() {
gulp.src(['index.html'])
.pipe(fileinclude({
filters: {
markdown: markdown.parse
}
}))
.pipe(gulp.dest('./'));
});
`
index.html
`
@@include('some.html', { "nav": true })
@@if (name === 'test' && nav === true) {
@@include('test.html')
}
`
gulpfile.js
`js`
fileinclude({
context: {
name: 'test'
}
});
index.html
`html+arr[i]+
@@for (var i = 0; i < arr.length; i++) {
`
}
gulpfile.js
`js`
fileinclude({
context: {
arr: ['test1', 'test2']
}
});
index.html lorem ipsum... lorem ipsum... lorem ipsum...
`html`
@@loop('loop-article.html', [
{ "title": "My post title", "text": "
{ "title": "Another post", "text": "
{ "title": "One more post", "text": "
])
loop-article.html
`html`
@@title
@@text
data.json lorem ipsum... lorem ipsum... lorem ipsum...
`js`
[
{ "title": "My post title", "text": "
{ "title": "Another post", "text": "
{ "title": "One more post", "text": "
]
loop-article.html
`html`
@@loop("loop-article.html", "data.json")
The webRoot field of the context contains the relative path from the source document to
the source root (unless the value is already set in the context options).
support/contact/index.html
`html
Support Contact Info