kaanon/gulp-compile-handlebars — pull request #6 by MadLittleMods (2014-10-07 15:44:15+00:00)
Title: Add `@/at` format to import helpers from template

This allows you to reference helpers directly inside the handlebars template. The `@` format syntax is the same as the [require-hbs plugin from Guy Bedford](https://github.com/guybedford/hbs#helpers).

## Format:
`{{@helpers/myhelper}}`
`{{#@helpers/myblockhelper}}...{{/helpers/myblockhelper}}`

Added path map option(`helpersAtPathMap: {}`) to map a module name (such as "helpers") to a complete path making it easier to reference helpers.

Also added documentation on this new `@` format.

---

Example taken from added documenation to readme.md:

## Example: inline `@/at` helpers

#### `src/hello.handlebars`

```handlebars

Hello {{firstName}}

HELLO! {{@helpers/capitals.helper firstName}}

{{#@helpers/noop.helper}}

A block helper that invokes the block as though no helper existed.

{{/helpers/noop}}
{{> footer}}
```

#### `src/js/hbs-helpers/capitals.helper.js`

```js
module.exports = function(str) {
return str.toUpperCase();
}
```

#### `src/js/hbs-helpers/noop.helper.js`

```js
module.exports = function(options) {
return options.fn(this);
}
```

#### `gulpfile.js`

```js
var gulp = require('gulp');
var handlebars = require('gulp-compile-handlebars');
var rename = require('gulp-rename');

gulp.task('default', function () {
var templateData = {
firstName: 'Kaanon'
},
options = {
ignorePartials: true,
partials : {
footer : '

the end

'
},
helpersAtPathMap: {
'helpers': './src/js/hbs-helpers/'
},
}

return gulp.src('src/hello.handlebars')
.pipe(handlebars(templateData, options))
.pipe(rename('hello.html'))
.pipe(gulp.dest('dist'));
});
```

#### `dist/hello.html`

```html

Hello Kaanon

HELLO! KAANON

A block helper that invokes the block as though no helper existed.

the end

```

---

Currently, in the current master branch of this project, the only way to batch helpers is to do something like this:
```
helpers : (function() {
var helpers = {};
// Get a list of all the helpers in our holder
var helperFiles = glob.sync("./src/js/hbs-helpers/*.js", {});
helperFiles.forEach(function(filePath, index, array) {
var pathParts = parsePath(filePath);
try {
helpers[pathParts.name] = require(filePath);
} catch(e) {

}
});

//console.log(helpers);
return helpers;
})()
```