Permalink
Browse files

v2.2.0. Improvement.

- v2.2.0 January 19, 2012
	- Added support for precompiling
		- Closes [pull request
#3](#3) thanks
to [Gilles Bouthenot](https://github.com/gbouthenot)
  • Loading branch information...
1 parent e9b751d commit fbd8cb48f3a427d1eb41c0365911f5cd5c734551 @balupton balupton committed Jan 19, 2013
Showing with 90 additions and 51 deletions.
  1. +4 −0 History.md
  2. +2 −2 Makefile
  3. +58 −42 README.md
  4. +8 −7 package.json
  5. +14 −0 test/out-expected/handlebars.inlinejs
  6. +4 −0 test/src/documents/handlebars.inlinejs.hbs
View
@@ -1,5 +1,9 @@
## History
+- v2.2.0 January 19, 2012
+ - Added support for precompiling
+ - Closes [pull request #3](https://github.com/docpad/docpad-plugin-handlebars/pull/3) thanks to [Gilles Bouthenot](https://github.com/gbouthenot)
+
- v2.1.0 November 17, 2012
- Added support for partials
View
@@ -5,8 +5,8 @@
# -----------------
# Variables
-BIN=node_modules/.bin/
-COFFEE=$(BIN)coffee
+BIN=node_modules/.bin
+COFFEE=$(BIN)/coffee
OUT=out
SRC=src
View
100 README.md
@@ -11,54 +11,70 @@ npm install --save docpad-plugin-handlebars
```
-## Usage
+## Configuration
+
+### Getting helpers and partials to work
+
+For the plugin to support helpers and partials, you'll have to add something like the following to your [docpad configuration file](http://docpad.org/docs/config) manually:
+
+``` coffee
+# ...
+plugins:
+ handlebars:
+ helpers:
+ # Expose docpads 'getBlock' function to handlebars
+ getBlock: (type, additional...) ->
+ additional.pop() # remove the hash object
+ @getBlock(type).add(additional).toHTML()
+ partials:
+ title: '<h1>{{document.title}}</h1>'
+ goUp: '<a href="#">Scroll up</a>'
+# ...
+```
-The plugin also supports helpers and partials. They can be defined in the docpad settings.
-Here is a small example:
+## Usage as precompiler
- {
- plugins:
- handlebars:
- helpers:
- # Expose docpads 'getBlock' function to handlebars
- getBlock: (type, additional...) ->
- additional.pop() # remove the hash object
- @getBlock(type).add(additional).toHTML()
- partials:
- title: '<h1>{{document.title}}</h1>'
- goUp: '<a href="#">Scroll up</a>'
- }
+If the document extension is `.inlinejs|js.handlebars|hbs|hb`, the plugin will produce a precompiled template. In this case, you can customise the precompiled template via the following:
+``` coffee
+# ...
+plugins:
+ handlebars:
+ precompileOpts:
+ wrapper: "default"
+# ...
+```
-## Usage as precompiler
+Available values for the wrapper option are:
+
+- `"default"`: Produces a handlebars wrapper like:
+ ``` javascript
+ (function() {
+ var template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {};
+ templates['theSlugOfTheFile'] = template(function (Handlebars,depth0,helpers,partials,data) {
+ ...
+ })
+ })();
+ ```
+
+- `"amd"`: Produces a AMD handlebars wrapper like:
+ ``` javascript
+ define(['handlebars'], function(Handlebars) {
+ var template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {};
+ templates['theSlugOfTheFile'] = template(function (Handlebars,depth0,helpers,partials,data) {
+ ...
+ });
+ });
+ ```
+
+- `"none"`: Produces a basic wrapper like:
+ ``` javascript
+ function (Handlebars,depth0,helpers,partials,data) {
+ ...
+ }
+ ```
-If the document extension is `.inlinejs|js.handlebars|hbs|hb`, the plugin will produce a precompiled template.
-In that, case, you can customise the ouput in the docpad settings:
-
- {
- precompileOpts:
- wrapper: "default"
- # wrapper should be "default", "amd" or "none" (please note that "none" is probably not what you want
- # "none": This option produces non-uglifable, so use "*.inlinejs.handlebars" extension
- # function (Handlebars,depth0,helpers,partials,data) {
- # ...
- # }
- # "default" :
- # (function() {
- # var template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {};
- # templates['test'] = template(function (Handlebars,depth0,helpers,partials,data) {
- # ...
- # })
- # })();
- # "amd":
- # define(['handlebars'], function(Handlebars) {
- # var template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {};
- # templates['test'] = template(function (Handlebars,depth0,helpers,partials,data) {
- # ...
- # });
- # });
- }
## History
View
@@ -1,6 +1,6 @@
{
"name": "docpad-plugin-handlebars",
- "version": "2.1.0",
+ "version": "2.2.0",
"description": "Adds support for the Handlebars templating engine to DocPad.",
"homepage": "http://docpad.org/plugin/handlebars",
"keywords": [
@@ -20,23 +20,24 @@
"contributors": [
"Mike Moulton <mike@meltmedia.com> (http://meltmedia.com)",
"Benjamin Lupton <b@lupton.cc> (http://balupton.com)",
- "Tobias Birmili <birmili@mecodia.de> (http://mecodia.de)"
+ "Tobias Birmili <birmili@mecodia.de> (http://mecodia.de)",
+ "Gilles Bouthenot (https://github.com/gbouthenot)"
],
"bugs": {
- "url": "https://github.com/bevry/docpad-extras/issues"
+ "url": "http://docpad.org/plugin/handlebars/issues"
},
"repository" : {
"type": "git",
- "url": "http://github.com/bevry/docpad-extras.git"
+ "url": "https://github.com/docpad/docpad-plugin-handlebars.git"
},
"dependencies": {
- "handlebars": "1.0.x"
+ "handlebars": "~1.0.7"
},
"devDependencies": {
- "coffee-script": "1.4.x"
+ "coffee-script": "~1.4.0"
},
"engines" : {
- "node": ">=0.4.0",
+ "node": ">=0.4",
"docpad": "6.x"
},
"main": "./out/handlebars.plugin.js",
@@ -0,0 +1,14 @@
+(function() {
+ var template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {};
+templates['handlebars'] = template(function (Handlebars,depth0,helpers,partials,data) {
+ helpers = helpers || Handlebars.helpers;
+ var buffer = "", stack1, functionType="function", escapeExpression=this.escapeExpression;
+
+
+ buffer += "<h1>";
+ stack1 = depth0.document;
+ stack1 = stack1 == null || stack1 === false ? stack1 : stack1.example;
+ stack1 = typeof stack1 === functionType ? stack1() : stack1;
+ buffer += escapeExpression(stack1) + "</h1>";
+ return buffer;});
+})();
@@ -0,0 +1,4 @@
+---
+example: 'Handlebars Example'
+---
+<h1>{{document.example}}</h1>

0 comments on commit fbd8cb4

Please sign in to comment.