# requirejs-hogan-plugin

> A requirejs wrapper for the mustache compiler.

Latest version **0.3.1** (published 2013-09-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install requirejs-hogan-plugin
pnpm add requirejs-hogan-plugin
yarn add requirejs-hogan-plugin
bun add requirejs-hogan-plugin
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.1 |
| Published | 2013-09-26 |
| First published | 2013-09-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 77 |
| Author | Millermedeiros |
| Maintainers | millermedeiros |
| Keywords | mustache, template, requirejs |

## Links

- npm: https://www.npmjs.com/package/requirejs-hogan-plugin
- Repository: https://github.com/millermedeiros/requirejs-hogan-plugin
- Issues: https://github.com/millermedeiros/requirejs-hogan-plugin/issues
- npm.io page: https://npm.io/package/requirejs-hogan-plugin

## Recent versions

- 0.3.1 (latest) — 2013-09-26

## README

# RequireJS mustache / hogan.js plugin

Load mustache / [hogan.js](http://twitter.github.com/hogan.js/) templates
dynamically during development and compile them during build to achieve greater
performance.



## Basic Usage

Define an external template like `foo.mustache`:

```mustache
<div class="foo">
    <h1>{{title}}</h1>
    <ul>
        {{#names}}
        <li>{{.}}</li>
        {{/names}}
    </ul>
</div>
```

Load it with the `hgn` plugin:

```js
// this will load the "foo.mustache" file
require(['hgn!foo'], function(foo){
    // the plugin will return the `render()` method of the `Hogan.Template`
    var markup = foo({
        title : 'Hello!',
        names : ['world', 'foo bar', 'lorem ipsum', 'nurse']
    });
    console.log(markup);
});
```

During development the template file will be loaded using the [RequireJS text
plugin](https://github.com/requirejs/text) and template will be compiled
automatically. During optimization it will pre-compile the template and store
it as pure JavaScript for better performance:

```js
define("hgn!foo", ["hogan"], function(hogan){  var tmpl = new hogan.Template(function(c,p,i){var _=this;_.b(i=i||"");_.b("<div class=\"foo\">\r");_.b("\n" + i);_.b("    <h1>");_.b(_.v(_.f("title",c,p,0)));_.b("</h1>\r");_.b("\n" + i);_.b("    <ul>\r");_.b("\n" + i);if(_.s(_.f("names",c,p,1),c,p,0,71,105,"{{ }}")){_.rs(c,p,function(c,p,_){_.b("        <li>");_.b(_.v(_.d(".",c,p,0)));_.b("</li>\r");_.b("\n");});c.pop();}_.b("    </ul>\r");_.b("\n" + i);_.b("</div>\r");_.b("\n");return _.fl();;}, "", hogan);  return function(){ return tmpl.render.apply(tmpl, arguments); };});;
```

The plugin code is only required for dynamic load so you can use the `r.js`
setting `stubModules` to remove the `text!` and `hgn!` plugins during build,
see `test/build.js` for example.



## Example

Example files are inside the `test` folder, to test build run:

```bash
cd test
node build
```

It will update the `test/scripts/main_built.js` file.



## Changelog

### v0.3.1 (2013/09/26)

 - update text plugin to 2.0.10 fixing bug related to node-webkit.

### v0.3.0 (2013/06/11)

 - update Hogan to v3.0

### v0.2.1 (2013/02/08)

 - add `template` property to the compiled template.
 - fix in case `config.hgn` isn't defined.

### v0.2.0 (2012/06/29)

 - add `compilationOptions` support.
 - add pragmas to remove compiler during build.
 - return `Template#render` method instead of the `Hogan.template` object.

### v0.1.0 (2012/06/18)

 - initial release.



## License

Released under the MIT license.



## Other plugins

You should also check the awesome [RequireJS Handlebars
Plugin](https://github.com/SlexAxton/require-handlebars-plugin) created by Alex
Sexton and the [list of plugins on RequireJS
wiki](https://github.com/jrburke/requirejs/wiki/Plugins).

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