{"_id":"coffee-templates","_rev":"74-9b10d2ddef9fd0e7d523fdbfae04289f","name":"coffee-templates","description":"Fastest Minimalist CoffeeScript/JavaScript CoffeeCup/Handlebars/Mustache template engine.","dist-tags":{"latest":"0.0.6"},"versions":{"0.0.2":{"name":"coffee-templates","version":"0.0.2","description":"Fastest Minimalist CoffeeScript/JavaScript CoffeeCup/Handlebars/Mustache template engine.","main":"js/coffee-templates.js","directories":{"test":"test"},"scripts":{"pretest":"coffee --bare -o js coffee/coffee-templates.coffee","test":"mocha --reporter spec --bail --ui bdd --colors --compilers coffee:coffee-script --require coffee-script test/test.coffee"},"repository":{"type":"git","url":"git://github.com/mikesmullin/coffee-templates.git"},"keywords":["html","html5","markup","template","coffeecup","mustache","handlebars","noengine","fast","fastest","browser","nodejs","engine"],"author":{"name":"Mike Smullin","email":"mike@smullindesign.com"},"license":"MIT","readmeFilename":"README.md","devDependencies":{"chai":"~1.4.0"},"readme":"# Why CoffeeTemplates?\n\n * 89.5% smaller download than [CoffeeCup](https://github.com/gradus/coffeecup) + [Handlebars](http://handlebarsjs.com/)--but compiles BOTH with just [226 lines](https://github.com/mikesmullin/coffee-templates/blob/production/js/coffee-templates.js).\n * thats just [6.9KB](https://raw.github.com/mikesmullin/coffee-templates/production/js/coffee-templates.js), [4.2KB minified](https://raw.github.com/mikesmullin/coffee-templates/production/js/coffee-templates.min.js), and [2.1KB gzipped](https://raw.github.com/mikesmullin/coffee-templates/production/js/coffee-templates.min.js.gz)\n * renders between [22%](http://jsperf.com/coffeecup-vs-coffee-templates) to [80% faster](http://jsperf.com/handlebars-vs-coffee-templates)\n * stand-alone client-side in browser or server-side with Node.js with NO [dependencies](https://github.com/mikesmullin/coffee-templates/blob/production/package.json)\n * compiling to .js yields one-function-per-template which renders using ONLY string concatenation--the secret to its speed\n * when compiled to .js, no ancillary \"engine\" library is required to render the template functions. nor is one embedded within the functions.\n * compiling directly from `.coffee` to `.html` or aggregated `templates.js` eliminates a lot of inbetween middleware\n * this means delays, complexities, and potential for double-trees between client and server-side templating engines are eliminated\n * only one language to write; one language to teach/master; one language to rule them all!\n * common functions available to node/js/coffee also available in templates i.e. require() and executed in same scope\n\nInspired by [coffeecup](https://github.com/gradus/coffeecup),\n and [ck](https://github.com/aeosynth/ck),\n and [mini-handlebars](https://github.com/mikesmullin/mini-handlebars) libraries.\n\n\n## Rendering Coffee to HTML\n\n```coffeescript\n# this line is only required within node\nCoffeeTemplates = require 'coffee-templates'\n\n# initialize new engine\nengine = new CoffeeTemplates format: true\n\n# provide template expression\ndoctype 5\nhtml ->\n  head ->\n    meta charset: 'utf-8'\n    title \"#{@title or 'Untitled'} | A completely plausible website\"\n    meta(name: 'description', content: @description) if @description?\n\n    link rel: 'stylesheet', href: '/css/app.css'\n\n    style '''\n      body {font-family: sans-serif}\n      header, nav, section, footer {display: block}\n    '''\n\n    comment 'Stylus is supported as well'\n\n    stylus '''\n      body\n        margin: 0\n    '''\n\n    script src: '/js/jquery.js'\n\n    coffeescript ->\n      $(document).ready ->\n        alert 'Alerts suck!'\n  body ->\n    header ->\n      h1 @title or 'Untitled'\n\n      nav ->\n        ul ->\n          (li -> a href: '/', -> 'Home') unless @path is '/'\n          li -> a href: '/chunky', -> 'Bacon!'\n          switch @user.role\n            when 'owner', 'admin'\n              li -> a href: '/admin', -> 'Secret Stuff'\n            when 'vip'\n              li -> a href: '/vip', -> 'Exclusive Stuff'\n            else\n              li -> a href: '/commoners', -> 'Just Stuff'\n\n    div '#myid.myclass.anotherclass', style: 'position: fixed', ->\n      p 'Divitis kills! Inline styling too.'\n\n    section ->\n      # A helper function you built and included.\n      breadcrumb separator: '>', clickable: yes\n\n      h2 \"Let's count to 10:\"\n      p i for i in [1..10]\n\n      # Another hypothetical helper.\n      form_to @post, ->\n        textbox '#title', label: 'Title:'\n        textbox '#author', label: 'Author:'\n        submit 'Save'\n\n    footer ->\n      # CoffeeScript comments. Not visible in the output document.\n      comment 'HTML comments.'\n      p 'Bye!'\n\n\nlocals =\n  title: 'Best website'\n\n# render coffee template to html\nconsole.log engine.render template, locals\n```\n\n## Rendering Coffee to Handlebars\n```coffeescript\nengine = new CoffeeTemplates format: true, handlebars: true\n\ntemplate = ->\n  ul ->\n    for company in @companies\n      block \"each #{company}\", ->\n        li '{{this}}'\n\nconsole.log handlebars_template = engine.render template,\n  companies: [ 'google', 'yahoo' ]\n```\n\nOutputs:\n\n```html\n<ul>\n  {{#each google}}\n    <li>{{this}}</li>\n  {{/each}}\n  {{#each yahoo}}\n    <li>{{this}}</li>\n  {{/each}}\n</ul>\n```\n\n## Improving Handlebars/Mustache\nNotice that while regular Mustache/Handlebars templates still compile,\nwe took the liberty to engineer several improvements to the compiler:\n\n * {{#blocks arg...}}{{/blocks}} can also be written as {{blocks arg...}}{{/blocks}}\n * however, blocks are required to take at least one argument\n * blocks are just javascript functions\n * any function that implements `function(arg..., cb) { cb(arg...) }` can be executed by a block\n * a function need only be in the window/root scope to be used as a helper; no need to define iterators specially\n * blocks can take any number of arguments\n * blocks can also list callback function arguments within parenthesis ()\n * any character that is valid in a function or variable name is a valid block or block argument name\n * therefore, `<ul>{{$.each companies}}<li>{{this}}</li>{{/$.each}}</ul>` is valid\n * and so is, `<ul>{{jQuery.each people, (key, value)}}<li>{{key}}: {{value}}</li>{{/each}}</ul>`\n\n```coffeescript\nengine = new CoffeeTemplates format: true\n\nconsole.log mustache_template = engine.render ->\n  block \"each company, (name, data)\", ->\n    h2 '{{name}}'\n    ul ->\n      block \"each data.people\", ->\n        li '{{this}}'\n```\n\nOutputs:\n\n```html\n{{each company, (name, data)}}\n  <h2>{{name}}</h2>\n  <ul>\n    {{each data.people}}\n      <li>{{this}}</li>\n    {{/each}}\n  </ul>\n{{/each}}\n```\n\n## Rendering Coffee/Handlebars/Mustache a NoEngine JS Function\n```coffeescript\nmustache_template = '{{each company, (name, data)}}<h2>{{name}}</h2><ul>{{each data.people}}<li>{{this}}</li>{{/each}}</ul>{{/each}}'\n\nconsole.log template_fn = CoffeeTemplates.compile mustache_template\n```\n\nOutputs:\n\n```javascript\nfunction anonymous(i) {\nvar o='',w=function(f,a) {o='';f.apply(i, a);return o};return w(each,[i.company,function(name,data){o+=\"<h2>\"+name+\"</h2><ul>\"+w(each,[data.people,function(){o+=\"<li>\"+this+\"</li>\"}])+\"</ul>\"}])\n}\n```\n\nThis single function is a completely stand-alone version of your template, and is all that is needed to render the HTML.\n\nOf course, this could also be used to render XML or some other markup, as well.\n\n## Rendering a NoEngine JS Function to HTML\n```coffeescript\nwindow.each = (o, cb) ->\n  for k of o\n    cb.apply o[k], [k, o[k]]\n  return\n\nconsole.log html = template_fn company:\n  goog: people: ['Larry Page', 'Sergey Brin']\n  msft: people: ['Bill Gates']\n```\n\nOutputs:\n\n```html\n<h2>goog</h2><ul><li>Larry Page</li><li>Sergey Brin</li></ul><h2>msft</h2><ul><li>Bill Gates</li></ul>\n```\n\n## Rendering multiple templates to function\n```coffeescript\nconsole.log templates = CoffeeTemplates.compileAll\n  'views/users/index': (CoffeeTemplates.compile mustache_template, false)\n  'views/users/index_by_company': (CoffeeTemplates.compile mustache_template, false)\n```\n\nOutputs:\n\n```javascript\nfunction anonymous(n,i) {\nvar o='',w=function(f,a) {o='';f.apply(i, a);return o},t={}\nt[\"views/users/index\"]=function(){return w(each,[this.company,function(name,data){o+=\"<h2>\"+name+\"</h2><ul>\"+w(each,[data.people,function(){o+=\"<li>\"+this+\"</li>\"}])+\"</ul>\"}])}\nt[\"views/users/index_by_company\"]=function(){return w(each,[this.company,function(name,data){o+=\"<h2>\"+name+\"</h2><ul>\"+w(each,[data.people,function(){o+=\"<li>\"+this+\"</li>\"}])+\"</ul>\"}])}\nreturn t[n].call(i)\n}\n```\n\nFrom here you would normally save the function in a file like `static/public/assets/templates.js`.\n\n## Further examples\n\nAs usual, for the latest examples, review the easy-to-follow [./test/test.coffee](https://github.com/mikesmullin/coffee-templates/blob/production/test/test.coffee).\n\nOr try it immediately in your browser with [codepen](http://codepen.io/mikesmullin/pen/nIytw).\n\n\n## Useful Tools\n\n* [Haml to HTML to CoffeeCup to JavaScript to CoffeeScript Converter](http://haml-html-coffeecup-javascript-coffeescript-converter.smullindesign.com/)\n","_id":"coffee-templates@0.0.2","dist":{"shasum":"dd79e4a49223431d01d0c652a2655c40902f2737","tarball":"https://registry.npmjs.org/coffee-templates/-/coffee-templates-0.0.2.tgz","integrity":"sha512-VJbN4ir/btYwSDhTBnbH5VebaRfeOYY9zw7OGPlEsMDwaiu4F8IhIvRKMfYu5iYUoMenEjCITtEnHfLV1qFoYw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDt7CMaujnXAi95YwLD8zaCKTQXRzrq5v1WS8KbeJTUnQIhAMZElM3h/M1qVvP7G6dW17RqIgjcriCXPS4PdncnCTXN"}]},"_npmVersion":"1.1.66","_npmUser":{"name":"mikesmullin","email":"mike@smullindesign.com"},"maintainers":[{"name":"mikesmullin","email":"mike@smullindesign.com"}]},"0.0.3":{"name":"coffee-templates","version":"0.0.3","description":"Fastest Minimalist CoffeeScript/JavaScript CoffeeCup/Handlebars/Mustache template engine.","main":"js/coffee-templates.js","directories":{"test":"test"},"scripts":{"pretest":"coffee --bare -o js coffee/coffee-templates.coffee","test":"mocha --reporter spec --bail --ui bdd --colors --compilers coffee:coffee-script --require coffee-script test/test.coffee"},"repository":{"type":"git","url":"git://github.com/mikesmullin/coffee-templates.git"},"keywords":["html","html5","markup","template","coffeecup","mustache","handlebars","noengine","fast","fastest","browser","nodejs","engine"],"author":{"name":"Mike Smullin","email":"mike@smullindesign.com"},"license":"MIT","readmeFilename":"README.md","devDependencies":{"chai":"~1.4.0"},"readme":"# Why CoffeeTemplates?\n\n * 89.5% smaller download than [CoffeeCup](https://github.com/gradus/coffeecup) + [Handlebars](http://handlebarsjs.com/)--but compiles BOTH with just [226 lines](https://github.com/mikesmullin/coffee-templates/blob/production/js/coffee-templates.js).\n * thats just [6.9KB](https://raw.github.com/mikesmullin/coffee-templates/production/js/coffee-templates.js), [4.2KB minified](https://raw.github.com/mikesmullin/coffee-templates/production/js/coffee-templates.min.js), and [2.1KB gzipped](https://raw.github.com/mikesmullin/coffee-templates/production/js/coffee-templates.min.js.gz)\n * renders between [22%](http://jsperf.com/coffeecup-vs-coffee-templates) to [80% faster](http://jsperf.com/handlebars-vs-coffee-templates) as tested on node/chrome/v8\n * stand-alone client-side in browser or server-side with Node.js with NO [dependencies](https://github.com/mikesmullin/coffee-templates/blob/production/package.json)\n * compiling to .js yields one-function-per-template which renders using ONLY string concatenation--the secret to its speed\n * when compiled to .js, no ancillary \"engine\" library is required to render the template functions. nor is one embedded within the functions.\n * compiling directly from `.coffee` to `.html` or aggregated `templates.js` eliminates a lot of inbetween middleware\n * this means delays, complexities, and potential for double-trees between client and server-side templating engines are eliminated\n * only one language to write; one language to teach/master; one language to rule them all!\n * common functions available to node/js/coffee also available in templates i.e. require() and executed in same scope\n\nInspired by [coffeecup](https://github.com/gradus/coffeecup),\n and [ck](https://github.com/aeosynth/ck),\n and [mini-handlebars](https://github.com/mikesmullin/mini-handlebars) libraries.\n\n\n## Rendering Coffee to HTML\n\n```coffeescript\n# this line is only required within node\nCoffeeTemplates = require 'coffee-templates'\n\n# initialize new engine\nengine = new CoffeeTemplates format: true\n\n# provide template expression\ndoctype 5\nhtml ->\n  head ->\n    meta charset: 'utf-8'\n    title \"#{@title or 'Untitled'} | A completely plausible website\"\n    meta(name: 'description', content: @description) if @description?\n\n    link rel: 'stylesheet', href: '/css/app.css'\n\n    style '''\n      body {font-family: sans-serif}\n      header, nav, section, footer {display: block}\n    '''\n\n    comment 'Stylus is not supported but an alternative is coming soon'\n\n    script src: '/js/jquery.js'\n\n    coffeescript ->\n      $(document).ready ->\n        alert 'Alerts suck!'\n  body ->\n    header ->\n      h1 @title or 'Untitled'\n\n      nav ->\n        ul ->\n          (li -> a href: '/', -> 'Home') unless @path is '/'\n          li -> a href: '/chunky', -> 'Bacon!'\n          switch @user.role\n            when 'owner', 'admin'\n              li -> a href: '/admin', -> 'Secret Stuff'\n            when 'vip'\n              li -> a href: '/vip', -> 'Exclusive Stuff'\n            else\n              li -> a href: '/commoners', -> 'Just Stuff'\n\n    div '#myid.myclass.anotherclass', style: 'position: fixed', ->\n      p 'Divitis kills! Inline styling too.'\n\n    section ->\n      # A helper function you built and included.\n      breadcrumb separator: '>', clickable: yes\n\n      h2 \"Let's count to 10:\"\n      p i for i in [1..10]\n\n      # Another hypothetical helper.\n      form_to @post, ->\n        textbox '#title', label: 'Title:'\n        textbox '#author', label: 'Author:'\n        submit 'Save'\n\n    footer ->\n      # CoffeeScript comments. Not visible in the output document.\n      comment 'HTML comments.'\n      p 'Bye!'\n\n\nlocals =\n  title: 'Best website'\n\n# render coffee template to html\nconsole.log engine.render template, locals\n```\n\n## Rendering Coffee to Handlebars\n```coffeescript\nengine = new CoffeeTemplates format: true, handlebars: true\n\ntemplate = ->\n  ul ->\n    for company in @companies\n      block \"each #{company}\", ->\n        li '{{this}}'\n\nconsole.log handlebars_template = engine.render template,\n  companies: [ 'google', 'yahoo' ]\n```\n\nOutputs:\n\n```html\n<ul>\n  {{#each google}}\n    <li>{{this}}</li>\n  {{/each}}\n  {{#each yahoo}}\n    <li>{{this}}</li>\n  {{/each}}\n</ul>\n```\n\n## Improving Handlebars/Mustache\nNotice that while regular Mustache/Handlebars templates still compile,\nwe took the liberty to engineer several improvements to the compiler:\n\n * {{#blocks arg...}}{{/blocks}} can also be written as {{blocks arg...}}{{/blocks}}\n * however, blocks are required to take at least one argument\n * blocks are just javascript functions\n * any function that implements `function(arg..., cb) { cb(arg...) }` can be executed by a block\n * a function need only be in the window/root scope to be used as a helper; no need to define iterators specially\n * blocks can take any number of arguments\n * blocks can also list callback function arguments within parenthesis ()\n * any character that is valid in a function or variable name is a valid block or block argument name\n * therefore, `<ul>{{$.each companies}}<li>{{this}}</li>{{/$.each}}</ul>` is valid\n * and so is, `<ul>{{jQuery.each people, (key, value)}}<li>{{key}}: {{value}}</li>{{/each}}</ul>`\n\n```coffeescript\nengine = new CoffeeTemplates format: true\n\nconsole.log mustache_template = engine.render ->\n  block \"each company, (name, data)\", ->\n    h2 '{{name}}'\n    ul ->\n      block \"each data.people\", ->\n        li '{{this}}'\n```\n\nOutputs:\n\n```html\n{{each company, (name, data)}}\n  <h2>{{name}}</h2>\n  <ul>\n    {{each data.people}}\n      <li>{{this}}</li>\n    {{/each}}\n  </ul>\n{{/each}}\n```\n\n## Rendering Coffee/Handlebars/Mustache to a NoEngine JS Function\n```coffeescript\nmustache_template = '{{each company, (name, data)}}<h2>{{name}}</h2><ul>{{each data.people}}<li>{{this}}</li>{{/each}}</ul>{{/each}}'\n\nconsole.log template_fn = CoffeeTemplates.compile mustache_template\n```\n\nOutputs:\n\n```javascript\nfunction anonymous(i) {\nvar o='',w=function(f,a){o='';f.apply(i, a);return o};return w(each,[i.company,function(name,data){o+=\"<h2>\"+name+\"</h2><ul>\"+w(each,[data.people,function(){o+=\"<li>\"+this+\"</li>\"}])+\"</ul>\"}])\n}\n```\n\nThis single function is a completely stand-alone version of your template, and is all that is needed to render the HTML.\n\nOf course, this could also be used to render XML or some other markup, as well.\n\n## Rendering a NoEngine JS Function to HTML\n```coffeescript\nwindow.each = (o, cb) ->\n  for k of o\n    cb.apply o[k], [k, o[k]]\n  return\n\nconsole.log html = template_fn company:\n  goog: people: ['Larry Page', 'Sergey Brin']\n  msft: people: ['Bill Gates']\n```\n\nOutputs:\n\n```html\n<h2>goog</h2><ul><li>Larry Page</li><li>Sergey Brin</li></ul><h2>msft</h2><ul><li>Bill Gates</li></ul>\n```\n\n## Rendering multiple templates to function\n```coffeescript\nconsole.log templates = CoffeeTemplates.compileAll\n  'views/users/index': (CoffeeTemplates.compile mustache_template, false)\n  'views/users/index_by_company': (CoffeeTemplates.compile mustache_template, false)\n```\n\nOutputs:\n\n```javascript\nfunction anonymous(n,i) {\nvar o='',w=function(f,a){o='';f.apply(i, a);return o},t={}\nt[\"views/users/index\"]=function(){return w(each,[this.company,function(name,data){o+=\"<h2>\"+name+\"</h2><ul>\"+w(each,[data.people,function(){o+=\"<li>\"+this+\"</li>\"}])+\"</ul>\"}])}\nt[\"views/users/index_by_company\"]=function(){return w(each,[this.company,function(name,data){o+=\"<h2>\"+name+\"</h2><ul>\"+w(each,[data.people,function(){o+=\"<li>\"+this+\"</li>\"}])+\"</ul>\"}])}\nreturn t[n].call(i)\n}\n```\n\nFrom here you would normally save the function in a file like `static/public/assets/templates.js`.\n\n## Further examples\n\nAs usual, for the latest examples, review the easy-to-follow [./test/test.coffee](https://github.com/mikesmullin/coffee-templates/blob/production/test/test.coffee).\n\nOr try it immediately in your browser with [codepen](http://codepen.io/mikesmullin/pen/nIytw).\n\n\n## Useful Tools\n\n* [Haml to HTML to CoffeeCup to JavaScript to CoffeeScript Converter](http://haml-html-coffeecup-javascript-coffeescript-converter.smullindesign.com/)\n","_id":"coffee-templates@0.0.3","dist":{"shasum":"25995d7bd82732cc0ed29df8bbe4abddd6ce5308","tarball":"https://registry.npmjs.org/coffee-templates/-/coffee-templates-0.0.3.tgz","integrity":"sha512-23Rbe7vqcmK9oZ1ckd31yrV8epJljfc5bFb9MI1oFeHiWLkvSftniz47GEvRrTLyg3DYn57AKHRow9W4ZetySA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIBZUh5tagUzlMNuNJegKx21y7yf7za7rInyzDAv5jQO2AiAdPJhyntXx22pfE1NSHG6LsaTcC9ulpLhbGEkaYm9N/g=="}]},"_npmVersion":"1.1.66","_npmUser":{"name":"mikesmullin","email":"mike@smullindesign.com"},"maintainers":[{"name":"mikesmullin","email":"mike@smullindesign.com"}]},"0.0.4":{"name":"coffee-templates","version":"0.0.4","description":"Fastest Minimalist CoffeeScript/JavaScript CoffeeCup/Handlebars/Mustache template engine.","main":"js/coffee-templates.js","directories":{"test":"test"},"scripts":{"pretest":"coffee --bare -o js coffee/coffee-templates.coffee","test":"mocha --reporter spec --bail --ui bdd --colors --compilers coffee:coffee-script --require coffee-script test/test.coffee"},"repository":{"type":"git","url":"git://github.com/mikesmullin/coffee-templates.git"},"keywords":["html","html5","markup","template","coffeecup","mustache","handlebars","noengine","fast","fastest","browser","nodejs","engine"],"author":{"name":"Mike Smullin","email":"mike@smullindesign.com"},"license":"MIT","readmeFilename":"README.md","devDependencies":{"chai":"*"},"readme":"# Why CoffeeTemplates?\n\n * 89.5% smaller download than [CoffeeCup](https://github.com/gradus/coffeecup) + [Handlebars](http://handlebarsjs.com/)--but compiles BOTH with just [226 lines](https://github.com/mikesmullin/coffee-templates/blob/stable/js/coffee-templates.js).\n * thats just [6.9KB](https://raw.github.com/mikesmullin/coffee-templates/stable/js/coffee-templates.js), [4.2KB minified](https://raw.github.com/mikesmullin/coffee-templates/stable/js/coffee-templates.min.js), and [2.1KB gzipped](https://raw.github.com/mikesmullin/coffee-templates/stable/js/coffee-templates.min.js.gz)\n * renders between [22%](http://jsperf.com/coffeecup-vs-coffee-templates) to [80% faster](http://jsperf.com/handlebars-vs-coffee-templates) as tested on node/chrome/v8\n * stand-alone client-side in browser or server-side with Node.js with NO [dependencies](https://github.com/mikesmullin/coffee-templates/blob/stable/package.json)\n * compiling to .js yields one-function-per-template which renders using ONLY string concatenation--the secret to its speed\n * when compiled to .js, no ancillary \"engine\" library is required to render the template functions. nor is one embedded within the functions.\n * compiling directly from `.coffee` to `.html` or aggregated `templates.js` eliminates a lot of inbetween middleware\n * this means delays, complexities, and potential for double-trees between client and server-side templating engines are eliminated\n * only one language to write; one language to teach/master; one language to rule them all!\n * common functions available to node/js/coffee also available in templates i.e. require() and executed in same scope\n\nInspired by [coffeecup](https://github.com/gradus/coffeecup),\n and [ck](https://github.com/aeosynth/ck),\n and [mini-handlebars](https://github.com/mikesmullin/mini-handlebars) libraries.\n\n## And now, a Haiku\n\n    5  template languages\n    7  are low-level logical\n    5  function recursions\n    7  the author dared not express\n    5  in the host language.\n    \n    5  syntactic sugar\n    7  on low-level languages\n    5  ala coffeescript\n    7  brings template control to the\n    5  speed where it belongs.\n\n## Rendering Coffee to HTML\n\n```coffeescript\n# this line is only required within node\nCoffeeTemplates = require 'coffee-templates'\n\n# initialize new engine\nengine = new CoffeeTemplates format: true\n\n# provide template expression\ndoctype 5\nhtml ->\n  head ->\n    meta charset: 'utf-8'\n    title \"#{@title or 'Untitled'} | A completely plausible website\"\n    meta(name: 'description', content: @description) if @description?\n\n    link rel: 'stylesheet', href: '/css/app.css'\n\n    style '''\n      body {font-family: sans-serif}\n      header, nav, section, footer {display: block}\n    '''\n\n    comment 'Stylus is not supported but CoffeeStyleshets might be'\n\n    script src: '/js/jquery.js'\n\n    coffeescript ->\n      $(document).ready ->\n        alert 'Alerts suck!'\n  body ->\n    header ->\n      h1 @title or 'Untitled'\n\n      nav ->\n        ul ->\n          (li -> a href: '/', -> 'Home') unless @path is '/'\n          li -> a href: '/chunky', -> 'Bacon!'\n          switch @user.role\n            when 'owner', 'admin'\n              li -> a href: '/admin', -> 'Secret Stuff'\n            when 'vip'\n              li -> a href: '/vip', -> 'Exclusive Stuff'\n            else\n              li -> a href: '/commoners', -> 'Just Stuff'\n\n    div '#myid.myclass.anotherclass', style: 'position: fixed', ->\n      p 'Divitis kills! Inline styling too.'\n\n    section ->\n      # A helper function you built and included.\n      breadcrumb separator: '>', clickable: yes\n\n      h2 \"Let's count to 10:\"\n      p i for i in [1..10]\n\n      # Another hypothetical helper.\n      form_to @post, ->\n        textbox '#title', label: 'Title:'\n        textbox '#author', label: 'Author:'\n        submit 'Save'\n\n    footer ->\n      # CoffeeScript comments. Not visible in the output document.\n      comment 'HTML comments.'\n      p 'Bye!'\n\n\nlocals =\n  title: 'Best website'\n\n# render coffee template to html\nconsole.log engine.render template, locals\n```\n\n## Rendering Coffee to Handlebars\n```coffeescript\nengine = new CoffeeTemplates format: true, handlebars: true\n\ntemplate = ->\n  ul ->\n    for company in @companies\n      block \"each #{company}\", ->\n        li '{{this}}'\n\nconsole.log handlebars_template = engine.render template,\n  companies: [ 'google', 'yahoo' ]\n```\n\nOutputs:\n\n```html\n<ul>\n  {{#each google}}\n    <li>{{this}}</li>\n  {{/each}}\n  {{#each yahoo}}\n    <li>{{this}}</li>\n  {{/each}}\n</ul>\n```\n\n## Improving Handlebars/Mustache\nNotice that while regular Mustache/Handlebars templates still compile,\nwe took the liberty to engineer several improvements to the compiler:\n\n * {{#blocks arg...}}{{/blocks}} can also be written as {{blocks arg...}}{{/blocks}}\n * however, blocks are required to take at least one argument\n * blocks are just javascript functions\n * any function that implements `function(arg..., cb) { cb(arg...) }` can be executed by a block\n * a function need only be in the window/root scope to be used as a helper; no need to define iterators specially\n * blocks can take any number of arguments\n * blocks can also list callback function arguments within parenthesis ()\n * any character that is valid in a function or variable name is a valid block or block argument name\n * therefore, `<ul>{{$.each companies}}<li>{{this}}</li>{{/$.each}}</ul>` is valid\n * and so is, `<ul>{{jQuery.each people, (key, value)}}<li>{{key}}: {{value}}</li>{{/each}}</ul>`\n\n```coffeescript\nengine = new CoffeeTemplates format: true\n\nconsole.log mustache_template = engine.render ->\n  block \"each company, (name, data)\", ->\n    h2 '{{name}}'\n    ul ->\n      block \"each data.people\", ->\n        li '{{this}}'\n```\n\nOutputs:\n\n```html\n{{each company, (name, data)}}\n  <h2>{{name}}</h2>\n  <ul>\n    {{each data.people}}\n      <li>{{this}}</li>\n    {{/each}}\n  </ul>\n{{/each}}\n```\n\n## Rendering Coffee/Handlebars/Mustache to a NoEngine JS Function\n```coffeescript\nmustache_template = '{{each company, (name, data)}}<h2>{{name}}</h2><ul>{{each data.people}}<li>{{this}}</li>{{/each}}</ul>{{/each}}'\n\nconsole.log template_fn = CoffeeTemplates.compile mustache_template\n```\n\nOutputs:\n\n```javascript\nfunction anonymous(i) {\nvar o='',w=function(f,a){o='';f.apply(i, a);return o};return w(each,[i.company,function(name,data){o+=\"<h2>\"+name+\"</h2><ul>\"+w(each,[data.people,function(){o+=\"<li>\"+this+\"</li>\"}])+\"</ul>\"}])\n}\n```\n\nThis single function is a completely stand-alone version of your template, and is all that is needed to render the HTML.\n\nOf course, this could also be used to render XML or some other markup, as well.\n\n## Rendering a NoEngine JS Function to HTML\n```coffeescript\nwindow.each = (o, cb) ->\n  for k of o\n    cb.apply o[k], [k, o[k]]\n  return\n\nconsole.log html = template_fn company:\n  goog: people: ['Larry Page', 'Sergey Brin']\n  msft: people: ['Bill Gates']\n```\n\nOutputs:\n\n```html\n<h2>goog</h2><ul><li>Larry Page</li><li>Sergey Brin</li></ul><h2>msft</h2><ul><li>Bill Gates</li></ul>\n```\n\n## Rendering multiple templates to function\n```coffeescript\nconsole.log templates = CoffeeTemplates.compileAll\n  'views/users/index': (CoffeeTemplates.compile mustache_template, false)\n  'views/users/index_by_company': (CoffeeTemplates.compile mustache_template, false)\n```\n\nOutputs:\n\n```javascript\nfunction anonymous(n,i) {\nvar o='',w=function(f,a){o='';f.apply(i, a);return o},t={}\nt[\"views/users/index\"]=function(){return w(each,[this.company,function(name,data){o+=\"<h2>\"+name+\"</h2><ul>\"+w(each,[data.people,function(){o+=\"<li>\"+this+\"</li>\"}])+\"</ul>\"}])}\nt[\"views/users/index_by_company\"]=function(){return w(each,[this.company,function(name,data){o+=\"<h2>\"+name+\"</h2><ul>\"+w(each,[data.people,function(){o+=\"<li>\"+this+\"</li>\"}])+\"</ul>\"}])}\nreturn t[n].call(i)\n}\n```\n\nFrom here you would normally save the function in a file like `static/public/assets/templates.js`.\n\n## Further examples\n\nAs usual, for the latest examples, review the easy-to-follow [./test/test.coffee](https://github.com/mikesmullin/coffee-templates/blob/stable/test/test.coffee).\n\nOr try it immediately in your browser with [codepen](http://codepen.io/mikesmullin/pen/nIytw).\n\n\n## Useful Tools\n\n* [Haml to HTML to CoffeeCup to JavaScript to CoffeeScript Converter](http://haml-html-coffeecup-javascript-coffeescript-converter.smullindesign.com/)\n","_id":"coffee-templates@0.0.4","dist":{"shasum":"f8ac2a8e1007256de9a3fff1f88a502871862626","tarball":"https://registry.npmjs.org/coffee-templates/-/coffee-templates-0.0.4.tgz","integrity":"sha512-dSID9Xem0fSV5hXg8sZUv6x/Yb5jpEQROoBpdlMtO7NZ2bk1gqhyx/Y99mw99JsyTy3d11Fow1Lqj67I2yFKnQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIDWjAFzQxuFssFkfWEA6FrWN+H/NrxcANce1GfaAVclcAiBnehRvH8mpMm9S74DfLiLosA6dBkCYPGtS7RlGj+kWuw=="}]},"_npmVersion":"1.1.66","_npmUser":{"name":"mikesmullin","email":"mike@smullindesign.com"},"maintainers":[{"name":"mikesmullin","email":"mike@smullindesign.com"}]},"0.0.5":{"name":"coffee-templates","version":"0.0.5","description":"Fastest Minimalist CoffeeScript/JavaScript CoffeeCup/Handlebars/Mustache template engine.","main":"js/coffee-templates.js","directories":{"test":"test"},"scripts":{"pretest":"coffee --bare -o js coffee/coffee-templates.coffee","test":"mocha --reporter spec --bail --ui bdd --colors --compilers coffee:coffee-script --require coffee-script test/test.coffee"},"repository":{"type":"git","url":"git://github.com/mikesmullin/coffee-templates.git"},"keywords":["html","html5","markup","template","coffeecup","mustache","handlebars","noengine","fast","fastest","browser","nodejs","engine"],"author":{"name":"Mike Smullin","email":"mike@smullindesign.com"},"license":"MIT","readmeFilename":"README.md","devDependencies":{"chai":"*"},"readme":"# Why CoffeeTemplates?\n\n * 89% smaller download than [CoffeeCup](https://github.com/gradus/coffeecup) + [Handlebars](http://handlebarsjs.com/)--but compiles BOTH with just [257 lines](https://github.com/mikesmullin/coffee-templates/blob/stable/js/coffee-templates.js).\n * thats just [8.6KB](https://raw.github.com/mikesmullin/coffee-templates/stable/js/coffee-templates.js), [5.5KB minified](https://raw.github.com/mikesmullin/coffee-templates/stable/js/coffee-templates.min.js), and [2.6KB gzipped](https://raw.github.com/mikesmullin/coffee-templates/stable/js/coffee-templates.min.js.gz)\n * renders between [22%](http://jsperf.com/coffeecup-vs-coffee-templates) to [80% faster](http://jsperf.com/handlebars-vs-coffee-templates) as tested on node/chrome/v8\n * stand-alone client-side in browser or server-side with Node.js with NO [dependencies](https://github.com/mikesmullin/coffee-templates/blob/stable/package.json)\n * compiling to .js yields one-function-per-template which renders using ONLY string concatenation--the secret to its speed\n * when compiled to .js, no ancillary \"engine\" library is required to render the template functions. nor is one embedded within the functions.\n * compiling directly from `.coffee` to `.html` or aggregated `templates.js` eliminates a lot of inbetween middleware\n * this means delays, complexities, and potential for double-trees between client and server-side templating engines are eliminated\n * only one language to write; one language to teach/master; one language to rule them all!\n * common functions available to node/js/coffee also available in templates i.e. require() and executed in same scope\n\nInspired by [coffeecup](https://github.com/gradus/coffeecup),\n and [ck](https://github.com/aeosynth/ck),\n and [mini-handlebars](https://github.com/mikesmullin/mini-handlebars) libraries.\n\n## And now, a Haiku\n\n    5  template languages\n    7  are low-level logical\n    5  function recursions\n    7  the author dared not express\n    5  in the host language.\n    \n    5  syntactic sugar\n    7  on low-level languages\n    5  ala coffeescript\n    7  brings template control to the\n    5  speed where it belongs.\n\n## Rendering Coffee to HTML\n\n```coffeescript\n# this line is only required within node\nCoffeeTemplates = require 'coffee-templates'\n\n# initialize new engine\nengine = new CoffeeTemplates format: true\n\n# provide template expression\ndoctype 5\nhtml ->\n  head ->\n    meta charset: 'utf-8'\n    title \"#{@title or 'Untitled'} | A completely plausible website\"\n    meta(name: 'description', content: @description) if @description?\n\n    link rel: 'stylesheet', href: '/css/app.css'\n\n    style '''\n      body {font-family: sans-serif}\n      header, nav, section, footer {display: block}\n    '''\n\n    comment 'Stylus is not supported but CoffeeStyleshets might be'\n\n    script src: '/js/jquery.js'\n\n    coffeescript ->\n      $(document).ready ->\n        alert 'Alerts suck!'\n  body ->\n    header ->\n      h1 @title or 'Untitled'\n\n      nav ->\n        ul ->\n          (li -> a href: '/', -> 'Home') unless @path is '/'\n          li -> a href: '/chunky', -> 'Bacon!'\n          switch @user.role\n            when 'owner', 'admin'\n              li -> a href: '/admin', -> 'Secret Stuff'\n            when 'vip'\n              li -> a href: '/vip', -> 'Exclusive Stuff'\n            else\n              li -> a href: '/commoners', -> 'Just Stuff'\n\n    div '#myid.myclass.anotherclass', style: 'position: fixed', ->\n      p 'Divitis kills! Inline styling too.'\n\n    section ->\n      # A helper function you built and included.\n      breadcrumb separator: '>', clickable: yes\n\n      h2 \"Let's count to 10:\"\n      p i for i in [1..10]\n\n      # Another hypothetical helper.\n      form_to @post, ->\n        textbox '#title', label: 'Title:'\n        textbox '#author', label: 'Author:'\n        submit 'Save'\n\n    footer ->\n      # CoffeeScript comments. Not visible in the output document.\n      comment 'HTML comments.'\n      p 'Bye!'\n\n\nlocals =\n  title: 'Best website'\n\n# render coffee template to html\nconsole.log engine.render template, locals\n```\n\n## Rendering Coffee to Handlebars\n```coffeescript\nengine = new CoffeeTemplates format: true, handlebars: true\n\ntemplate = ->\n  ul ->\n    for company in @companies\n      block \"each #{company}\", ->\n        li '{{this}}'\n\nconsole.log handlebars_template = engine.render template,\n  companies: [ 'google', 'yahoo' ]\n```\n\nOutputs:\n\n```html\n<ul>\n  {{#each google}}\n    <li>{{this}}</li>\n  {{/each}}\n  {{#each yahoo}}\n    <li>{{this}}</li>\n  {{/each}}\n</ul>\n```\n\n## Improving Handlebars/Mustache\nNotice that while regular Mustache/Handlebars templates still compile,\nwe took the liberty to engineer several improvements to the compiler:\n\n * {{#blocks arg...}}{{/blocks}} can also be written as {{blocks arg...}}{{/blocks}}\n * however, blocks are required to take at least one argument\n * blocks are just javascript functions\n * any function that implements `function(arg..., cb) { cb(arg...) }` can be executed by a block\n * a function need only be in the window/root scope to be used as a helper; no need to define iterators specially\n * blocks can take any number of arguments\n * blocks can also list callback function arguments within parenthesis ()\n * any character that is valid in a function or variable name is a valid block or block argument name\n * therefore, `<ul>{{$.each companies}}<li>{{this}}</li>{{/$.each}}</ul>` is valid\n * and so is, `<ul>{{jQuery.each people, (key, value)}}<li>{{key}}: {{value}}</li>{{/each}}</ul>`\n\n```coffeescript\nengine = new CoffeeTemplates format: true\n\nconsole.log mustache_template = engine.render ->\n  block \"each company, (name, data)\", ->\n    h2 '{{name}}'\n    ul ->\n      block \"each data.people\", ->\n        li '{{this}}'\n```\n\nOutputs:\n\n```html\n{{each company, (name, data)}}\n  <h2>{{name}}</h2>\n  <ul>\n    {{each data.people}}\n      <li>{{this}}</li>\n    {{/each}}\n  </ul>\n{{/each}}\n```\n\n## Rendering Coffee/Handlebars/Mustache to a NoEngine JS Function\n```coffeescript\nmustache_template = '{{each company, (name, data)}}<h2>{{name}}</h2><ul>{{each data.people}}<li>{{this}}</li>{{/each}}</ul>{{/each}}'\n\nconsole.log template_fn = CoffeeTemplates.compile mustache_template\n```\n\nOutputs:\n\n```javascript\nfunction anonymous(i) {\nvar o='',w=function(f,a){o='';f.apply(i, a);return o};return w(each,[i.company,function(name,data){o+=\"<h2>\"+name+\"</h2><ul>\"+w(each,[data.people,function(){o+=\"<li>\"+this+\"</li>\"}])+\"</ul>\"}])\n}\n```\n\nThis single function is a completely stand-alone version of your template, and is all that is needed to render the HTML.\n\nOf course, this could also be used to render XML or some other markup, as well.\n\n## Rendering a NoEngine JS Function to HTML\n```coffeescript\nwindow.each = (o, cb) ->\n  for k of o\n    cb.apply o[k], [k, o[k]]\n  return\n\nconsole.log html = template_fn company:\n  goog: people: ['Larry Page', 'Sergey Brin']\n  msft: people: ['Bill Gates']\n```\n\nOutputs:\n\n```html\n<h2>goog</h2><ul><li>Larry Page</li><li>Sergey Brin</li></ul><h2>msft</h2><ul><li>Bill Gates</li></ul>\n```\n\n## Rendering multiple templates to function\n```coffeescript\nconsole.log templates = ''+CoffeeTemplates.compileAll\n  'views/users/index': mustache_template\n  'views/users/index_by_company':mustache_template\n```\n\nOutputs:\n\n```javascript\nfunction anonymous(n,i) {\nvar o='',w=function(f,a){o='';f.apply(i, a);return o},t={}\nt[\"views/users/index\"]=function(){return w(each,[this.company,function(name,data){o+=\"<h2>\"+name+\"</h2><ul>\"+w(each,[data.people,function(){o+=\"<li>\"+this+\"</li>\"}])+\"</ul>\"}])}\nt[\"views/users/index_by_company\"]=function(){return w(each,[this.company,function(name,data){o+=\"<h2>\"+name+\"</h2><ul>\"+w(each,[data.people,function(){o+=\"<li>\"+this+\"</li>\"}])+\"</ul>\"}])}\nreturn t[n].call(i)\n}\n```\n\nFrom here you would normally save the function in a file like `static/public/assets/templates.js`.\n\n## Further examples\n\nAs usual, for the latest examples, review the easy-to-follow [./test/test.coffee](https://github.com/mikesmullin/coffee-templates/blob/stable/test/test.coffee).\n\nOr try it immediately in your browser with [codepen](http://codepen.io/mikesmullin/pen/nIytw).\n\n\n## Useful Tools\n\n* [Haml to HTML to CoffeeCup to JavaScript to CoffeeScript Converter](http://haml-html-coffeecup-javascript-coffeescript-converter.smullindesign.com/)\n","_id":"coffee-templates@0.0.5","dist":{"shasum":"eb89ea8243542c00bdfc76e36993f353b10c6eed","tarball":"https://registry.npmjs.org/coffee-templates/-/coffee-templates-0.0.5.tgz","integrity":"sha512-wj/kuIkJymuypr79LNTyKxvEyBB1P+dYyYZJtuiIvkhrVeyX5eEP2po9aQ+xGMo3Rp2yCd5iwJ40RsQWBXSSog==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIC8BRH72o0wZkFreH9jvM/J8JdKgdRUdDl/UGqzoaQwMAiBiYAITMgFMMnv32raijZuO+Y0DPm/iyNP16/t43Tb4hA=="}]},"_npmVersion":"1.1.66","_npmUser":{"name":"mikesmullin","email":"mike@smullindesign.com"},"maintainers":[{"name":"mikesmullin","email":"mike@smullindesign.com"}]},"0.0.6":{"name":"coffee-templates","version":"0.0.6","description":"Fastest Minimalist CoffeeScript/JavaScript CoffeeCup/Handlebars/Mustache template engine.","main":"js/coffee-templates.js","directories":{"test":"test"},"scripts":{"pretest":"coffee --bare -o js coffee/coffee-templates.coffee","test":"mocha --reporter spec --bail --ui bdd --colors --compilers coffee:coffee-script --require coffee-script test/test.coffee"},"repository":{"type":"git","url":"git://github.com/mikesmullin/coffee-templates.git"},"keywords":["html","html5","markup","template","coffeecup","mustache","handlebars","noengine","fast","fastest","browser","nodejs","engine"],"author":{"name":"Mike Smullin","email":"mike@smullindesign.com"},"license":"MIT","readmeFilename":"README.md","devDependencies":{"chai":"*"},"readme":"# Why CoffeeTemplates?\n\n * 89% smaller download than [CoffeeCup](https://github.com/gradus/coffeecup) + [Handlebars](http://handlebarsjs.com/)--but compiles BOTH with just [257 lines](https://github.com/mikesmullin/coffee-templates/blob/stable/js/coffee-templates.js).\n * thats just [8.7KB](https://raw.github.com/mikesmullin/coffee-templates/stable/js/coffee-templates.js), [5.6KB minified](https://raw.github.com/mikesmullin/coffee-templates/stable/js/coffee-templates.min.js), and [2.6KB gzipped](https://raw.github.com/mikesmullin/coffee-templates/stable/js/coffee-templates.min.js.gz)\n * renders between [22%](http://jsperf.com/coffeecup-vs-coffee-templates/4) to [80% faster](http://jsperf.com/handlebars-vs-coffee-templates/3) as tested on node/chrome/v8\n * stand-alone client-side in browser or server-side with Node.js with NO [dependencies](https://github.com/mikesmullin/coffee-templates/blob/stable/package.json)\n * compiling to .js yields one-function-per-template which renders using ONLY string concatenation--the secret to its speed\n * when compiled to .js, no ancillary \"engine\" library is required to render the template functions. nor is one embedded within the functions.\n * compiling directly from `.coffee` to `.html` or aggregated `templates.js` eliminates a lot of inbetween middleware\n * this means delays, complexities, and potential for double-trees between client and server-side templating engines are eliminated\n * only one language to write; one language to teach/master; one language to rule them all!\n * common functions available to node/js/coffee also available in templates i.e. require() and executed in same scope\n\nInspired by [coffeecup](https://github.com/gradus/coffeecup),\n and [ck](https://github.com/aeosynth/ck),\n and [mini-handlebars](https://github.com/mikesmullin/mini-handlebars) libraries.\n\n## And now, a Haiku\n\n    5  template languages\n    7  are low-level logical\n    5  function recursions\n    7  the author dared not express\n    5  in the host language.\n    \n    5  syntactic sugar\n    7  on low-level languages\n    5  ala coffeescript\n    7  brings template control to the\n    5  speed where it belongs.\n\n## Rendering Coffee to HTML\n\n```coffeescript\n# this line is only required within node\nCoffeeTemplates = require 'coffee-templates'\n\n# initialize new engine\nengine = new CoffeeTemplates format: true\n\n# provide template expression\ndoctype 5\nhtml ->\n  head ->\n    meta charset: 'utf-8'\n    title \"#{@title or 'Untitled'} | A completely plausible website\"\n    meta(name: 'description', content: @description) if @description?\n\n    link rel: 'stylesheet', href: '/css/app.css'\n\n    style '''\n      body {font-family: sans-serif}\n      header, nav, section, footer {display: block}\n    '''\n\n    comment 'Stylus is not supported but CoffeeStyleshets might be'\n\n    script src: '/js/jquery.js'\n\n    coffeescript ->\n      $(document).ready ->\n        alert 'Alerts suck!'\n  body ->\n    header ->\n      h1 @title or 'Untitled'\n\n      nav ->\n        ul ->\n          (li -> a href: '/', -> 'Home') unless @path is '/'\n          li -> a href: '/chunky', -> 'Bacon!'\n          switch @user.role\n            when 'owner', 'admin'\n              li -> a href: '/admin', -> 'Secret Stuff'\n            when 'vip'\n              li -> a href: '/vip', -> 'Exclusive Stuff'\n            else\n              li -> a href: '/commoners', -> 'Just Stuff'\n\n    div '#myid.myclass.anotherclass', style: 'position: fixed', ->\n      p 'Divitis kills! Inline styling too.'\n\n    section ->\n      # A helper function you built and included.\n      breadcrumb separator: '>', clickable: yes\n\n      h2 \"Let's count to 10:\"\n      p i for i in [1..10]\n\n      # Another hypothetical helper.\n      form_to @post, ->\n        textbox '#title', label: 'Title:'\n        textbox '#author', label: 'Author:'\n        submit 'Save'\n\n    footer ->\n      # CoffeeScript comments. Not visible in the output document.\n      comment 'HTML comments.'\n      p 'Bye!'\n\n\nlocals =\n  title: 'Best website'\n\n# render coffee template to html\nconsole.log engine.render template, locals\n```\n\n## Rendering Coffee to Handlebars\n```coffeescript\nengine = new CoffeeTemplates format: true, handlebars: true\n\ntemplate = ->\n  ul ->\n    for company in @companies\n      block \"each #{company}\", ->\n        li '{{this}}'\n\nconsole.log handlebars_template = engine.render template,\n  companies: [ 'google', 'yahoo' ]\n```\n\nOutputs:\n\n```html\n<ul>\n  {{#each google}}\n    <li>{{this}}</li>\n  {{/each}}\n  {{#each yahoo}}\n    <li>{{this}}</li>\n  {{/each}}\n</ul>\n```\n\n## Improving Handlebars/Mustache\nNotice that while regular Mustache/Handlebars templates still compile,\nwe took the liberty to engineer several improvements to the compiler:\n\n * {{#blocks arg...}}{{/blocks}} can also be written as {{blocks arg...}}{{/blocks}}\n * however, blocks are required to take at least one argument\n * blocks are just javascript functions\n * any function that implements `function(arg..., cb) { cb(arg...) }` can be executed by a block\n * a function need only be in the window/root scope to be used as a helper; no need to define iterators specially\n * blocks can take any number of arguments\n * blocks can also list callback function arguments within parenthesis ()\n * any character that is valid in a function or variable name is a valid block or block argument name\n * therefore, `<ul>{{$.each companies}}<li>{{this}}</li>{{/$.each}}</ul>` is valid\n * and so is, `<ul>{{jQuery.each people, (key, value)}}<li>{{key}}: {{value}}</li>{{/each}}</ul>`\n\n```coffeescript\nengine = new CoffeeTemplates format: true\n\nconsole.log mustache_template = engine.render ->\n  block \"each company, (name, data)\", ->\n    h2 '{{name}}'\n    ul ->\n      block \"each data.people\", ->\n        li '{{this}}'\n```\n\nOutputs:\n\n```html\n{{each company, (name, data)}}\n  <h2>{{name}}</h2>\n  <ul>\n    {{each data.people}}\n      <li>{{this}}</li>\n    {{/each}}\n  </ul>\n{{/each}}\n```\n\n## Rendering Coffee/Handlebars/Mustache to a NoEngine JS Function\n```coffeescript\nmustache_template = '{{each company, (name, data)}}<h2>{{name}}</h2><ul>{{each data.people}}<li>{{this}}</li>{{/each}}</ul>{{/each}}'\n\nconsole.log template_fn = CoffeeTemplates.compile mustache_template\n```\n\nOutputs:\n\n```javascript\nfunction anonymous(i) {\nvar o='',w=function(f,a){o='';f.apply(i, a);return o};return w(each,[i.company,function(name,data){o+=\"<h2>\"+name+\"</h2><ul>\"+w(each,[data.people,function(){o+=\"<li>\"+this+\"</li>\"}])+\"</ul>\"}])\n}\n```\n\nThis single function is a completely stand-alone version of your template, and is all that is needed to render the HTML.\n\nOf course, this could also be used to render XML or some other markup, as well.\n\n## Rendering a NoEngine JS Function to HTML\n```coffeescript\nwindow.each = (o, cb) ->\n  for k of o\n    cb.apply o[k], [k, o[k]]\n  return\n\nconsole.log html = template_fn company:\n  goog: people: ['Larry Page', 'Sergey Brin']\n  msft: people: ['Bill Gates']\n```\n\nOutputs:\n\n```html\n<h2>goog</h2><ul><li>Larry Page</li><li>Sergey Brin</li></ul><h2>msft</h2><ul><li>Bill Gates</li></ul>\n```\n\n## Rendering multiple templates to function\n```coffeescript\nconsole.log templates = ''+CoffeeTemplates.compileAll\n  'views/users/index': mustache_template\n  'views/users/index_by_company':mustache_template\n```\n\nOutputs:\n\n```javascript\nfunction anonymous(n,i) {\nvar o='',w=function(f,a){o='';f.apply(i, a);return o},t={}\nt[\"views/users/index\"]=function(){return w(each,[this.company,function(name,data){o+=\"<h2>\"+name+\"</h2><ul>\"+w(each,[data.people,function(){o+=\"<li>\"+this+\"</li>\"}])+\"</ul>\"}])}\nt[\"views/users/index_by_company\"]=function(){return w(each,[this.company,function(name,data){o+=\"<h2>\"+name+\"</h2><ul>\"+w(each,[data.people,function(){o+=\"<li>\"+this+\"</li>\"}])+\"</ul>\"}])}\nreturn t[n].call(i)\n}\n```\n\nFrom here you would normally save the function in a file like `static/public/assets/templates.js`.\n\n## Further examples\n\nAs usual, for the latest examples, review the easy-to-follow [./test/test.coffee](https://github.com/mikesmullin/coffee-templates/blob/stable/test/test.coffee).\n\nOr try it immediately in your browser with [codepen](http://codepen.io/mikesmullin/pen/nIytw).\n\n\n## Useful Tools\n\n* [Haml to HTML to CoffeeCup to JavaScript to CoffeeScript Converter](http://haml-html-coffeecup-javascript-coffeescript-converter.smullindesign.com/)\n","_id":"coffee-templates@0.0.6","dist":{"shasum":"f4685273c7bbc840c5747fa16fb8bc93534d5333","tarball":"https://registry.npmjs.org/coffee-templates/-/coffee-templates-0.0.6.tgz","integrity":"sha512-jaHDHCdYx8VnJ0ocWATC+HSxWKYpGzfWtd8hxFwASrjim4vgajPaRgq+itSPbdNJrBMWZ3C/iM9Q3QVOYT02vQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQD1y2GcT9ozeRS+XNeap8MkDzBDsrcGXurlbGEwOXKuFgIgO/kD+rlCOut9RWBVKg9I6rQisjT9dNwWnxqoV290jz0="}]},"_npmVersion":"1.1.69","_npmUser":{"name":"mikesmullin","email":"mike@smullindesign.com"},"maintainers":[{"name":"mikesmullin","email":"mike@smullindesign.com"}]}},"readme":"# Why CoffeeTemplates?\n\n * 89.5% smaller download than [CoffeeCup](https://github.com/gradus/coffeecup) + [Handlebars](http://handlebarsjs.com/)--but compiles BOTH with just [226 lines](https://github.com/mikesmullin/coffee-templates/blob/production/js/coffee-templates.js).\n * thats just [6.9KB](https://raw.github.com/mikesmullin/coffee-templates/production/js/coffee-templates.js), [4.2KB minified](https://raw.github.com/mikesmullin/coffee-templates/production/js/coffee-templates.min.js), and [2.1KB gzipped](https://raw.github.com/mikesmullin/coffee-templates/production/js/coffee-templates.min.js.gz)\n * renders between [22%](http://jsperf.com/coffeecup-vs-coffee-templates) to [80% faster](http://jsperf.com/handlebars-vs-coffee-templates)\n * stand-alone client-side in browser or server-side with Node.js with NO [dependencies](https://github.com/mikesmullin/coffee-templates/blob/production/package.json)\n * compiling to .js yields one-function-per-template which renders using ONLY string concatenation--the secret to its speed\n * when compiled to .js, no ancillary \"engine\" library is required to render the template functions. nor is one embedded within the functions.\n * compiling directly from `.coffee` to `.html` or aggregated `templates.js` eliminates a lot of inbetween middleware\n * this means delays, complexities, and potential for double-trees between client and server-side templating engines are eliminated\n * only one language to write; one language to teach/master; one language to rule them all!\n * common functions available to node/js/coffee also available in templates i.e. require() and executed in same scope\n\nInspired by [coffeecup](https://github.com/gradus/coffeecup),\n and [ck](https://github.com/aeosynth/ck),\n and [mini-handlebars](https://github.com/mikesmullin/mini-handlebars) libraries.\n\n\n## Rendering Coffee to HTML\n\n```coffeescript\n# this line is only required within node\nCoffeeTemplates = require 'coffee-templates'\n\n# initialize new engine\nengine = new CoffeeTemplates format: true\n\n# provide template expression\ndoctype 5\nhtml ->\n  head ->\n    meta charset: 'utf-8'\n    title \"#{@title or 'Untitled'} | A completely plausible website\"\n    meta(name: 'description', content: @description) if @description?\n\n    link rel: 'stylesheet', href: '/css/app.css'\n\n    style '''\n      body {font-family: sans-serif}\n      header, nav, section, footer {display: block}\n    '''\n\n    comment 'Stylus is supported as well'\n\n    stylus '''\n      body\n        margin: 0\n    '''\n\n    script src: '/js/jquery.js'\n\n    coffeescript ->\n      $(document).ready ->\n        alert 'Alerts suck!'\n  body ->\n    header ->\n      h1 @title or 'Untitled'\n\n      nav ->\n        ul ->\n          (li -> a href: '/', -> 'Home') unless @path is '/'\n          li -> a href: '/chunky', -> 'Bacon!'\n          switch @user.role\n            when 'owner', 'admin'\n              li -> a href: '/admin', -> 'Secret Stuff'\n            when 'vip'\n              li -> a href: '/vip', -> 'Exclusive Stuff'\n            else\n              li -> a href: '/commoners', -> 'Just Stuff'\n\n    div '#myid.myclass.anotherclass', style: 'position: fixed', ->\n      p 'Divitis kills! Inline styling too.'\n\n    section ->\n      # A helper function you built and included.\n      breadcrumb separator: '>', clickable: yes\n\n      h2 \"Let's count to 10:\"\n      p i for i in [1..10]\n\n      # Another hypothetical helper.\n      form_to @post, ->\n        textbox '#title', label: 'Title:'\n        textbox '#author', label: 'Author:'\n        submit 'Save'\n\n    footer ->\n      # CoffeeScript comments. Not visible in the output document.\n      comment 'HTML comments.'\n      p 'Bye!'\n\n\nlocals =\n  title: 'Best website'\n\n# render coffee template to html\nconsole.log engine.render template, locals\n```\n\n## Rendering Coffee to Handlebars\n```coffeescript\nengine = new CoffeeTemplates format: true, handlebars: true\n\ntemplate = ->\n  ul ->\n    for company in @companies\n      block \"each #{company}\", ->\n        li '{{this}}'\n\nconsole.log handlebars_template = engine.render template,\n  companies: [ 'google', 'yahoo' ]\n```\n\nOutputs:\n\n```html\n<ul>\n  {{#each google}}\n    <li>{{this}}</li>\n  {{/each}}\n  {{#each yahoo}}\n    <li>{{this}}</li>\n  {{/each}}\n</ul>\n```\n\n## Improving Handlebars/Mustache\nNotice that while regular Mustache/Handlebars templates still compile,\nwe took the liberty to engineer several improvements to the compiler:\n\n * {{#blocks arg...}}{{/blocks}} can also be written as {{blocks arg...}}{{/blocks}}\n * however, blocks are required to take at least one argument\n * blocks are just javascript functions\n * any function that implements `function(arg..., cb) { cb(arg...) }` can be executed by a block\n * a function need only be in the window/root scope to be used as a helper; no need to define iterators specially\n * blocks can take any number of arguments\n * blocks can also list callback function arguments within parenthesis ()\n * any character that is valid in a function or variable name is a valid block or block argument name\n * therefore, `<ul>{{$.each companies}}<li>{{this}}</li>{{/$.each}}</ul>` is valid\n * and so is, `<ul>{{jQuery.each people, (key, value)}}<li>{{key}}: {{value}}</li>{{/each}}</ul>`\n\n```coffeescript\nengine = new CoffeeTemplates format: true\n\nconsole.log mustache_template = engine.render ->\n  block \"each company, (name, data)\", ->\n    h2 '{{name}}'\n    ul ->\n      block \"each data.people\", ->\n        li '{{this}}'\n```\n\nOutputs:\n\n```html\n{{each company, (name, data)}}\n  <h2>{{name}}</h2>\n  <ul>\n    {{each data.people}}\n      <li>{{this}}</li>\n    {{/each}}\n  </ul>\n{{/each}}\n```\n\n## Rendering Coffee/Handlebars/Mustache a NoEngine JS Function\n```coffeescript\nmustache_template = '{{each company, (name, data)}}<h2>{{name}}</h2><ul>{{each data.people}}<li>{{this}}</li>{{/each}}</ul>{{/each}}'\n\nconsole.log template_fn = CoffeeTemplates.compile mustache_template\n```\n\nOutputs:\n\n```javascript\nfunction anonymous(i) {\nvar o='',w=function(f,a) {o='';f.apply(i, a);return o};return w(each,[i.company,function(name,data){o+=\"<h2>\"+name+\"</h2><ul>\"+w(each,[data.people,function(){o+=\"<li>\"+this+\"</li>\"}])+\"</ul>\"}])\n}\n```\n\nThis single function is a completely stand-alone version of your template, and is all that is needed to render the HTML.\n\nOf course, this could also be used to render XML or some other markup, as well.\n\n## Rendering a NoEngine JS Function to HTML\n```coffeescript\nwindow.each = (o, cb) ->\n  for k of o\n    cb.apply o[k], [k, o[k]]\n  return\n\nconsole.log html = template_fn company:\n  goog: people: ['Larry Page', 'Sergey Brin']\n  msft: people: ['Bill Gates']\n```\n\nOutputs:\n\n```html\n<h2>goog</h2><ul><li>Larry Page</li><li>Sergey Brin</li></ul><h2>msft</h2><ul><li>Bill Gates</li></ul>\n```\n\n## Rendering multiple templates to function\n```coffeescript\nconsole.log templates = CoffeeTemplates.compileAll\n  'views/users/index': (CoffeeTemplates.compile mustache_template, false)\n  'views/users/index_by_company': (CoffeeTemplates.compile mustache_template, false)\n```\n\nOutputs:\n\n```javascript\nfunction anonymous(n,i) {\nvar o='',w=function(f,a) {o='';f.apply(i, a);return o},t={}\nt[\"views/users/index\"]=function(){return w(each,[this.company,function(name,data){o+=\"<h2>\"+name+\"</h2><ul>\"+w(each,[data.people,function(){o+=\"<li>\"+this+\"</li>\"}])+\"</ul>\"}])}\nt[\"views/users/index_by_company\"]=function(){return w(each,[this.company,function(name,data){o+=\"<h2>\"+name+\"</h2><ul>\"+w(each,[data.people,function(){o+=\"<li>\"+this+\"</li>\"}])+\"</ul>\"}])}\nreturn t[n].call(i)\n}\n```\n\nFrom here you would normally save the function in a file like `static/public/assets/templates.js`.\n\n## Further examples\n\nAs usual, for the latest examples, review the easy-to-follow [./test/test.coffee](https://github.com/mikesmullin/coffee-templates/blob/production/test/test.coffee).\n\nOr try it immediately in your browser with [codepen](http://codepen.io/mikesmullin/pen/nIytw).\n\n\n## Useful Tools\n\n* [Haml to HTML to CoffeeCup to JavaScript to CoffeeScript Converter](http://haml-html-coffeecup-javascript-coffeescript-converter.smullindesign.com/)\n","maintainers":[{"name":"mikesmullin","email":"mike@smullindesign.com"}],"time":{"modified":"2022-06-13T06:27:57.357Z","created":"2012-12-21T02:22:06.247Z","0.0.2":"2012-12-21T02:22:06.861Z","0.0.3":"2012-12-27T03:41:19.184Z","0.0.4":"2013-01-04T06:07:13.038Z","0.0.5":"2013-01-04T23:04:39.582Z","0.0.6":"2013-01-13T04:45:09.276Z"},"author":{"name":"Mike Smullin","email":"mike@smullindesign.com"},"repository":{"type":"git","url":"git://github.com/mikesmullin/coffee-templates.git"},"users":{"tunnckocore":true}}