{"id":15363873,"url":"https://github.com/yanickrochon/koa-efficient","last_synced_at":"2025-08-30T17:39:07.302Z","repository":{"id":137997553,"uuid":"18073099","full_name":"yanickrochon/koa-efficient","owner":"yanickrochon","description":"co-efficient template engine middleware for Koa","archived":false,"fork":false,"pushed_at":"2016-01-13T16:28:49.000Z","size":19,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-29T19:21:23.621Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yanickrochon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-03-24T18:16:11.000Z","updated_at":"2016-01-13T16:28:50.000Z","dependencies_parsed_at":"2023-03-17T21:10:34.630Z","dependency_job_id":null,"html_url":"https://github.com/yanickrochon/koa-efficient","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/yanickrochon/koa-efficient","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yanickrochon%2Fkoa-efficient","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yanickrochon%2Fkoa-efficient/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yanickrochon%2Fkoa-efficient/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yanickrochon%2Fkoa-efficient/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yanickrochon","download_url":"https://codeload.github.com/yanickrochon/koa-efficient/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yanickrochon%2Fkoa-efficient/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272882928,"owners_count":25009334,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-30T02:00:09.474Z","response_time":77,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-01T13:08:50.097Z","updated_at":"2025-08-30T17:39:07.258Z","avatar_url":"https://github.com/yanickrochon.png","language":"JavaScript","readme":"# Koa Efficient\n\n[![Build Status](https://travis-ci.org/yanickrochon/koa-efficient.svg)](https://travis-ci.org/yanickrochon/koa-efficient)\n[![Coverage Status](https://coveralls.io/repos/yanickrochon/koa-efficient/badge.svg?branch=master\u0026service=github)](https://coveralls.io/github/yanickrochon/koa-efficient?branch=master)\n\n\n[`Efficient`](https://github.com/yanickrochon/efficient) template engine middleware for Koa\n\n\n# BREAKING CHANGE\n\nThis package now use a new template engine slightly incompatible with the previous one, but faster, more flexible and easy to use. This notice will remain up until February 2016. Open issues if you have any trouble upgrading.\n\nHere are notable changes :\n* Template syntax (i.e. context paths, segment types, no more helpers, etc.)\n* Engine configuration options\n* Context mapping keys and values have swapped now.\n\n\n## Features\n\n* Asynchronous templates with `efficient`.\n* Dual engines configuration (layouts + views)\n* Preset global data\n* Optional basic error handling in response\n\n\n## Install\n\n`npm install koa-efficient --save`\n\n\n## Example\n\n```js\nvar efficient = require('koa-efficient');\nvar koa = require('koa');\n\nvar app = koa();\napp.use(efficient({\n  layout: 'main',\n  layoutOptions: {\n    paths: {\n      '*': './layouts'\n    }\n  },\n  viewOptions: {\n    paths: {\n      '*': './layouts'\n    }\n  },\n\n  // expose passport's user to the views and layouts as 'identity'\n  contextMap: {\n    'passport.user': 'identity'\n  }\n}))\n```\n\n\n## Options\n\n* **data** *{Object}* : an object of global data passed to the template.\n* **layout** *{String}* : set the layout's name. Set to false to disable the layout.\n* **layoutOptions** *{Object}* : passed directly to `efficient` engine's layout instance. See [efficent](https://github.com/yanickrochon/efficient#configuration)'s configuration for more information.\n* **layoutEngine** *{coefficient.Engine}* : the coefficient template engine to use when rendering the layouts. When this is specified, **layoutOptions** are ignored.\n* **viewOptions** *{Object}* : passed directly to `efficient` engine's view instance. See [efficent](https://github.com/yanickrochon/efficient#configuration)'s configuration for more information.\n* **viewEngine** *{coefficient.Engine}* : the coefficient template engine to use when rendering the views. When this is specified, **viewOptions** are ignored.\n* **handleErrors** *{Boolean}* : optionally handle errors automatically and set the status and response body. *(default `false`)*\n* **httpHeaders** *{Object}* : define any HTTP headers to set *after* successful rendering. The object may specify getters for dynamic headers.\n* **contextMap** *{Object}* : if any request's context data needs to be exposed to the view, this will map the context (`this`) object's value to the data, overwritting any previous value.\n\n\n## Usage\n\n```js\napp.use(function (next) {\n  yield this.render('view-template', {\n    title: 'Hello world!'\n  }, 'other-layout');\n})\n```\n\nThe above snippet, given the configuration above, will render `./views/view-template.coeft.html`, using the layout `./layouts/other-layout.coeft.html`.\n\nTo disable the layout (render only the view), pass `false` as layout name.\n\n```js\napp.use(function (next) {\n  yield this.render('view-template', {\n    title: 'Hello world!'\n  }, false);\n})\n```\n\n\n## ContextMap\n\nWhen rendering a template and/or layout, instead of manually processing the current request's `this` context, mapping a `data` object to send to the rendering engines, `koa-efficient` can perform a automated transformation instead.\n\nFor example, you may transform\n\n```javascript\nvar efficient = require('koa-efficient');\n\napp.use(efficient({\n  ...\n}));\n\napp.use(function * () {\n  var data = {\n    username: this.passport.identifier,\n    cartItems: this.session.cartItems\n  };\n\n  this.render('foo', data);\n});\n```\n\ninto\n\n```javascript\nvar efficient = require('koa-efficient');\n\napp.use(efficient({\n  ...\n  contextMap: {\n    'username': 'passport.identifier',\n    'cartItems': 'session.cartItems'\n  }\n}));\n\napp.use(function * () {\n  this.render('foo');\n});\n```\n\n\n## License\n\nThe MIT License (MIT)\n\nCopyright (c) 2015 Mind2Soft \u003cyanick.rochon@mind2soft.com\u003e\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of\nthis software and associated documentation files (the \"Software\"), to deal in\nthe Software without restriction, including without limitation the rights to\nuse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\nthe Software, and to permit persons to whom the Software is furnished to do so,\nsubject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\nFOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\nCOPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\nIN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\nCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyanickrochon%2Fkoa-efficient","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyanickrochon%2Fkoa-efficient","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyanickrochon%2Fkoa-efficient/lists"}