dpolivy/hbs-utils — pull request #1 by jas (2014-04-23 20:24:02+00:00)
Title: Add "regex" and "name" options

This pull request makes the regular expression used to check `isValidTemplate` configurable, and adds an option to rename the partial before it's registered.

My partials live amongst other views and are prefixed with an underscore. Unfortunately I can't restructure my template files, so I need a way to limit the registrations to those files with an underscore at the beginning, and have the underscore removed from the name that is registered.

#### New Options

**`regex`**: (default: `/\.(html|hbs)$/`) A regular expression that each partial's filename is tested against to determine whether it is a valid partial.

**`name`**: A function in the form `function(template) {}` that will be called for each partial. The name of the partial is passed as the sole parameter. This function gives you the opportunity to rename the partial before it is registered — for example, to remove a leading `_` from the filename — by returning the new name.

#### Example

```javascript
var path = require('path');
var hbsutils = require('hbs-utils');

hbsutils.registerPartials('./views', {
// match html and hbs files beginning with an underscore
regex: /_.+\.(html|hbs)$/,
// remove the underscore from the partial name
name: function(template) {
var basename = path.basename(template);
return template.replace(basename, basename.replace('_', ''));
}
});
```