{"_id":"@ladjs/koa-views","_rev":"1-75e0956a3112f6c1cc32ad31ff113e53","name":"@ladjs/koa-views","dist-tags":{"latest":"9.0.0"},"versions":{"8.1.0":{"name":"@ladjs/koa-views","description":"Template rendering middleware for koa","version":"8.1.0","author":{"name":"queckezz"},"bugs":{"url":"https://github.com/ladjs/koa-views/issues"},"dependencies":{"@ladjs/consolidate":"^1.0.1","debug":"^4.3.4","get-paths":"0.0.7","koa-send":"^5.0.1","mz":"^2.7.0","pretty":"^2.0.0","resolve-path":"^1.4.0"},"devDependencies":{"ejs":"^3.1.9","eslint":"^8.42.0","eslint-config-standard":"^17.1.0","eslint-plugin-import":"^2.27.5","eslint-plugin-n":"^16.0.0","eslint-plugin-node":"^11.1.0","eslint-plugin-promise":"^6.1.1","eslint-plugin-standard":"^4.1.0","handlebars":"^4.7.7","koa":"^2.14.2","mocha":"^10.2.0","nunjucks":"^3.2.4","pre-commit":"^1.2.2","pug":"^3.0.2","should":"^13.2.3","supertest":"^6.3.3","tap-spec":"^5.0.0","tape":"^5.6.3","underscore":"^1.13.6"},"keywords":["app-wide","koa","render","templates","templating","views"],"license":"MIT","main":"src/index.js","peerDependencies":{"@types/koa":"^2.13.1"},"peerDependenciesMeta":{"@types/koa":{"optional":true}},"precommit":"lint, test","publishConfig":{"access":"public"},"repository":{"type":"git","url":"git+https://github.com/ladjs/koa-views.git"},"scripts":{"lint":"eslint .","test":"mocha --reporter dot --bail --exit"},"types":"index.d.ts","gitHead":"3f9bd3302df76542a7fe8d02caa5c034f99093e6","homepage":"https://github.com/ladjs/koa-views#readme","_id":"@ladjs/koa-views@8.1.0","_nodeVersion":"18.15.0","_npmVersion":"9.5.0","dist":{"integrity":"sha512-3QNC9ClBWVZCzAZDHYD33Vtl11rsiAucV/2p8r/w8ITENJICZQWR45NTgRvL8jF2ADZfigidDuUR1eHthG6xrQ==","shasum":"e6f6ce9074f3619d6915cf6f86b5128e7340bde6","tarball":"https://registry.npmjs.org/@ladjs/koa-views/-/koa-views-8.1.0.tgz","fileCount":24,"unpackedSize":26448,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIEfn5iLt4Dcd6vLK2a4JgeXuwClO+fwauZCmjxq30kdaAiBoWHLDpWCRwzlFa7T9sqlt7XSItIyTj/w/wA1PT4dXyg=="}]},"_npmUser":{"name":"titanism","email":"npm@titanism.com"},"directories":{},"maintainers":[{"name":"titanism","email":"npm@titanism.com"},{"name":"shadowgate15","email":"taylorschley@me.com"},{"name":"niftylettuce","email":"niftylettuce@gmail.com"},{"name":"shaunwarman","email":"shaunwarman1@gmail.com"},{"name":"spence-s","email":"sasnyde2@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/koa-views_8.1.0_1686272546946_0.03474927066044842"},"_hasShrinkwrap":false},"9.0.0":{"name":"@ladjs/koa-views","description":"Template rendering middleware for koa","version":"9.0.0","author":{"name":"queckezz"},"bugs":{"url":"https://github.com/ladjs/koa-views/issues"},"dependencies":{"@ladjs/consolidate":"^1.0.1","debug":"^4.3.4","get-paths":"0.0.7","koa-send":"^5.0.1","mz":"^2.7.0","pretty":"^2.0.0","resolve-path":"^1.4.0"},"engines":{"node":">=14"},"devDependencies":{"ejs":"^3.1.9","eslint":"^8.42.0","eslint-config-standard":"^17.1.0","eslint-plugin-import":"^2.27.5","eslint-plugin-n":"^16.0.0","eslint-plugin-node":"^11.1.0","eslint-plugin-promise":"^6.1.1","eslint-plugin-standard":"^4.1.0","handlebars":"^4.7.7","koa":"^2.14.2","mocha":"^10.2.0","nunjucks":"^3.2.4","pre-commit":"^1.2.2","pug":"^3.0.2","should":"^13.2.3","supertest":"^6.3.3","tap-spec":"^5.0.0","tape":"^5.6.3","underscore":"^1.13.6"},"keywords":["app-wide","koa","render","templates","templating","views"],"license":"MIT","main":"src/index.js","peerDependencies":{"@types/koa":"^2.13.1"},"peerDependenciesMeta":{"@types/koa":{"optional":true}},"precommit":"lint, test","publishConfig":{"access":"public"},"repository":{"type":"git","url":"git+https://github.com/ladjs/koa-views.git"},"scripts":{"lint":"eslint .","test":"mocha --reporter dot --bail --exit"},"types":"index.d.ts","gitHead":"3518b16934b11a1b980cfaf9b1e3436276ce5995","homepage":"https://github.com/ladjs/koa-views#readme","_id":"@ladjs/koa-views@9.0.0","_nodeVersion":"18.15.0","_npmVersion":"9.5.0","dist":{"integrity":"sha512-/nzUN3HhB7SIxrE4c2MXCLARXMwgoy7xJogyX8lNJo4VBxM6dVQ47iZWjOoHxTBKGFNAv2OTQ0rWI7HYpiv8kg==","shasum":"22db62988e5040102da94b73133a7f97b381c02a","tarball":"https://registry.npmjs.org/@ladjs/koa-views/-/koa-views-9.0.0.tgz","fileCount":24,"unpackedSize":26487,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCZgOFCIHqPLq7d8cqW6PKDqSRXhfJLbojvRtDcnfZCtgIgazcOUuL6y0fqyfQhb3X7LvNDIjCaszQp1M78/XkgqHo="}]},"_npmUser":{"name":"titanism","email":"npm@titanism.com"},"directories":{},"maintainers":[{"name":"titanism","email":"npm@titanism.com"},{"name":"shadowgate15","email":"taylorschley@me.com"},{"name":"niftylettuce","email":"niftylettuce@gmail.com"},{"name":"shaunwarman","email":"shaunwarman1@gmail.com"},{"name":"spence-s","email":"sasnyde2@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/koa-views_9.0.0_1686272778238_0.7168828810386445"},"_hasShrinkwrap":false}},"time":{"created":"2023-06-09T01:02:26.879Z","8.1.0":"2023-06-09T01:02:27.141Z","modified":"2023-06-09T01:06:18.641Z","9.0.0":"2023-06-09T01:06:18.444Z"},"maintainers":[{"name":"titanism","email":"npm@titanism.com"},{"name":"shadowgate15","email":"taylorschley@me.com"},{"name":"niftylettuce","email":"niftylettuce@gmail.com"},{"name":"shaunwarman","email":"shaunwarman1@gmail.com"},{"name":"spence-s","email":"sasnyde2@gmail.com"}],"description":"Template rendering middleware for koa","homepage":"https://github.com/ladjs/koa-views#readme","keywords":["app-wide","koa","render","templates","templating","views"],"repository":{"type":"git","url":"git+https://github.com/ladjs/koa-views.git"},"author":{"name":"queckezz"},"bugs":{"url":"https://github.com/ladjs/koa-views/issues"},"license":"MIT","readme":"# @ladjs/koa-views\n\n![@ladjs/koa-views](https://img.shields.io/github/workflow/status/ladjs/koa-views/koa-views?logo=github&style=flat-square)\n[![NPM version][npm-image]][npm-url]\n[![NPM downloads][npm-downloads-image]][npm-url]\n[![Dependency Status][david-image]][david-url]\n[![License][license-image]][license-url]\n\nTemplate rendering middleware for `koa@2`.\n\n## Installation\n\n```sh\nnpm install @ladjs/koa-views\n```\n\n## Templating engines\n\n`@ladjs/koa-views` is using [@ladjs/consolidate](https://github.com/ladjs/consolidate) under the hood.\n\n[List of supported engines](https://github.com/ladjs/consolidate#engines)\n\n**NOTE**: you must still install the engines you wish to use, add them to your package.json dependencies.\n\n## Example\n\n```js\nvar views = require('@ladjs/koa-views');\n\nconst render = views(__dirname + '/views', {\n  map: {\n    html: 'underscore'\n  }\n})\n\n// Must be used before any router is used\napp.use(render)\n// OR Expand by app.context\n// No order restrictions\n// app.context.render = render()\n\napp.use(async function (ctx) {\n  ctx.state = {\n    session: this.session,\n    title: 'app'\n  };\n\n  await ctx.render('user', {\n    user: 'John'\n  });\n});\n```\n\nFor more examples you can take a look at the [tests](./test/index.js).\n\n## Simple middleware\n\nIf you need to simply render pages with locals, you can install `koa-views-render`:\n\n```sh\nnpm install koa-views-render\n```\n\nThen simply use it on your routes and its arguments will be passed to `ctx.render`.\n\n```js\nvar render = require('koa-views-render');\n\n// ...\n\napp.use(render('home', { title : 'Home Page' }));\n```\n\n## API\n\n#### `views(root, opts)`\n\n* `root`: Where your views are located. Must be an absolute path. All rendered views are relative to this path\n* `opts` (optional)\n\n* `opts.autoRender`: Whether to use `ctx.body` to receive the rendered template string. Defaults to `true`.\n\n```js\nconst render = views(__dirname, { autoRender: false, extension: 'pug' });\napp.use(render)\n// OR\n// app.context.render = render()\n\napp.use(async function (ctx) {\n  return await ctx.render('user.pug')\n})\n```\n\nvs.\n\n```js\nconst render = views(__dirname, { extension: 'pug' })\napp.use(render)\n// OR\n// app.context.render = render()\n\napp.use(async function (ctx) {\n  await ctx.render('user.pug')\n})\n```\n\n* `opts.extension`: Default extension for your views\n\nInstead of providing the full file extension you can omit it.\n```js\napp.use(async function (ctx) {\n  await ctx.render('user.pug')\n})\n```\n\nvs.\n\n```js\nconst render = views(__dirname, { extension: 'pug' })\napp.use(render)\n// OR\n// app.context.render = render()\n\napp.use(async function (ctx) {\n  await ctx.render('user')\n})\n```\n\n* `opts.map`: Map a file extension to an engine\n\nIn this example, each file ending with `.html` will get rendered using the `nunjucks` templating engine.\n```js\nconst render = views(__dirname, { map: {html: 'nunjucks' }})\napp.use(render)\n// OR\n// app.context.render = render()\n// render `user.html` with nunjucks\napp.use(async function (ctx) {\n  await ctx.render('user.html')\n})\n```\n\n* `opts.engineSource`: replace `@ladjs/consolidate` as default engine source\n\nIf you’re not happy with `@ladjs/consolidate` or want more control over the engines, you can override it with this options. `engineSource` should\nbe an object that maps an extension to a function that receives a path and options and returns a promise. In this example templates with the `foo` extension will always return `bar`.\n\n```js\nconst render = views(__dirname, { engineSource: {foo: () => Promise.resolve('bar')}})\napp.use(render)\n// OR\n// app.context.render = render()\n\napp.use(async function (ctx) {\n  await ctx.render('index.foo')\n})\n```\n\n* `opts.options`: These options will get passed to the view engine. This is the time to add `partials` and `helpers` etc.\n\n```js\nconst app = new Koa()\n  .use(views(__dirname, {\n    map: { hbs: 'handlebars' },\n    options: {\n      helpers: {\n        uppercase: (str) => str.toUpperCase()\n      },\n\n      partials: {\n        subTitle: './my-partial' // requires ./my-partial.hbs\n      },\n      \n      cache: true // cache the template string or not\n    }\n  }))\n  .use(function (ctx) {\n    ctx.state = { title: 'my title', author: 'queckezz' }\n    return ctx.render('./my-view.hbs')\n  })\n```\n\n## Debug\n\nSet the `DEBUG` environment variable to `@ladjs/koa-views` when starting your server.\n\n```bash\n$ DEBUG=@ladjs/koa-views\n```\n\n## License\n\n[MIT](./license)\n\n[npm-image]: https://img.shields.io/npm/v/@ladjs/koa-views.svg?style=flat-square\n[npm-downloads-image]: https://img.shields.io/npm/dm/@ladjs/koa-views.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/@ladjs/koa-views\n[david-image]: http://img.shields.io/david/ladjs/koa-views.svg?style=flat-square\n[david-url]: https://david-dm.org/@ladjs/koa-views\n[license-image]: http://img.shields.io/npm/l/koa-views.svg?style=flat-square\n[license-url]: ./license\n","readmeFilename":"README.md"}