gulp-advanced-file-include

0.1.1 • Public • Published

NPM version License

gulp-file-include

a plugin of gulp for file include

install

npm install gulp-file-include

options

  • options - type: string, just as prefix, default @@, and basepath is default @file
fileinclude('@@')
  • options - type: object

    • prefix: string, default @@
    • suffix: string, default ''
    • basepath: string, default @file, it could be @root, @file, your-basepath
    • filters: object, filters of include content
    • context: object, context of if statement
    • indent: boolean, default false
  • options.basepath - type: string, it could be

    • @root, include file relative to the dir where gulp running in
    • @file, include file relative to the dir where file in example
    • your-basepath include file relative to the basepath you give
fileinclude({
  prefix: '@@',
  basepath: '@file'
})
fileinclude({
  prefix: '@@',
  basepath: '/home/'
})

example

index.html

<!DOCTYPE html>
<html>
  <body>
  @@include('./view.html')
  @@include('./var.html', {
    "name": "haoxin",
    "age": 12345,
    "socials": {
      "fb": "facebook.com/include",
      "tw": "twitter.com/include"
    }
  })
  </body>
</html>

view.html

<h1>view</h1>

var.html

<label>@@name</label>
<label>@@age</label>
<strong>@@socials.fb</strong>
<strong>@@socials.tw</strong>

gulpfile.js

var fileinclude = require('gulp-file-include'),
  gulp = require('gulp');
 
gulp.task('fileinclude', function() {
  gulp.src(['index.html'])
    .pipe(fileinclude({
      prefix: '@@',
      basepath: '@file'
    }))
    .pipe(gulp.dest('./'));
});

and the result is:

<!DOCTYPE html>
<html>
  <body>
  <h1>view</h1>
  <label>haoxin</label>
<label>12345</label>
<strong>facebook.com/include</strong>
<strong>twitter.com/include</strong>
  </body>
</html>

filters

<!DOCTYPE html>
<html>
  <body>
  @@include(markdown('view.md'))
  @@include('./var.html', {
    "name": "haoxin",
    "age": 12345
  })
  </body>
</html>

view.md

view
====
var fileinclude = require('gulp-file-include'),
  markdown = require('markdown'),
  gulp = require('gulp');
 
gulp.task('fileinclude', function() {
  gulp.src(['index.html'])
    .pipe(fileinclude({
      filters: {
        markdown: markdown.parse
      }
    }))
    .pipe(gulp.dest('./'));
});

if statement

fileinclude({
  context: {
    name: 'test'
  }
});
@@include('some.html', { "nav": true })

@@if (name === 'test' && nav === true) {
  @@include('test.html')
}

foreach statement

fileinclude({
  context: {
    buttons: {
      "button1": {"text": "Cancel"},
      "button2": {"text": "Submit"}
    }
  }
});

@@foreach (buttons) {
  <button name="@@index">@@text</button>
}

License

MIT

Dependencies (6)

Dev Dependencies (0)

    Package Sidebar

    Install

    npm i gulp-advanced-file-include

    Weekly Downloads

    6

    Version

    0.1.1

    License

    none

    Last publish

    Collaborators

    • torbenberger