# gulp-hogan-compile

> A gulp plugin to compile mustache HTML templates to JavaScript functions using hogan.

Latest version **2.0.0** (published 2019-11-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install gulp-hogan-compile
pnpm add gulp-hogan-compile
yarn add gulp-hogan-compile
bun add gulp-hogan-compile
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2019-11-24 |
| First published | 2014-02-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=8 |
| Dependencies | 4 |
| Unpacked size | 13.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8 |
| Author | Paul Willoughby |
| Maintainers | paulwib |
| Keywords | gulpplugin, templates, mustache, hogan |

## Links

- npm: https://www.npmjs.com/package/gulp-hogan-compile
- Repository: https://github.com/paulwib/gulp-hogan-compile
- Issues: https://github.com/paulwib/gulp-hogan-compile/issues
- npm.io page: https://npm.io/package/gulp-hogan-compile

## Dependencies (4)

- [vinyl](https://npm.io/package/vinyl.md) ^2.2.0
- [through](https://npm.io/package/through.md) ^2.3.0
- [hogan.js](https://npm.io/package/hogan.js.md) ^3.0.0
- [plugin-error](https://npm.io/package/plugin-error.md) ^1.0.1

## Recent versions

- 2.0.0 (latest) — 2019-11-24
- 1.0.2 — 2016-10-04
- 1.0.1 — 2016-10-04
- 1.0.0 — 2016-10-04
- 0.5.0 — 2016-09-05
- 0.4.1 — 2014-10-27
- 0.4.0 — 2014-10-27
- 0.2.1 — 2014-03-04
- 0.1.2 — 2014-02-25

## README

gulp-hogan-compile [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url]
===

A [gulp][] plugin to compile [mustache][] HTML templates to JavaScript functions using [hogan][].

## Usage

In `templates/test.html`:

```html
<p>Hello {{place}}</p>
```

In your gulpfile:

```javascript
var compiler = require('gulp-hogan-compile');

gulp.task('templates', function() {
    gulp.src('templates/**/*.html')
        .pipe(compiler('templates.js'))
        .pipe(gulp.dest('js/'));
});
```

In your code:

```javascript
    var templates = require('js/templates.js');
    var html = templates.test.render({
        place: 'world';
    })
    console.log(html); // <p>Hello world</p>
```

This will compile the templates into a JavaScript AMD module using `hogan.compile`.

It will `require('hogan')` so that module needs to be available. You can change the name/path of the hogan module at compile time  with `options.hoganModule`.

Alternatively you can pass an object to have it populated with executable templates, which is useful if you need templates as part of a build step, for example:

```javascript
var compiler = require('gulp-hogan-compile');
var templates = {};

gulp.task('templates', function() {
    gulp.src('templates/**/*.html')
        .pipe(compiler(templates));
});

gulp.task('render', ['templates'], function() {
    // Do something with templates, like passing to a static site generator
});
```

## Parameters

* dest `string|object`
    * Either the name of a file or an object - if using an object it will be populated with compiled template code and no file will be outputted (so all string output related options below are ignored)
* options `object`
    * Options passed to the hogan task

## Options

### newLine `string`

The line delimiter, defaults to your operating system's newline. Ignored if `dest` is an object.

### wrapper `string`

Either `amd`, `commonjs` or `false` for no wrapper, defaults to `amd`. If wrapper is `false` a local var `templates` will be defined containing the templates. Ignored if `dest` is an object.

### templateOptions `object`

Options passed through to `hogan.compile`. The `asString` option will be set depending on whether output is a file or an object, any passed setting is ignored.

### templateName `function(file)`

A function that will be passed the file and should return a name for the template. By default uses the relative path and basename of the file without an extension.

### templatesVariableName `'templates'`

Override the variable name used for the templates, default is `templates`. Useful when not using a wrapper in the browser and don't want it assigned to `window.templates`.

### hoganModule `string`

The name of the hogan module *in your app*, defaults to `hogan`. If you're not using a wrapper then the global `Hogan` must be available.

[gulp]:http://gulpjs.com
[mustache]:http://mustache.github.io
[hogan]:https://github.com/twitter/hogan.js

[npm-url]: https://npmjs.org/package/gulp-hogan-compile
[npm-image]: http://img.shields.io/npm/v/gulp-hogan-compile.svg?style=flat

[travis-image]: https://travis-ci.org/paulwib/gulp-hogan-compile.svg
[travis-url]: https://travis-ci.org/paulwib/gulp-hogan-compile

---
_Source: https://npm.io/package/gulp-hogan-compile · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
