{"id":18169682,"url":"https://github.com/firstandthird/vision-nunjucks","last_synced_at":"2025-05-13T01:36:26.705Z","repository":{"id":51806672,"uuid":"73050196","full_name":"firstandthird/vision-nunjucks","owner":"firstandthird","description":"Nunjucks support for vision","archived":false,"fork":false,"pushed_at":"2023-01-05T01:39:01.000Z","size":937,"stargazers_count":2,"open_issues_count":12,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-18T11:20:37.321Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/firstandthird.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-11-07T06:50:41.000Z","updated_at":"2021-03-08T20:01:51.000Z","dependencies_parsed_at":"2023-02-03T04:16:43.382Z","dependency_job_id":null,"html_url":"https://github.com/firstandthird/vision-nunjucks","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/firstandthird%2Fvision-nunjucks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/firstandthird%2Fvision-nunjucks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/firstandthird%2Fvision-nunjucks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/firstandthird%2Fvision-nunjucks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/firstandthird","download_url":"https://codeload.github.com/firstandthird/vision-nunjucks/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253855320,"owners_count":21974445,"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-11-02T14:05:17.507Z","updated_at":"2025-05-13T01:36:26.686Z","avatar_url":"https://github.com/firstandthird.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# vision-nunjucks\n\n[Nunjucks](https://mozilla.github.io/nunjucks/) rendering language support for [vision](https://github.com/hapijs/vision)\n\nVision Nunjucks also has built in support for the  [clientkit](https://github.com/firstandthird/clientkit) UI Framework.\n\n## Installation\n\n```\nnpm install vision-nunjucks\n```\n\n## Basic Usage\n```js\nawait server.register(require('vision'));\n\nserver.views({\n  engines: {\n    njk: require('vision-nunjucks')\n  },\n  path: '/views'\n});\n```\n\nNow you can specify template-rendering routes just with\n```js\nserver.route({\n  path: '/',\n  method: 'get',\n  handler: {\n    view: {\n      template: 'test',\n      context: {\n        meal1: 'Breakfast',\n        meal2: 'Second Breakfast'\n      },\n    }\n  }\n});\n```\n\n## Helpers\n\n   Helpers are functions that will be registered as Nunjucks filters. You can manually register helpers like so:\n\n```js\nconst viewManager = server.views({\n  engines: {\n    njk: visionNunjucks\n  },\n  path: `${__dirname}/views`\n});\nviewManager.registerHelper('myHelper', (str) =\u003e `${str} from test`);\n```\n\nThen in your Nunjucks templates you can do:\n```html\n\u003cp\u003e{{ \"hi\" | myHelper }}\u003c/p\u003e\n```\n\nand get back:\n\n```html\n\u003cp\u003ehi from test\u003c/p\u003e\n```\n\n## Asynchronous Helpers\n\nBy default vision-nunjucks assumes your helpers are synchronous, but you can also have it invoke helpers in the asynchronous style:\n\n```js\nserver.views({\n  engines: {\n    njk: require('vision-nunjucks')\n  },\n  path: '/views',\n  compileMode: 'async'\n});\n```\n\nYour helpers should then have the form:\n```js\nmodule.exports = function(str, done) {\n  done(null, `${str} is a `);\n};\n```\n\n## Compile Options\n\nYou can pass additional nunjucks compile options like so:\n\n```js\nserver.views({\n  engines: {\n    njk: require('vision-nunjucks')\n  },\n  path: '/views',\n  compileOptions: {\n    throwOnUndefined: true\n  }\n});\n```\n\n## Exported Functions:\n\nvision-nunjucks exports all of the default functions in [Nunjucks](https://mozilla.github.io/nunjucks/api.html), and additionally provides the following wrapper functions to facilitate using Nunjucks:\n\n- __compile(src, options, callback)__\n\n  A frontend for [Nunjucks.compile](https://mozilla.github.io/nunjucks/api.html#compile).  Will take in the string source code for a template and return a render function that takes in a context object and renders the template with that context. _options_ can include a _filename_ field that will be passed as the _path_ option for _Nunjucks.compile_. vision-nunjucks will manage the env parameter for you.\n\n- __initEnvironment(path, compileOptions)__\n\n  Frontend for the [Nunjucks.configure](https://mozilla.github.io/nunjucks/api.html#configure). _compileOptions_ will be passed to the _opt_ field.  Will return the _env_ object if you need access to it, but you can ignore it and vision-nunjucks will manage it for you.\n\n- __clearEnvironment()__\n\n  Resets the managed env parameter.\n\n- __prepare(options, next)__\n\n  Will call _initEnvironment_ and register helpers.  The _options_ object can contain:\n\n  - _compileMode_\n\n    Set to 'sync' or 'async' to have synchronous / asynchronous helpers.\n\n  - _path_\n\n    Will be passed as the path parameter to _initEnvironment_.\n\n  - _compileOptions_\n\n    Will be passed as the _compileOptions_ to _initEnvironment_.\n\n- __registerHelper(name, helper)__\n\n  Takes in the name and function for a helper and then registers it in the managed environment.  Calling _initEnvironment_ will purge these from the environment.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffirstandthird%2Fvision-nunjucks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffirstandthird%2Fvision-nunjucks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffirstandthird%2Fvision-nunjucks/lists"}