https://github.com/firstandthird/hapi-nunjucks-helpers
Helpers for clientkit
https://github.com/firstandthird/hapi-nunjucks-helpers
hapi-plugin hapi-v17
Last synced: 8 months ago
JSON representation
Helpers for clientkit
- Host: GitHub
- URL: https://github.com/firstandthird/hapi-nunjucks-helpers
- Owner: firstandthird
- License: mit
- Created: 2016-11-02T19:40:29.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2021-03-19T16:27:35.000Z (about 5 years ago)
- Last Synced: 2025-06-29T12:39:35.162Z (9 months ago)
- Topics: hapi-plugin, hapi-v17
- Language: JavaScript
- Size: 107 KB
- Stars: 1
- Watchers: 5
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# hapi-nunjucks-helpers
A library of useful [nunjucks](https://mozilla.github.io/nunjucks/) helpers and filters, with a wrapper for use with [hapi](https://hapi.dev/)
## Installation
```
npm install hapi-nunjucks-helpers
```
## Usage
hapi-nunjucks-helpers is designed to work with [vision](https://github.com/hapijs/vision) and
[vision-nunjucks](https://github.com/firstandthird/vision-nunjucks), you just need to make sure to tell nunjucks to compile the helpers in 'async' mode:
```js
await server.register(require('vision'));
server.views({
engines: {
njk: require('vision-nunjucks')
},
path: '/views',
isCached: false,
compileMode: 'async'
});
await server.register(require('hapi-nunjucks-helpers'));
```
Is all you need to do, all of the following helpers will then be available for use in your views:
## Asset Helper
When you register the plugin you can pass options to configure how your assets filter will work:
```js
await server.register({
plugin: require('hapi-nunjucks-helpers'),
options: {
assets: {
endpoint: 'http://localhost:8080/',
cdn: 'http://localhost',
mappingFile: 'assets-map.json'
}
}
});
```
These options are as follows:
- `endpoint` The base asset directory, default is none.
- `dist` The root directory under _endpoint_ where compiled asset files reside, so `assets` will look for compiled asset files in the directory specified by _${endpoint}/${dist}_. Default is none.
- `mappingFile` A JSON file containing the map of source files to their corresponding hashed assets, this file should look like:
```JS
{
"common.js": "common.0d5714f897be66e21c18.js",
"common.css": "common.f7f029f8ee35aec7a7f6.css",
"script.js": "script.68e5e334aa4dcb31eece.js"
...
}
```
- `cdn` - Optional CDN domain for assets. Default: none.
- `cache` - If `true`, caches contents of `mappingFile`. Default: `false` (you will generally want to leave cacheing off during development)
## Filters:
**asset**
Reads from the mapping file if available:
```html
```
Also possible to pass a version to force new fetch from cache:
```html