helper-example
Version:
Opinionated template helper that inserts a code example from a filepath.
99 lines (65 loc) • 3.47 kB
Markdown
# helper-example [](https://www.npmjs.com/package/helper-example) [](https://travis-ci.org/jonschlinkert/helper-example)
> Opinionated template helper that inserts a code example from a filepath.
## Install
Install with [npm](https://www.npmjs.com/):
```sh
$ npm install helper-example --save
```
## Usage
Register the helper with `app` ([verb](https://github.com/verbose/verb), [assemble](https://github.com/assemble/assemble) or [templates](https://github.com/jonschlinkert/templates));
```js
app.helper('example', require('helper-example'));
```
To use the helper, pass the filepath of the code example to inject and the name of the module as the second argument:
```html
<%= example("examples/foo.js", "foo-bar-baz") %>
```
If the contents of `foo.js` is something like this:
```js
var app = require('./');
function foo(a, b, c) {
//=> do stuff with a, b, and c
return app(a, b, c);
}
foo('one', 'two', 'three');
```
The `require('./')` statement is converted to `require('helper-example')`:
```js
var app = require('helper-example');
function foo(a, b, c) {
//=> do stuff with a, b, and c
return app(a, b, c);
}
foo('one', 'two', 'three');
```
## Related projects
* [assemble](https://www.npmjs.com/package/assemble): Assemble is a powerful, extendable and easy to use static site generator for node.js. Used… [more](https://www.npmjs.com/package/assemble) | [homepage](https://github.com/assemble/assemble)
* [generate](https://www.npmjs.com/package/generate): Fast, composable, highly extendable project generator with a user-friendly and expressive API. | [homepage](https://github.com/generate/generate)
* [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://www.npmjs.com/package/templates) | [homepage](https://github.com/jonschlinkert/templates)
* [update](https://www.npmjs.com/package/update): Easily keep anything in your project up-to-date by installing the updaters you want to use… [more](https://www.npmjs.com/package/update) | [homepage](https://github.com/update/update)
* [verb](https://www.npmjs.com/package/verb): Documentation generator for GitHub projects. Verb is extremely powerful, easy to use, and is used… [more](https://www.npmjs.com/package/verb) | [homepage](https://github.com/verbose/verb)
## Contributing
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/helper-example/issues/new).
## Building docs
Generate readme and API documentation with [verb](https://github.com/verbose/verb):
```sh
$ npm install verb && npm run docs
```
Or, if [verb](https://github.com/verbose/verb) is installed globally:
```sh
$ verb
```
## Running tests
Install dev dependencies:
```sh
$ npm install -d && npm test
```
## Author
**Jon Schlinkert**
* [github/jonschlinkert](https://github.com/jonschlinkert)
* [twitter/jonschlinkert](http://twitter.com/jonschlinkert)
## License
Copyright © 2016 [Jon Schlinkert](https://github.com/jonschlinkert)
Released under the [MIT license](https://github.com/jonschlinkert/helper-example/blob/master/LICENSE).
***
_This file was generated by [verb](https://github.com/verbose/verb), v0.9.0, on February 26, 2016._