Skip to content

Commit

Permalink
v0.11.0
Browse files Browse the repository at this point in the history
  • Loading branch information
vladikoff committed Oct 16, 2015
1 parent 30602cc commit ee5d6bb
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 41 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
v0.11.0:
date: 2015-10-16
changes:
- Handlebars ~4
v0.10.2:
date: 2015-04-21
changes:
Expand Down
31 changes: 16 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# grunt-contrib-handlebars v0.10.2 [![Build Status: Linux](https://travis-ci.org/gruntjs/grunt-contrib-handlebars.svg?branch=master)](https://travis-ci.org/gruntjs/grunt-contrib-handlebars) [![Build Status: Windows](https://ci.appveyor.com/api/projects/status/byxsu7xtyjxuwe3g/branch/master?svg=true)](https://ci.appveyor.com/project/gruntjs/grunt-contrib-handlebars/branch/master)
# grunt-contrib-handlebars v0.11.0 [![Build Status: Linux](https://travis-ci.org/gruntjs/grunt-contrib-handlebars.svg?branch=master)](https://travis-ci.org/gruntjs/grunt-contrib-handlebars) [![Build Status: Windows](https://ci.appveyor.com/api/projects/status/byxsu7xtyjxuwe3g/branch/master?svg=true)](https://ci.appveyor.com/project/gruntjs/grunt-contrib-handlebars/branch/master)

> Precompile Handlebars templates to JST file.
Expand Down Expand Up @@ -42,7 +42,7 @@ Default: `'JST'`
The namespace in which the precompiled templates will be assigned. *Use dot notation (e.g. App.Templates) for nested namespaces or false for no namespace wrapping.* When false with `amd` or `commonjs` option set `true`, templates will be returned directly from the AMD/CommonJS wrapper.

