sramam / handlebars-dir-render

Renders a source directory of handlebars templates to a destination directory, with a given context

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

handlebars-dir-render

npm license travis status Build status Coverage Status David David
NPM

Given a context and a source directory of handlebars templates, recursively renders all files from source directory to destination directory. Strips and *.hbs & *.handlebars extensions from source directory.

Installation

npm install handlebars-dir-render

Usage

import { render } from 'handlebars-dir-render';
render(srcDir, dstDir, context);

or

const render = require('handlebars-dir-render').render;
render(srcDir, dstDir, context);

API

/**
 * Recursively renders template files in srcDir to dstDir.
 * Strips any *.hbs and *.handlebars extensions from source files.
 * Provides the ability to filter files in source directory.
 *
 * @param srcDir   source directory with template
 * @param dstDir   destination directory
 * @param context  The handlerbars context object
 * @param filter   (optional) function to filter files. Defaults to null - all files are processed.
 *                 signature: ({path: string, stats: fstats}) => boolean
 * @param options  (optional) { handlebars: anHandlebarsInstance, hb_options: handlebar-options }
 */
async function render (
  srcDir: string,
  dstDir: string,
  context: any,
  filter: (File) => boolean = null,
  options: Options = null
): Promise<string[]>

License

Apache-2.0

Support

Bugs, PRs, comments, suggestions welcomed!

About

Renders a source directory of handlebars templates to a destination directory, with a given context

License:Apache License 2.0


Languages

Language:TypeScript 61.6%Language:JavaScript 38.4%