{"id":15138770,"url":"https://github.com/shepherdwind/papilio-nunjucks","last_synced_at":"2026-01-19T07:33:00.080Z","repository":{"id":32808350,"uuid":"36400972","full_name":"shepherdwind/papilio-nunjucks","owner":"shepherdwind","description":"simple nunjucks api encapsulation","archived":false,"fork":false,"pushed_at":"2015-07-17T06:20:28.000Z","size":160,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-12T16:21:27.316Z","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/shepherdwind.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-05-27T23:00:31.000Z","updated_at":"2015-05-27T23:17:11.000Z","dependencies_parsed_at":"2022-08-31T22:10:15.085Z","dependency_job_id":null,"html_url":"https://github.com/shepherdwind/papilio-nunjucks","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/shepherdwind%2Fpapilio-nunjucks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shepherdwind%2Fpapilio-nunjucks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shepherdwind%2Fpapilio-nunjucks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shepherdwind%2Fpapilio-nunjucks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shepherdwind","download_url":"https://codeload.github.com/shepherdwind/papilio-nunjucks/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247471297,"owners_count":20944153,"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-09-26T07:44:27.876Z","updated_at":"2026-01-19T07:33:00.053Z","avatar_url":"https://github.com/shepherdwind.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## papilio-nunjucks\n\n[![NPM version][npm-image]][npm-url]\n[![build status][travis-image]][travis-url]\n[![Test coverage][coveralls-image]][coveralls-url]\n\n\n[npm-image]: http://img.shields.io/npm/v/papilio-nunjucks.svg?style=flat-square\n[npm-url]: http://npmjs.org/package/papilio-nunjucks\n[travis-image]: https://img.shields.io/travis/shepherdwind/papilio-nunjucks.svg?style=flat-square\n[travis-url]: https://travis-ci.org/shepherdwind/papilio-nunjucks\n[coveralls-image]: https://img.shields.io/coveralls/shepherdwind/papilio-nunjucks.svg?style=flat-square\n[coveralls-url]: https://coveralls.io/r/shepherdwind/papilio-nunjucks?branch=master\n\n\n### API\n\n```js\nvar nunjucks = require('papilio-nunjucks');\nnunjucks(base)\n.filter('stringify', JSON.stringify)\n.engine('.vm', function(name) {\n  // .vm file retrun empty string\n  return '';\n})\n.engine('.css', function(file) {\n  // css wraped with style tag\n  var str = fs.readFileSync(file).toString();\n  return '\u003cstyle\u003e\\n' + str + '\u003c/style\u003e';\n})\n.use(function(schema) {\n  return getData(schema);\n}, function(schema) {\n  return [\n    '\u003cdiv class=\"tag\" data-schema=\"' + schema + '\"\u003e',\n    '\u003c/div\u003e'\n  ];\n})\n.render('index.html')\n```\n\n### async render tag\n\nYou could use methd `yield()` to change render method retrun an promise, so you\ncan pass an generator function to use method, like this:\n\n```js\nnunjucks(base)\n.yield()\n.use(function*() {\n  var data = yield Promise.resolve({name: 'inner'});\n  return data;\n})\n.render('use/html.html').then(function(ret) {\n  ret.trim()\n  .should\n  .eql('\u003cdiv\u003e inner \u003c/div\u003e');\n})\n.catch(done);\n```\n\nIn koa, you can write code like this:\n\n```\nvar view = nunjucks(base).yield().use(this.services.getData);\nreturn yield view.render(xx.html)\n```\n\n### use tag\n\nAdd a custom tag support\n\n```html\n{% use 'schemas/shop.js' %}\n  {{title}} is {{url}} {{img}}\n{% enduse %}\n```\n\nThe template wraped by use tag, then, those template context will be the use\nmethod return value.\n\nSuch as `use 'schemas/shop'` return an object `{title: 1, url: 2, img: 3}`, then\nuse tag render as `1 is 2 3`.\n\nWhen use tag return a array, template render just like for loop. Each loop run,\nthe template context will change to the current array item object. Also you can\nuse loop local variable.\n\nYou can see more example as code `test/extention.test.js`.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshepherdwind%2Fpapilio-nunjucks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshepherdwind%2Fpapilio-nunjucks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshepherdwind%2Fpapilio-nunjucks/lists"}