{
  "author": {
    "name": "Tom Carden",
    "email": "tom@tom-carden.co.uk"
  },
  "contributors": [
    {
      "name": "Robert Sköld",
      "email": "robert@publicclass.se",
      "url": "http://publicclass.se"
    }
  ],
  "name": "ejs-locals",
  "description": "Express 3.x locals for layout, partial and blocks.",
  "version": "1.0.2",
  "repository": {
    "type": "git",
    "url": "git://github.com/randometc/ejs-locals.git"
  },
  "homepage": "https://github.com/randometc/ejs-locals",
  "engines": {
    "node": ">=0.6.0"
  },
  "dependencies": {
    "ejs": "0.8.x"
  },
  "devDependencies": {
    "express": "~3.0.0",
    "mocha": "*",
    "should": "*",
    "methods": "0.0.1"
  },
  "scripts": {
    "test": "mocha -r should -R spec"
  },
  "readme": "# ejs-locals\n\nExpress 3.x `layout`, `partial` and `block` template functions for the EJS template engine. \n\nPreviously also offered `include` but you should use EJS 0.8.x's own method for that now.\n\n## Installation\n\n    $ npm install ejs-locals --save\n\n(`--save` automatically writes to your `package.json` file, tell your friends)\n\n\n## Usage\n\nRun `node app.js` from `examples` and open `localhost:3000` to see a working example.\n\nGiven a template, `index.ejs`:\n\n    <% layout('boilerplate') -%>\n    <% script('foo.js') -%>\n    <% stylesheet('foo.css') -%>\n    <h1>I am the <%=what%> template</h1>\n    <% block('header', \"<p>I'm in the header.</p>\") -%>\n    <% block('footer', \"<p>I'm in the footer.</p>\") -%>\n\nAnd a layout, `boilerplate.ejs`:\n\n    <!DOCTYPE html>\n    <html>\n      <head>\n        <title>It's <%=who%></title>\n        <%-scripts%>\n        <%-stylesheets%>\n      </head>\n      <body>\n        <header>\n          <%-blocks.header%>\n        </header>\n        <section>\n          <%-body -%>\n        </section>\n        <footer>\n          <%-blocks.footer%>\n        </footer>\n      </body>\n    </html>\n\nWhen rendered by an Express 3.0 app:\n\n    var express = require('express')\n      , engine = require('ejs-locals')\n      , app = express();\n\n    // use ejs-locals for all ejs templates:\n    app.engine('ejs', engine);\n\n    app.set('views',__dirname + '/views');\n    app.set('view engine', 'ejs'); // so you can render('index')\n\n    // render 'index' into 'boilerplate':\n    app.get('/',function(req,res,next){\n      res.render('index', { what: 'best', who: 'me' });\n    });\n\n    app.listen(3000);\n\nYou get the following result:\n\n    <!DOCTYPE html>\n    <html>\n      <head>\n        <title>It's me</title>\n        <script src=\"foo.js\"></script>\n        <link rel=\"stylesheet\" href=\"foo.css\" />\n      </head>\n      <body>\n        <header>\n          <p>I'm in the header.</p>\n        </header>\n        <section>\n          <h1>I am the best template</h1>\n        </section>\n        <footer>\n          <p>I'm in the footer.</p>\n        </footer>\n      </body>\n    </html>\n\nNote, if you haven't seen it before, this example uses trailing dashes in the EJS includes to slurp trailing whitespace and generate cleaner HTML. It's not strictly necessary.\n\n\n## Features\n\n### `layout(view)`\n\nWhen called anywhere inside a template, requests that the output of the current template be passed to the given view as the `body` local. Use this to specify layouts from within your template, which is recommended with Express 3.0, since the app-level layout functionality has been removed.\n\n### `partial(name,optionsOrCollection)`\n\nWhen called anywhere inside a template, adds the given view to that template using the current given `optionsOrCollection`. The usual way to use this is to pass an Array as the collection argument. The given view is then executed for each item in the Array; the item is passed into the view as a local with a name generated from the view's filename.\n\nFor example, if you do `<%-partial('thing',things)%>` then each item in the `things` Array is passed to `thing.ejs` with the name `thing`. If you rename the template, the local name of each item will correspond to the template name.\n\n### `block(name,html)`\n\nWhen called anywhere inside a template, adds the given html to the named block. In the layout you can then do `<%-block('foo')%> to render all the html for that block.\n\nSince this relies on javascript strings, and bypasses EJS's default escaping, you should be very careful if you use this function with user-submitted data.\n\n### `script(src,type)`\n\nA convenience function for `block('scripts', '<script src=\"src.js\"></script>')` with optional type. When called anywhere inside a template, adds a script tag with the given src/type to the scripts block. In the layout you can then do `<%-scripts%> to output the scripts from all the child templates.\n\n### `stylesheet(href,media)`\n\nA convenience function for `block('stylesheets', '<link rel=\"stylesheet\" href=\"href.css\" />')` with optional media type. When called anywhere inside a template, adds a link tag for the stylesheet with the given href/media to the stylesheets block. In the layout you can then do `<%-stylesheets%> to output the links from all the child templates.\n\n\n## Template Support\n\n  - `ejs` (actually hard coded right now, but feel free to __fork and help!__)\n\n\n## TODO\n\n - More Tests!\n - More templates.\n - Better, safer (autoescaped) syntax for longer blocks\n\n\n## Running Tests\n\nTo run the test suite first invoke the following command within the repo, installing the development dependencies:\n\n    $ npm install -d\n\nthen run the tests:\n\n    $ npm test\n\n\n## Backwards Compatibility\n\nExpress 2.0 had similar functionality built in, using `{ layout: 'view' }` as an argument to  `res.render` but this has been removed in Express 3.0. If you want the old behavior you should do:\n\n    app.locals({\n      _layoutFile: true\n    })\n\n\nAnd/or pass `_layoutFile: true` in the options when you call `res.render(...)`.\n\n## Whither Include?\n\nPrevious versions of this library had an `include` function. This is now supported directly by EJS, albeit with a different syntax. For `ejs-locals` 1.0+ simply do:\n\n### `<% include path/view %>`\n\nWhen called anywhere inside a template, this adds the given view to that template using the current options and locals. This is built-in to [EJS](https://github.com/visionmedia/ejs) 0.8+.\n\n## Credits\n\nThis library is a fork from Robert Sk&ouml;ld's [express-partials](https://github.com/publicclass/express-partials), and the partial function remains relatively untouched from there (aside from cache support). Robert is still updating his library and it now supports other template engines - check it out!\n\nThe blocks idea and syntax comes from Aseem Kishore's [express-blocks](https://github.com/aseemk/express-blocks)\n\n\n## License\n\n(The MIT License)\n\nCopyright (c) 2012 Robert Sk&ouml;ld &lt;robert@publicclass.se&gt;\nCopyright (c) 2012 Tom Carden &lt;tom@tom-carden.co.uk&gt;\n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n'Software'), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\nIN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\nCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\nTORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\nSOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n",
  "readmeFilename": "README.md",
  "bugs": {
    "url": "https://github.com/randometc/ejs-locals/issues"
  },
  "_id": "ejs-locals@1.0.2",
  "dist": {
    "shasum": "1812fe6e32dccf13704ea57daceb1fc7a80a01ef"
  },
  "_from": "ejs-locals@",
  "_resolved": "https://registry.npmjs.org/ejs-locals/-/ejs-locals-1.0.2.tgz"
}
