You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
2.2 KiB

  1. # Handlebars Plugin for DocPad
  2. Adds support for the [Handlebars](http://handlebarsjs.com/) templating engine to [DocPad](https://docpad.org)
  3. Convention: `.inlinejs|js|anything.handlebars|hbs|hb`
  4. ## Install
  5. ```
  6. npm install --save docpad-plugin-handlebars
  7. ```
  8. ## Configuration
  9. ### Getting helpers and partials to work
  10. 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:
  11. ``` coffee
  12. # ...
  13. plugins:
  14. handlebars:
  15. helpers:
  16. # Expose docpads 'getBlock' function to handlebars
  17. getBlock: (type, additional...) ->
  18. additional.pop() # remove the hash object
  19. @getBlock(type).add(additional).toHTML()
  20. partials:
  21. title: '<h1>{{document.title}}</h1>'
  22. goUp: '<a href="#">Scroll up</a>'
  23. # ...
  24. ```
  25. ## Usage as precompiler
  26. 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:
  27. ``` coffee
  28. # ...
  29. plugins:
  30. handlebars:
  31. precompileOpts:
  32. wrapper: "default"
  33. # ...
  34. ```
  35. Available values for the wrapper option are:
  36. - `"default"`: Produces a handlebars wrapper like:
  37. ``` javascript
  38. (function() {
  39. var template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {};
  40. templates['theSlugOfTheFile'] = template(function (Handlebars,depth0,helpers,partials,data) {
  41. ...
  42. })
  43. })();
  44. ```
  45. - `"amd"`: Produces a AMD handlebars wrapper like:
  46. ``` javascript
  47. define(['handlebars'], function(Handlebars) {
  48. var template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {};
  49. templates['theSlugOfTheFile'] = template(function (Handlebars,depth0,helpers,partials,data) {
  50. ...
  51. });
  52. });
  53. ```
  54. - `"none"`: Produces a basic wrapper like:
  55. ``` javascript
  56. function (Handlebars,depth0,helpers,partials,data) {
  57. ...
  58. }
  59. ```
  60. ## History
  61. You can discover the history inside the `History.md` file
  62. ## License
  63. Licensed under the incredibly [permissive](http://en.wikipedia.org/wiki/Permissive_free_software_licence) [MIT License](http://creativecommons.org/licenses/MIT/)
  64. <br/>Copyright &copy; 2012 [Mike Moulton](http://meltmedia.com)