@hidoo/gulp-task-build-html-handlebars

0.19.0 • Public • Published

@hidoo/gulp-task-build-html-handlebars

Task that build html by handlebars for gulp.

Installation

$ npm install --save-dev gulp@next @hidoo/gulp-task-build-html-handlebars

Usage

import {task} from 'gulp';
import buildHtml from '@hidoo/gulp-task-build-html-handlebars';

task('html', buildHtml({
  src: '/path/to/html/*.hbs',
  dest: '/path/to/dest'
}));

API

buildHtml

return html build task by handlebars

Parameters

  • options Object options (optional, default {})

    • options.name String task name (use as displayName) (optional, default 'build:html')
    • options.src String source path
    • options.dest String destination path
    • options.extname String destination extname (optional, default '.html')
    • options.partials String Handlebars partials files glob pattern (optional, default '')
    • options.layouts String Handlebars layouts files glob pattern (optional, default '')
    • options.helpers String Handlebars helpers files glob pattern (optional, default '')
    • options.data String data files glob pattern (optional, default '')
    • options.compress Boolean compress file or not (optional, default false)
    • options.compressOptions Object? compress options. (see examples for default) see: gulp-htmlmin options.
    • options.onFilesParsed Function<Object> additional process after data files parsed (optional, default (context)=>context)
    • options.onFrontMatterParsed Function<Object> additional process after front matter parsed (optional, default (context)=>context)
    • options.verbose Boolean out log or not (optional, default false)

Examples

import {task} from 'gulp';
import buildHtml from '@hidoo/gulp-task-build-html-handlebars';

task('html', buildHtml({
  name: 'html:main',
  src: '/path/to/html/*.hbs',
  dest: '/path/to/dest',
  extname: '.php',
  partials: '/path/to/html/partials/*.hbs',
  layouts: '/path/to/html/layouts/*.hbs',
  helpers: '/path/to/html/helpers/*.js',
  data: '/path/to/html/data/*.{json,yaml}',
  compress: true,
  // Default for this options
  compressOptions: {
    caseSensitive: true,
    collapseWhitespace: true,
    conservativeCollapse: true,
    preserveLineBreaks: true,
    ignoreCustomFragments: [
      // php start end tags
      /<\?[\s\S]*?\?>/,
      // cms tags
      /<\/?mt:?[\s\S]*?>/i,
      /<\$mt:?[\s\S]*?\$>/i
    ]
  },
  onFilesParsed: (context) => context,
  onFrontMatterParsed: (context) => context,
  verbose: false
}));

Returns Function<Promise>

Template API

Builtin Helpers

See @hidoo/handlebars-helpers.

Template context

global:

name example description
NODE_ENV {{#is NODE_ENV 'production'}}...{{/is}} string of process.env.NODE_ENV
compress {{#if compress}}...{{/if}} value of options.compress
pages {{#each pages}}...{{/each}} array of Front Matter for all pages

path (when file is subdir/index.hbs):

name example description
path.depth {{path.depth}} => ../ depth of file from options.src
path.relative {{path.relative}} => subdir/index.html relative path of file from options.src
path.basename {{path.basename}} => index.html basename of file
path.extname {{path.extname}} => .html extname of file

Test

$ yarn test

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i @hidoo/gulp-task-build-html-handlebars

Weekly Downloads

2

Version

0.19.0

License

MIT

Unpacked Size

28.2 kB

Total Files

6

Last publish

Collaborators

  • hidoo