Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jonschlinkert/engine-handlebars
Handlebars engine, consolidate.js style but with enhancements. This works with Assemble, express.js, engine-cache or any application that follows consolidate.js conventions.
https://github.com/jonschlinkert/engine-handlebars
compile engine engine-handlebars handlebars hbs helpers javascript jonschlinkert node nodejs partial render
Last synced: 4 months ago
JSON representation
Handlebars engine, consolidate.js style but with enhancements. This works with Assemble, express.js, engine-cache or any application that follows consolidate.js conventions.
- Host: GitHub
- URL: https://github.com/jonschlinkert/engine-handlebars
- Owner: jonschlinkert
- License: mit
- Created: 2014-09-06T09:47:42.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2020-08-12T09:09:44.000Z (over 4 years ago)
- Last Synced: 2024-10-01T19:15:06.473Z (4 months ago)
- Topics: compile, engine, engine-handlebars, handlebars, hbs, helpers, javascript, jonschlinkert, node, nodejs, partial, render
- Language: JavaScript
- Homepage: https://github.com/jonschlinkert
- Size: 51.8 KB
- Stars: 7
- Watchers: 3
- Forks: 7
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# engine-handlebars [![NPM version](https://img.shields.io/npm/v/engine-handlebars.svg?style=flat)](https://www.npmjs.com/package/engine-handlebars) [![NPM monthly downloads](https://img.shields.io/npm/dm/engine-handlebars.svg?style=flat)](https://npmjs.org/package/engine-handlebars) [![NPM total downloads](https://img.shields.io/npm/dt/engine-handlebars.svg?style=flat)](https://npmjs.org/package/engine-handlebars) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/engine-handlebars.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/engine-handlebars)
> Handlebars engine, consolidate.js style but with enhancements. This works with Assemble, express.js, engine-cache or any application that follows consolidate.js conventions.
Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support.
## Install
Install with [npm](https://www.npmjs.com/):
```sh
$ npm install --save engine-handlebars
```## Heads up!
There were major [breaking changes in v1.0!](#release-history).
## Usage
```js
const handlebars = require('handlebars');
const engine = require('engine-handlebars')(handlebars);
console.log(engine);
```The `engine` object that is returned has the following properties:
* `name` - the name of the engine: `handlebars`, used for engine detection in other libraries.
* `instance` - your instance of handlebars
* `compile` - async compile method
* `compileSync` - sync compile method
* `render` - async render method
* `renderSync` - sync render method## API
### [.compile](index.js#L49)
Compile `file.contents` with `handlebars.compile()`. Adds a compiled `.fn()` property to the given `file`.
**Params**
* `file` **{Object}**: File object with `contents` string or buffer.
* `options` **{Object}**: Options with partials and helpers.
* `returns` **{Promise}****Example**
```js
engine.compile({ contents: 'Jon {{ name }}' })
.then(file => {
console.log(typeof file.fn) // 'function'
});
```### [.render](index.js#L70)
Render `file.contents` with the function returned from `.compile()`.
**Params**
* `file` **{Object}**: File object with `contents` string or buffer.
* `locals` **{Object}**: Locals to use as contents to render the string.
* `options` **{Object}**: Options with partials and helpers.
* `returns` **{Promise}****Example**
```js
engine.render({ contents: 'Jon {{ name }}' }, { name: 'Schlinkert' })
.then(file => {
console.log(file.contents.toString()) // 'Jon Schlinkert'
});
```### [.compileSync](index.js#L116)
Compile `file.contents` with `handlebars.compile()`. Adds a compiled `.fn()` property to the given `file`.
**Params**
* `file` **{Object}**: File object with `contents` string or buffer.
* `options` **{Object}**: Options with partials and helpers.
* `returns` **{Object}**: Returns the file object.**Example**
```js
let file = engine.compileSync({ contents: 'Jon {{ name }}' });
console.log(typeof file.fn) // 'function'
```### [.renderSync](index.js#L146)
Render `file.contents` with the function returned from `.compile()`.
**Params**
* `file` **{Object}**: File object with `contents` string or buffer.
* `locals` **{Object}**: Locals to use as contents to render the string.
* `options` **{Object}**: Options with partials and helpers.
* `returns` **{Object}**: Returns the file object.**Example**
```js
let file = engine.renderSync({ contents: 'Jon {{ name }}' }, { name: 'Schlinkert' });
console.log(file.contents.toString()) // 'Jon Schlinkert'
```## Release History
### v1.0.0
* The main export is now a function that takes an instance of handlebars.
* `renderFile` and `__express` have been removed.
* `.compile` and `.render` now return a promise.
* `.compileSync` and `.renderSync` may be used for sync operations.
* All methods now expect a `file` object with a `.contents` property (string or buffer).### v0.8.0
* `renderFile` now expects a [vinyl](https://github.com/gulpjs/vinyl) file.
* The old renderFile method is now exposed on `engine.__express`### v0.7.0
* updated to handlebars 0.4.0
## About
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
Running Tests
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
```sh
$ npm install && npm test
```Building docs
_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_
To generate the readme, run the following command:
```sh
$ npm install -g verbose/verb#dev verb-generate-readme && verb
```### Related projects
You might also be interested in these projects:
* [assemble](https://www.npmjs.com/package/assemble): Get the rocks out of your socks! Assemble makes you fast at creating web projects… [more](https://github.com/assemble/assemble) | [homepage](https://github.com/assemble/assemble "Get the rocks out of your socks! Assemble makes you fast at creating web projects. Assemble is used by thousands of projects for rapid prototyping, creating themes, scaffolds, boilerplates, e-books, UI components, API documentation, blogs, building websit")
* [handlebars-helpers](https://www.npmjs.com/package/handlebars-helpers): More than 130 Handlebars helpers in ~20 categories. Helpers can be used with Assemble, Generate… [more](https://github.com/helpers/handlebars-helpers) | [homepage](https://github.com/helpers/handlebars-helpers "More than 130 Handlebars helpers in ~20 categories. Helpers can be used with Assemble, Generate, Verb, Ghost, gulp-handlebars, grunt-handlebars, consolidate, or any node.js/Handlebars project.")
* [template-helpers](https://www.npmjs.com/package/template-helpers): Generic JavaScript helpers that can be used with any template engine. Handlebars, Lo-Dash, Underscore, or… [more](https://github.com/jonschlinkert/template-helpers) | [homepage](https://github.com/jonschlinkert/template-helpers "Generic JavaScript helpers that can be used with any template engine. Handlebars, Lo-Dash, Underscore, or any engine that supports helper functions.")
* [templates](https://www.npmjs.com/package/templates): System for creating and managing template collections, and rendering templates with any node.js template engine… [more](https://github.com/jonschlinkert/templates) | [homepage](https://github.com/jonschlinkert/templates "System for creating and managing template collections, and rendering templates with any node.js template engine. Can be used as the basis for creating a static site generator or blog framework.")### Contributors
| **Commits** | **Contributor** |
| --- | --- |
| 32 | [jonschlinkert](https://github.com/jonschlinkert) |
| 18 | [doowb](https://github.com/doowb) |### Author
**Jon Schlinkert**
* [GitHub Profile](https://github.com/jonschlinkert)
* [Twitter Profile](https://twitter.com/jonschlinkert)
* [LinkedIn Profile](https://linkedin.com/in/jonschlinkert)### License
Copyright © 2018, [Jon Schlinkert](https://github.com/jonschlinkert).
Released under the [MIT License](LICENSE).***
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.8.0, on November 11, 2018._