Example:
```js
```javascript
options: {
namespace: 'MyApp.Templates'
}
Expand All @@ -51,7 +51,7 @@ options: {
You can generate nested namespaces based on the file system paths of your templates by providing a function. The function will be called with one argument (the template filepath). *The function must return a dot notation based on the filepath*.

Example:
```js
```javascript
options: {
namespace: function(filename) {
var names = filename.replace(/modules\/(.*)(\/\w+\.hbs)/, '$1');
Expand Down Expand Up @@ -95,7 +95,7 @@ If `Array` then those strings will be used in the module definition. `'handleba

If `Function` then it will be called per each module and returned string will be used in the module defintion `"define(['" + options.amd(filename, ast, compiled) + "']"`

```js
```javascript
define(['handlebars'], function(Handlebars) {
//...//
return this['[template namespace]'];
Expand All @@ -108,7 +108,7 @@ Default: `false`

Wraps the output file in a CommonJS module function, exporting the compiled templates. It will also add templates to the template namespace, unless `namespace` is explicitly set to `false`.

```js
```javascript
module.exports = function(Handlebars) {
//...//
Handlebars.template(…);
Expand All @@ -118,7 +118,7 @@ module.exports = function(Handlebars) {

When requiring the module in a CommonJS environment, pass in your `Handlebars` object.

```js
```javascript
var Handlebars = require('handlebars');
var templates = require('./templates')(Handlebars);
```
Expand All @@ -128,7 +128,7 @@ Type: `function`

This option accepts a function which takes two arguments (the template file content, and the filepath) and returns a string which will be used as the source for the precompiled template object. The example below removes leading and trailing spaces to shorten templates.

```js
```javascript
options: {
processContent: function(content, filepath) {
content = content.replace(/^[\x20\t]+/mg, '').replace(/[\x20\t]+$/mg, '');
Expand All @@ -143,7 +143,7 @@ Type: `function`

This option accepts a function which takes one argument (the parsed Abstract Syntax Tree) and returns a modified version which will be used as the source for the precompiled template object. The example below removes any partial and replaces it with the text `foo`.

```js
```javascript
options: {
processAST: function(ast) {
ast.statements.forEach(function(statement, i) {
Expand All @@ -161,7 +161,7 @@ Type: `function`

This option accepts a function which takes one argument (the template filepath) and returns a string which will be used as the key for the precompiled template object. The example below stores all templates on the default JST namespace in capital letters.

```js
```javascript
options: {
processName: function(filePath) {
return filePath.toUpperCase();
Expand All @@ -174,7 +174,7 @@ Type: `function`

This option accepts a function which takes one argument (the partial filepath) and returns a string which will be used as the key for the precompiled partial object when it is registered in Handlebars.partials. The example below stores all partials using only the actual filename instead of the full path.

```js
```javascript
options: {
processPartialName: function(filePath) { // input: templates/_header.hbs
var pieces = filePath.split("/");
Expand All @@ -191,7 +191,7 @@ Default: `/^_/`

This option accepts a regex that defines the prefix character that is used to identify Handlebars partial files.

``` javascript
```javascript
// assumes partial files would be prefixed with "par_" ie: "par_header.hbs"
options: {
partialRegex: /^par_/
Expand All @@ -204,7 +204,7 @@ Default: `/./`

This option accepts a regex that defines the path to a directory of Handlebars partials files. The example below shows how to mark every file in a specific directory as a partial.

``` javascript
```javascript
options: {
partialRegex: /.*/,
partialsPathRegex: /\/partials\//
Expand All @@ -217,7 +217,7 @@ Default: `{}`

This option allows you to specify a hash of options which will be passed directly to the Handlebars compiler.

``` javascript
```javascript
options: {
compilerOptions: {
knownHelpers: {
Expand All @@ -231,7 +231,7 @@ options: {

### Usage Examples

```js
```javascript
handlebars: {
compile: {
options: {
Expand All @@ -248,6 +248,7 @@ handlebars: {

## Release History

* 2015-10-16   v0.11.0   Handlebars ~4
* 2015-04-21   v0.10.2   Added options.amd as a function
* 2015-03-23   v0.10.1   Documentation fix
* 2015-03-23   v0.10.0   Update to Handlebars 3.0.0
Expand Down Expand Up @@ -286,4 +287,4 @@ handlebars: {

Task submitted by [Tim Branyen](http://tbranyen.com)

*This file was generated on Tue Apr 21 2015 09:47:19.*
*This file was generated on Fri Oct 16 2015 11:17:16.*
2 changes: 1 addition & 1 deletion docs/handlebars-examples.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Usage Examples

```js
```javascript
handlebars: {
compile: {
options: {
Expand Down
44 changes: 22 additions & 22 deletions docs/handlebars-options.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
# Options

## separator
Type: `String`
Type: `String`
Default: `linefeed + linefeed`

Concatenated files will be joined on this string.

## namespace
Type: `String` or `false` or `function`
Type: `String` or `false` or `function`
Default: `'JST'`

The namespace in which the precompiled templates will be assigned. *Use dot notation (e.g. App.Templates) for nested namespaces or false for no namespace wrapping.* When false with `amd` or `commonjs` option set `true`, templates will be returned directly from the AMD/CommonJS wrapper.

Example:
```js
```javascript
options: {
namespace: 'MyApp.Templates'
}
Expand All @@ -22,7 +22,7 @@ options: {
You can generate nested namespaces based on the file system paths of your templates by providing a function. The function will be called with one argument (the template filepath). *The function must return a dot notation based on the filepath*.

Example:
```js
```javascript
options: {
namespace: function(filename) {
var names = filename.replace(/modules\/(.*)(\/\w+\.hbs)/, '$1');
Expand All @@ -35,27 +35,27 @@ options: {
```

## partialsUseNamespace
Type: `Boolean`
Type: `Boolean`
Default: `false`

When set to `true`, partials will be registered in the `namespace` in addition to templates.

## wrapped
Type: `Boolean`
Type: `Boolean`
Default: `true`

Determine if preprocessed template functions will be wrapped in Handlebars.template function.

## node
Type: `Boolean`
Type: `Boolean`
Default: `false`

Enable the compiled file to be required on node.js by preppending and appending proper declarations. You can use the file safely on the front-end.

For this option to work you need to define the `namespace` option.

## amd
Type: `Boolean` or `String` or `Array` or `Function`
Type: `Boolean` or `String` or `Array` or `Function`
Default: `false`

Wraps the output file with an AMD define function and returns the compiled template namespace unless namespace has been explicitly set to false in which case the template function will be returned directly.
Expand All @@ -66,20 +66,20 @@ If `Array` then those strings will be used in the module definition. `'handleba

If `Function` then it will be called per each module and returned string will be used in the module defintion `"define(['" + options.amd(filename, ast, compiled) + "']"`

```js
```javascript
define(['handlebars'], function(Handlebars) {
//...//
return this['[template namespace]'];
});
```

## commonjs
Type: `Boolean`
Type: `Boolean`
Default: `false`

Wraps the output file in a CommonJS module function, exporting the compiled templates. It will also add templates to the template namespace, unless `namespace` is explicitly set to `false`.

```js
```javascript
module.exports = function(Handlebars) {
//...//
Handlebars.template(…);
Expand All @@ -89,7 +89,7 @@ module.exports = function(Handlebars) {

When requiring the module in a CommonJS environment, pass in your `Handlebars` object.

```js
```javascript
var Handlebars = require('handlebars');
var templates = require('./templates')(Handlebars);
```
Expand All @@ -99,7 +99,7 @@ Type: `function`

This option accepts a function which takes two arguments (the template file content, and the filepath) and returns a string which will be used as the source for the precompiled template object. The example below removes leading and trailing spaces to shorten templates.

```js
```javascript
options: {
processContent: function(content, filepath) {
content = content.replace(/^[\x20\t]+/mg, '').replace(/[\x20\t]+$/mg, '');
Expand All @@ -114,7 +114,7 @@ Type: `function`

This option accepts a function which takes one argument (the parsed Abstract Syntax Tree) and returns a modified version which will be used as the source for the precompiled template object. The example below removes any partial and replaces it with the text `foo`.

```js
```javascript
options: {
processAST: function(ast) {
ast.statements.forEach(function(statement, i) {
Expand All @@ -132,7 +132,7 @@ Type: `function`

This option accepts a function which takes one argument (the template filepath) and returns a string which will be used as the key for the precompiled template object. The example below stores all templates on the default JST namespace in capital letters.

```js
```javascript
options: {
processName: function(filePath) {
return filePath.toUpperCase();
Expand All @@ -145,7 +145,7 @@ Type: `function`

This option accepts a function which takes one argument (the partial filepath) and returns a string which will be used as the key for the precompiled partial object when it is registered in Handlebars.partials. The example below stores all partials using only the actual filename instead of the full path.

```js
```javascript
options: {
processPartialName: function(filePath) { // input: templates/_header.hbs
var pieces = filePath.split("/");
Expand All @@ -157,38 +157,38 @@ options: {
Note: If processPartialName is not provided as an option the default assumes that partials will be stored by stripping trailing underscore characters and filename extensions. For example, the path *templates/_header.hbs* will become *header* and can be referenced in other templates as *{{> header}}*.

## partialRegex
Type: `Regexp`
Type: `Regexp`
Default: `/^_/`

This option accepts a regex that defines the prefix character that is used to identify Handlebars partial files.

```js
```javascript
// assumes partial files would be prefixed with "par_" ie: "par_header.hbs"
options: {
partialRegex: /^par_/
}
```

## partialsPathRegex
Type: `Regexp`
Type: `Regexp`
Default: `/./`

This option accepts a regex that defines the path to a directory of Handlebars partials files. The example below shows how to mark every file in a specific directory as a partial.

```js
```javascript
options: {
partialRegex: /.*/,
partialsPathRegex: /\/partials\//
}
```

## compilerOptions
Type `Object`
Type `Object`
Default: `{}`

This option allows you to specify a hash of options which will be passed directly to the Handlebars compiler.

```js
```javascript
options: {
compilerOptions: {
knownHelpers: {
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "grunt-contrib-handlebars",
"description": "Precompile Handlebars templates to JST file",
"version": "0.10.2",
"description": "Precompile Handlebars templates to JST file.",
"version": "0.11.0",
"author": {
"name": "Grunt Team",
"url": "http://gruntjs.com/"
Expand All @@ -15,7 +15,7 @@
"test": "grunt test"
},
"dependencies": {
"handlebars": "^4.0.0",
"handlebars": "~4.0.0",
"chalk": "^1.0.0",
"nsdeclare": "0.1.0"
},
Expand Down

0 comments on commit ee5d6bb

Please sign in to comment.