{ "name": "handlebars", "barename": "handlebars", "version": "2.0.0", "description": "Handlebars provides the power necessary to let you build semantic templates effectively with no frustration", "homepage": "http://www.handlebarsjs.com/", "keywords": [ "handlebars", "mustache", "template", "html" ], "repository": { "type": "git", "url": "git+https://github.com/wycats/handlebars.js.git" }, "author": { "name": "Yehuda Katz" }, "license": "MIT", "readmeFilename": "README.markdown", "engines": { "node": ">=0.4.7" }, "dependencies": { "optimist": "~0.3", "uglify-js": "~2.3" }, "optionalDependencies": { "uglify-js": "~2.3" }, "devDependencies": { "async": "~0.2.9", "aws-sdk": "~1.5.0", "benchmark": "~1.0", "dustjs-linkedin": "~2.0.2", "eco": "~1.1.0-rc-3", "es6-module-packager": "1.x", "grunt": "~0.4.1", "grunt-cli": "~0.1.10", "grunt-contrib-clean": "~0.4.1", "grunt-contrib-concat": "~0.3.0", "grunt-contrib-connect": "~0.5.0", "grunt-contrib-copy": "~0.4.1", "grunt-contrib-jshint": "0.x", "grunt-contrib-requirejs": "~0.4.1", "grunt-contrib-uglify": "~0.2.2", "grunt-contrib-watch": "~0.5.3", "grunt-saucelabs": "8.x", "istanbul": "^0.3.0", "jison": "~0.3.0", "keen.io": "0.0.3", "mocha": "~1.20.0", "mustache": "~0.7.2", "semver": "~2.1.0", "underscore": "~1.5.1" }, "main": "lib/index.js", "bin": { "handlebars": "bin/handlebars" }, "scripts": { "test": "grunt" }, "readme": "[![Travis Build Status](https://img.shields.io/travis/wycats/handlebars.js/master.svg)](https://travis-ci.org/wycats/handlebars.js)\n[![Selenium Test Status](https://saucelabs.com/buildstatus/handlebars)](https://saucelabs.com/u/handlebars)\n\nHandlebars.js\n=============\n\nHandlebars.js is an extension to the [Mustache templating\nlanguage](http://mustache.github.com/) created by Chris Wanstrath.\nHandlebars.js and Mustache are both logicless templating languages that\nkeep the view and the code separated like we all know they should be.\n\nCheckout the official Handlebars docs site at\n[http://www.handlebarsjs.com](http://www.handlebarsjs.com).\n\nInstalling\n----------\nInstalling Handlebars is easy. Simply download the package [from the official site](http://handlebarsjs.com/) or the [bower repository][bower-repo] and add it to your web pages (you should usually use the most recent version).\n\nAlternatively, if you prefer having the latest version of handlebars from\nthe 'master' branch, passing builds of the 'master' branch are automatically\npublished to S3. You may download the latest passing master build by grabbing\na `handlebars-latest.js` file from the [builds page][builds-page]. When the\nbuild is published, it is also available as a `handlebars-gitSHA.js` file on\nthe builds page if you need a version to refer to others.\n`handlebars-runtime.js` builds are also available.\n\n**Note**: The S3 builds page is provided as a convenience for the community,\nbut you should not use it for hosting Handlebars in production.\n\nUsage\n-----\nIn general, the syntax of Handlebars.js templates is a superset\nof Mustache templates. For basic syntax, check out the [Mustache\nmanpage](http://mustache.github.com/mustache.5.html).\n\nOnce you have a template, use the `Handlebars.compile` method to compile\nthe template into a function. The generated function takes a context\nargument, which will be used to render the template.\n\n```js\nvar source = \"

Hello, my name is {{name}}. I am from {{hometown}}. I have \" +\n \"{{kids.length}} kids:

\" +\n \"\";\nvar template = Handlebars.compile(source);\n\nvar data = { \"name\": \"Alan\", \"hometown\": \"Somewhere, TX\",\n \"kids\": [{\"name\": \"Jimmy\", \"age\": \"12\"}, {\"name\": \"Sally\", \"age\": \"4\"}]};\nvar result = template(data);\n\n// Would render:\n//

Hello, my name is Alan. I am from Somewhere, TX. I have 2 kids:

\n// \n```\n\n\nRegistering Helpers\n-------------------\n\nYou can register helpers that Handlebars will use when evaluating your\ntemplate. Here's an example, which assumes that your objects have a URL\nembedded in them, as well as the text for a link:\n\n```js\nHandlebars.registerHelper('link_to', function() {\n return new Handlebars.SafeString(\"\" + Handlebars.Utils.escapeExpression(this.body) + \"\");\n});\n\nvar context = { posts: [{url: \"/hello-world\", body: \"Hello World!\"}] };\nvar source = \"\"\n\nvar template = Handlebars.compile(source);\ntemplate(context);\n\n// Would render:\n//\n// \n```\n\nHelpers take precedence over fields defined on the context. To access a field\nthat is masked by a helper, a path reference may be used. In the example above\na field named `link_to` on the `context` object would be referenced using:\n\n```\n{{./link_to}}\n```\n\nEscaping\n--------\n\nBy default, the `{{expression}}` syntax will escape its contents. This\nhelps to protect you against accidental XSS problems caused by malicious\ndata passed from the server as JSON.\n\nTo explicitly *not* escape the contents, use the triple-mustache\n(`{{{}}}`). You have seen this used in the above example.\n\n\nDifferences Between Handlebars.js and Mustache\n----------------------------------------------\nHandlebars.js adds a couple of additional features to make writing\ntemplates easier and also changes a tiny detail of how partials work.\n\n### Paths\n\nHandlebars.js supports an extended expression syntax that we call paths.\nPaths are made up of typical expressions and . characters. Expressions\nallow you to not only display data from the current context, but to\ndisplay data from contexts that are descendants and ancestors of the\ncurrent context.\n\nTo display data from descendant contexts, use the `.` character. So, for\nexample, if your data were structured like:\n\n```js\nvar data = {\"person\": { \"name\": \"Alan\" }, \"company\": {\"name\": \"Rad, Inc.\" } };\n```\n\nYou could display the person's name from the top-level context with the\nfollowing expression:\n\n```\n{{person.name}}\n```\n\nYou can backtrack using `../`. For example, if you've already traversed\ninto the person object you could still display the company's name with\nan expression like `{{../company.name}}`, so:\n\n```\n{{#with person}}{{name}} - {{../company.name}}{{/person}}\n```\n\nwould render:\n\n```\nAlan - Rad, Inc.\n```\n\n### Strings\n\nWhen calling a helper, you can pass paths or Strings as parameters. For\ninstance:\n\n```js\nHandlebars.registerHelper('link_to', function(title, options) {\n return \"\" + title + \"!\"\n});\n\nvar context = { posts: [{url: \"/hello-world\", body: \"Hello World!\"}] };\nvar source = ''\n\nvar template = Handlebars.compile(source);\ntemplate(context);\n\n// Would render:\n//\n// \n```\n\nWhen you pass a String as a parameter to a helper, the literal String\ngets passed to the helper function.\n\n\n### Block Helpers\n\nHandlebars.js also adds the ability to define block helpers. Block\nhelpers are functions that can be called from anywhere in the template.\nHere's an example:\n\n```js\nvar source = \"\";\nHandlebars.registerHelper('link', function(options) {\n return '' + options.fn(this) + '';\n});\nvar template = Handlebars.compile(source);\n\nvar data = { \"people\": [\n { \"name\": \"Alan\", \"id\": 1 },\n { \"name\": \"Yehuda\", \"id\": 2 }\n ]};\ntemplate(data);\n\n// Should render:\n// \n```\n\nWhenever the block helper is called it is given one or more parameters,\nany arguments that are passed in the helper in the call and an `options`\nobject containing the `fn` function which executes the block's child.\nThe block's current context may be accessed through `this`.\n\nBlock helpers have the same syntax as mustache sections but should not be\nconfused with one another. Sections are akin to an implicit `each` or\n`with` statement depending on the input data and helpers are explicit\npieces of code that are free to implement whatever behavior they like.\nThe [mustache spec](http://mustache.github.io/mustache.5.html)\ndefines the exact behavior of sections. In the case of name conflicts,\nhelpers are given priority.\n\n### Partials\n\nYou can register additional templates as partials, which will be used by\nHandlebars when it encounters a partial (`{{> partialName}}`). Partials\ncan either be String templates or compiled template functions. Here's an\nexample:\n\n```js\nvar source = \"\";\n\nHandlebars.registerPartial('link', '{{name}}')\nvar template = Handlebars.compile(source);\n\nvar data = { \"people\": [\n { \"name\": \"Alan\", \"id\": 1 },\n { \"name\": \"Yehuda\", \"id\": 2 }\n ]};\n\ntemplate(data);\n\n// Should render:\n// \n```\n\n### Comments\n\nYou can add comments to your templates with the following syntax:\n\n```js\n{{! This is a comment }}\n```\n\nYou can also use real html comments if you want them to end up in the output.\n\n```html\n
\n {{! This comment will not end up in the output }}\n \n
\n```\n\n\n### Compatibility\n\nThere are a few Mustache behaviors that Handlebars does not implement.\n- Handlebars deviates from Mustache slightly in that it does not perform recursive lookup by default. The compile time `compat` flag must be set to enable this functionality. Users should note that there is a performance cost for enabling this flag. The exact cost varies by template, but it's recommended that performance sensitive operations should avoid this mode and instead opt for explicit path references.\n- The optional Mustache-style lambdas are not supported. Instead Handlebars provides it's own lambda resolution that follows the behaviors of helpers.\n- Alternative delimeters are not supported.\n\n\nPrecompiling Templates\n----------------------\n\nHandlebars allows templates to be precompiled and included as javascript\ncode rather than the handlebars template allowing for faster startup time.\n\n### Installation\nThe precompiler script may be installed via npm using the `npm install -g handlebars`\ncommand.\n\n### Usage\n\n
\nPrecompile handlebar templates.\nUsage: handlebars template...\n\nOptions:\n  -a, --amd            Create an AMD format function (allows loading with RequireJS)          [boolean]\n  -f, --output         Output File                                                            [string]\n  -k, --known          Known helpers                                                          [string]\n  -o, --knownOnly      Known helpers only                                                     [boolean]\n  -m, --min            Minimize output                                                        [boolean]\n  -s, --simple         Output template function only.                                         [boolean]\n  -r, --root           Template root. Base value that will be stripped from template names.   [string]\n  -c, --commonjs       Exports CommonJS style, path to Handlebars module                      [string]\n  -h, --handlebarPath  Path to handlebar.js (only valid for amd-style)                        [string]\n  -n, --namespace      Template namespace                                                     [string]\n  -p, --partial        Compiling a partial template                                           [boolean]\n  -d, --data           Include data when compiling                                            [boolean]\n  -e, --extension      Template extension.                                                    [string]\n  -b, --bom            Removes the BOM (Byte Order Mark) from the beginning of the templates. [boolean]\n
\n\nIf using the precompiler's normal mode, the resulting templates will be\nstored to the `Handlebars.templates` object using the relative template\nname sans the extension. These templates may be executed in the same\nmanner as templates.\n\nIf using the simple mode the precompiler will generate a single\njavascript method. To execute this method it must be passed to\nthe `Handlebars.template` method and the resulting object may be used as normal.\n\n### Optimizations\n\n- Rather than using the full _handlebars.js_ library, implementations that\n do not need to compile templates at runtime may include _handlebars.runtime.js_\n whose min+gzip size is approximately 1k.\n- If a helper is known to exist in the target environment they may be defined\n using the `--known name` argument may be used to optimize accesses to these\n helpers for size and speed.\n- When all helpers are known in advance the `--knownOnly` argument may be used\n to optimize all block helper references.\n- Implementations that do not use `@data` variables can improve performance of\n iteration centric templates by specifying `{data: false}` in the compiler options.\n\nSupported Environments\n----------------------\n\nHandlebars has been designed to work in any ECMAScript 3 environment. This includes\n\n- Node.js\n- Chrome\n- Firefox\n- Safari 5+\n- Opera 11+\n- IE 6+\n\nOlder versions and other runtimes are likely to work but have not been formally\ntested. The compiler requires `JSON.stringify` to be implemented natively or via a polyfill. If using the precompiler this is not necessary.\n\n[![Selenium Test Status](https://saucelabs.com/browser-matrix/handlebars.svg)](https://saucelabs.com/u/handlebars)\n\nPerformance\n-----------\n\nIn a rough performance test, precompiled Handlebars.js templates (in\nthe original version of Handlebars.js) rendered in about half the\ntime of Mustache templates. It would be a shame if it were any other\nway, since they were precompiled, but the difference in architecture\ndoes have some big performance advantages. Justin Marney, a.k.a.\n[gotascii](http://github.com/gotascii), confirmed that with an\n[independent test](http://sorescode.com/2010/09/12/benchmarks.html). The\nrewritten Handlebars (current version) is faster than the old version,\nwith many [performance tests](https://travis-ci.org/wycats/handlebars.js/builds/33392182#L538) being 5 to 7 times faster than the Mustache equivalent.\n\n\nUpgrading\n---------\n\nSee [release-notes.md](https://github.com/wycats/handlebars.js/blob/master/release-notes.md) for upgrade notes.\n\nKnown Issues\n------------\n\nSee [FAQ.md](https://github.com/wycats/handlebars.js/blob/master/FAQ.md) for known issues and common pitfalls.\n\n\nHandlebars in the Wild\n----------------------\n\n* [Assemble](http://assemble.io), by [@jonschlinkert](https://github.com/jonschlinkert)\n and [@doowb](https://github.com/doowb), is a static site generator that uses Handlebars.js\n as its template engine.\n* [CoSchedule](http://coschedule.com) An editorial calendar for WordPress that uses Handlebars.js\n* [Ember.js](http://www.emberjs.com) makes Handlebars.js the primary way to\n structure your views, also with automatic data binding support.\n* [Ghost](https://ghost.org/) Just a blogging platform.\n* [handlebars_assets](http://github.com/leshill/handlebars_assets): A Rails Asset Pipeline gem\n from Les Hill (@leshill).\n* [handlebars-helpers](https://github.com/assemble/handlebars-helpers) is an extensive library\n with 100+ handlebars helpers.\n* [hbs](http://github.com/donpark/hbs): An Express.js view engine adapter for Handlebars.js,\n from Don Park.\n* [koa-hbs](https://github.com/jwilm/koa-hbs): [koa](https://github.com/koajs/koa) generator based\n renderer for Handlebars.js.\n* [jblotus](http://github.com/jblotus) created [http://tryhandlebarsjs.com](http://tryhandlebarsjs.com)\n for anyone who would like to try out Handlebars.js in their browser.\n* [jQuery plugin](http://71104.github.io/jquery-handlebars/): allows you to use\n Handlebars.js with [jQuery](http://jquery.com/).\n* [Lumbar](http://walmartlabs.github.io/lumbar) provides easy module-based template management for\n handlebars projects.\n* [sammy.js](http://github.com/quirkey/sammy) by Aaron Quint, a.k.a. quirkey,\n supports Handlebars.js as one of its template plugins.\n* [SproutCore](http://www.sproutcore.com) uses Handlebars.js as its main\n templating engine, extending it with automatic data binding support.\n* [YUI](http://yuilibrary.com/yui/docs/handlebars/) implements a port of handlebars\n* [Swag](https://github.com/elving/swag) by [@elving](https://github.com/elving) is a growing collection of helpers for handlebars.js. Give your handlebars.js templates some swag son!\n* [DOMBars](https://github.com/blakeembrey/dombars) is a DOM-based templating engine built on the Handlebars parser and runtime\n\nExternal Resources\n------------------\n\n* [Gist about Synchronous and asynchronous loading of external handlebars templates](https://gist.github.com/2287070)\n\nHave a project using Handlebars? Send us a [pull request][pull-request]!\n\nLicense\n-------\nHandlebars.js is released under the MIT license.\n\n[bower-repo]: https://github.com/components/handlebars.js\n[builds-page]: http://builds.handlebarsjs.com.s3.amazonaws.com/bucket-listing.html?sort=lastmod&sortdir=desc\n[pull-request]: https://github.com/wycats/handlebars.js/pull/new/master\n", "bugs": { "url": "https://github.com/wycats/handlebars.js/issues" }, "_id": "handlebars@2.0.0", "_shasum": "6e9d7f8514a3467fa5e9f82cc158ecfc1d5ac76f", "_resolved": "https://registry.npmjs.org/handlebars/-/handlebars-2.0.0.tgz", "_from": "handlebars@>=2.0.0 <3.0.0" }