{"id":13799040,"url":"https://github.com/nswbmw/co-ejs","last_synced_at":"2025-10-29T05:31:28.875Z","repository":{"id":26292423,"uuid":"29740168","full_name":"nswbmw/co-ejs","owner":"nswbmw","description":"Koa ejs view render middleware.","archived":false,"fork":false,"pushed_at":"2018-07-15T11:21:54.000Z","size":23,"stargazers_count":8,"open_issues_count":2,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-09-29T05:22:46.251Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/nswbmw.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":"2015-01-23T15:59:35.000Z","updated_at":"2018-07-15T11:21:56.000Z","dependencies_parsed_at":"2022-07-21T08:32:21.128Z","dependency_job_id":null,"html_url":"https://github.com/nswbmw/co-ejs","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nswbmw%2Fco-ejs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nswbmw%2Fco-ejs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nswbmw%2Fco-ejs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nswbmw%2Fco-ejs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nswbmw","download_url":"https://codeload.github.com/nswbmw/co-ejs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219858317,"owners_count":16556047,"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","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-08-04T00:00:58.139Z","updated_at":"2025-10-29T05:31:28.557Z","avatar_url":"https://github.com/nswbmw.png","language":"JavaScript","funding_links":[],"categories":["仓库"],"sub_categories":["中间件"],"readme":"## co-ejs\n\nKoa ejs view render middleware.\n\n### Install\n\n    npm i co-ejs --save\n\n### Example\n\n```\nvar path = require('path');\n\nvar koa = require('koa');\nvar wait = require('co-wait');\nvar render = require('..');\n\nvar app = koa();\n\nvar locals = {\n  version: '1.0.0',\n  now: function () {\n    return new Date();\n  },\n  ip: function *() {\n    yield wait(1000);\n    return this.ip || '\u003cp\u003e127.0.0.1\u003c/p\u003e';\n  },\n  callback: function() {\n    return function (cb) {\n      cb(null, '\u003cp\u003ecallback\u003c/p\u003e');\n    }\n  },\n  callbackGen: function() {\n    return function* () {\n      yield wait(3000);\n      return '\u003cp\u003ecallbackGen\u003c/p\u003e';\n    };\n  },\n  doNothing: function() {\n    console.log('this will not print');\n  }\n};\n\nvar filters = {\n  format: function (time) {\n    return time.getFullYear() + '-' + (time.getMonth() + 1) + '-' + time.getDate();\n  }\n};\n\napp.use(render(app, {\n  root: path.join(__dirname, 'views'),\n  layout: 'layout',\n  viewExt: 'html',\n  cache: true,\n  debug: true,\n  locals: locals,\n  filters: filters\n}));\n\napp.use(function *() {\n  console.time('time');\n  yield this.render('content', {\n    users: [{name: 'John'}, {name: 'Jack'}, {name: 'Tom'}]\n  });\n  console.timeEnd('time');\n});\n\napp.listen(3000, function () {\n  console.log('listening on 3000.');\n});\n```\nOr you can checkout the example.\n\n### settings\n\n* root: view root directory.\n* layout: global layout file, default is `layout`, set `false` to disable layout.\n* viewExt: view file extension (default `html`).\n* cache: cache compiled templates (default `true`).\n* debug: debug flag (default `false`).\n* locals: global locals, can be function type, `this` in the function is koa's ctx.\n* filters: ejs custom filters.\n* open: open sequence (default `\u003c%`).\n* close: close sequence (default `%\u003e`).\n\n### $this\n\nAfter version `1.4.0`, you could use `$this` in ejs template, like: `\u003c%= $this.path %\u003e`.\n\n### Others\n\nsee [ejs](https://github.com/tj/ejs)\n\n### License\n\nMIT","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnswbmw%2Fco-ejs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnswbmw%2Fco-ejs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnswbmw%2Fco-ejs/lists"}