mirror of https://github.com/zulip/zulip.git
47 lines
13 KiB
JSON
47 lines
13 KiB
JSON
{
|
|
"name": "handlebars",
|
|
"description": "Extension of the Mustache logicless template language",
|
|
"version": "1.0.11",
|
|
"homepage": "http://www.handlebarsjs.com/",
|
|
"keywords": [
|
|
"handlebars mustache template html"
|
|
],
|
|
"repository": {
|
|
"type": "git",
|
|
"url": "git://github.com/wycats/handlebars.js.git"
|
|
},
|
|
"engines": {
|
|
"node": ">=0.4.7"
|
|
},
|
|
"dependencies": {
|
|
"optimist": "~0.3",
|
|
"uglify-js": "~1.2"
|
|
},
|
|
"devDependencies": {
|
|
"benchmark": "~1.0",
|
|
"dust": "~0.3",
|
|
"jison": "~0.3",
|
|
"mocha": "*",
|
|
"mustache": "~0.7.2"
|
|
},
|
|
"main": "lib/handlebars.js",
|
|
"bin": {
|
|
"handlebars": "bin/handlebars"
|
|
},
|
|
"scripts": {
|
|
"test": "node_modules/.bin/mocha -u qunit spec/qunit_spec.js"
|
|
},
|
|
"optionalDependencies": {},
|
|
"readme": "[![Build Status](https://travis-ci.org/wycats/handlebars.js.png?branch=master)](https://travis-ci.org/wycats/handlebars.js)\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\n\nInstalling\n----------\nInstalling Handlebars is easy. Simply download the package [from the\nofficial site](http://handlebarsjs.com/) and add it to your web pages\n(you should usually use the most recent version).\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 = \"<p>Hello, my name is {{name}}. I am from {{hometown}}. I have \" +\n \"{{kids.length}} kids:</p>\" +\n \"<ul>{{#kids}}<li>{{name}} is {{age}}</li>{{/kids}}</ul>\";\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// <p>Hello, my name is Alan. I am from Somewhere, TX. I have 2 kids:</p>\n// <ul>\n// <li>Jimmy is 12</li>\n// <li>Sally is 4</li>\n// </ul>\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(context) {\n return \"<a href='\" + context.url + \"'>\" + context.body + \"</a>\";\n});\n\nvar context = { posts: [{url: \"/hello-world\", body: \"Hello World!\"}] };\nvar source = \"<ul>{{#posts}}<li>{{{link_to this}}}</li>{{/posts}}</ul>\"\n\nvar template = Handlebars.compile(source);\ntemplate(context);\n\n// Would render:\n//\n// <ul>\n// <li><a href='/hello-world'>Hello World!</a></li>\n// </ul>\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 descendents and ancestors of the\ncurrent context.\n\nTo display data from descendent 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{{#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, context) {\n return \"<a href='/posts\" + context.url + \"'>\" + title + \"!</a>\"\n});\n\nvar context = { posts: [{url: \"/hello-world\", body: \"Hello World!\"}] };\nvar source = '<ul>{{#posts}}<li>{{{link_to \"Post\" this}}}</li>{{/posts}}</ul>'\n\nvar template = Handlebars.compile(source);\ntemplate(context);\n\n// Would render:\n//\n// <ul>\n// <li><a href='/posts/hello-world'>Post!</a></li>\n// </ul>\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 = \"<ul>{{#people}}<li>{{#link}}{{name}}{{/link}}</li>{{/people}}</ul>\";\nHandlebars.registerHelper('link', function(options) {\n return '<a href=\"/people/' + this.id + '\">' + options.fn(this) + '</a>';\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// <ul>\n// <li><a href=\"/people/1\">Alan</a></li>\n// <li><a href=\"/people/2\">Yehuda</a></li>\n// </ul>\n```\n\nWhenever the block helper is called it is given two parameters, the\nargument that is passed to the helper, or the current context if no\nargument is passed and the compiled contents of the block. Inside of\nthe block helper the value of `this` is the current context, wrapped to\ninclude a method named `__get__` that helps translate paths into values\nwithin the helpers.\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 = \"<ul>{{#people}}<li>{{> link}}</li>{{/people}}</ul>\";\n\nHandlebars.registerPartial('link', '<a href=\"/people/{{id}}\">{{name}}</a>')\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// <ul>\n// <li><a href=\"/people/1\">Alan</a></li>\n// <li><a href=\"/people/2\">Yehuda</a></li>\n// </ul>\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<div>\n {{! This comment will not end up in the output }}\n <!-- This comment will show up in the output -->\n</div>\n```\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<pre>\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</pre>\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 the using\nthe `Handlebars.template` method and the resulting object may be as\nnormal.\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\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,\nand we will have some benchmarks in the near future.\n\n\nBuilding\n--------\n\nTo build handlebars, just run `rake release`, and you will get two files\nin the `dist` directory.\n\n\nUpgrading\n---------\n\nWhen upgrading from the Handlebars 0.9 series, be aware that the\nsignature for passing custom helpers or partials to templates has\nchanged.\n\nInstead of:\n\n```js\ntemplate(context, helpers, partials, [data])\n```\n\nUse:\n\n```js\ntemplate(context, {helpers: helpers, partials: partials, data: data})\n```\n\nKnown Issues\n------------\n* Handlebars.js can be cryptic when there's an error while rendering.\n* Using a variable, helper, or partial named `class` causes errors in IE browsers. (Instead, use `className`)\n\nHandlebars in the Wild\n-----------------\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* Don Park wrote an Express.js view engine adapter for Handlebars.js called\n [hbs](http://github.com/donpark/hbs).\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* [Ember.js](http://www.emberjs.com) makes Handlebars.js the primary way to\n structure your views, also with automatic data binding support.\n* Les Hill (@leshill) wrote a Rails Asset Pipeline gem named\n handlebars_assets](http://github.com/leshill/handlebars_assets).\n* [Gist about Synchronous and asynchronous loading of external handlebars templates](https://gist.github.com/2287070)\n\nHelping Out\n-----------\nTo build Handlebars.js you'll need a few things installed.\n\n* Node.js\n* Jison, for building the compiler - `npm install jison`\n* Ruby\n* therubyracer, for running tests - `gem install therubyracer`\n* rspec, for running tests - `gem install rspec`\n\nThere's a Gemfile in the repo, so you can run `bundle` to install rspec\nand therubyracer if you've got bundler installed.\n\nTo build Handlebars.js from scratch, you'll want to run `rake compile`\nin the root of the project. That will build Handlebars and output the\nresults to the dist/ folder. To run tests, run `rake spec`. You can also\nrun our set of benchmarks with `rake bench`.\n\nIf you notice any problems, please report\nthem to the GitHub issue tracker at\n[http://github.com/wycats/handlebars.js/issues](http://github.com/wycats/handlebars.js/issues).\nFeel free to contact commondream or wycats through GitHub with any other\nquestions or feature requests. To submit changes fork the project and\nsend a pull request.\n\nLicense\n-------\nHandlebars.js is released under the MIT license.\n\n",
|
|
"readmeFilename": "README.markdown",
|
|
"bugs": {
|
|
"url": "https://github.com/wycats/handlebars.js/issues"
|
|
},
|
|
"_id": "handlebars@1.0.11",
|
|
"dist": {
|
|
"shasum": "0a7f8ac34a41929ce1a9b0429283b31c76812b17"
|
|
},
|
|
"_from": "handlebars@1.0.11",
|
|
"_resolved": "https://registry.npmjs.org/handlebars/-/handlebars-1.0.11.tgz"
|
|
}
|