|
| 1 | + |
| 2 | + |
1 | 3 | # nunjucks-brunch-static |
2 | 4 | Compile static nunjucks files with brunch. |
| 5 | + |
| 6 | +nunjucks-brunch-static is a processor for [html-brunch-static](https://github.com/bmatcuk/html-brunch-static), a [brunch](http://brunch.io/) plugin designed to handle static html files. nunjucks-brunch-static can convert nunjucks files into static html files with html-brunch-static's support for layouts and partial views. |
| 7 | + |
| 8 | +If you're looking for support for deprecated "jade" files, check out [jade-brunch-static](https://github.com/bmatcuk/jade-brunch-static). |
| 9 | + |
| 10 | +## Installation |
| 11 | +nunjucks-brunch-static depends on [html-brunch-static](https://github.com/bmatcuk/html-brunch-static), which also depends on [brunch-static](https://github.com/bmatcuk/brunch-static), so, you will need to install all three. The recommended method is via npm: |
| 12 | + |
| 13 | +```bash |
| 14 | +npm install --save-dev brunch-static html-brunch-static nunjucks-brunch-static |
| 15 | +``` |
| 16 | + |
| 17 | +Or manually: |
| 18 | + |
| 19 | +* Add `"brunch-static": "x.y.z"` to package.json |
| 20 | +* Add `"html-brunch-static": "x.y.z"` to package.json |
| 21 | +* Add `"nunjucks-brunch-static": "x.y.z"` to package.json |
| 22 | +* Run `npm install` |
| 23 | +* Alternatively, you may use the latest git version with: |
| 24 | + * `"brunch-static": "git+ssh://git@github.com:bmatcuk/brunch-static"` |
| 25 | + * `"html-brunch-static": "git+ssh://git@github.com:bmatcuk/html-brunch-static"` |
| 26 | + * `"nunjucks-brunch-static": "git+ssh://git@github.com:bmatcuk/nunjucks-brunch-static"` |
| 27 | + |
| 28 | +## Configuration |
| 29 | +Add nunjucks-brunch-static to your list of html-brunch-static processors: |
| 30 | + |
| 31 | +```coffee |
| 32 | +exports.config = |
| 33 | + ... |
| 34 | + plugins: { |
| 35 | + static: { |
| 36 | + processors: [ |
| 37 | + require('html-brunch-static')({ |
| 38 | + processors: [ |
| 39 | + require('nunjucks-brunch-static')({ |
| 40 | + fileMatch: 'source/views/home.nunjucks', |
| 41 | + fileTransform: (filename) => filename.replace(/static\.njk/, '.html') |
| 42 | + }) |
| 43 | + ] |
| 44 | + }) |
| 45 | + ] |
| 46 | + } |
| 47 | + } |
| 48 | +``` |
| 49 | + |
| 50 | +Most options passed to nunjucks-brunch-static are passed, verbatim, to [nunjucks](https://github.com/mozilla/nunjucks), with the exception of: |
| 51 | + |
| 52 | +* **fileMatch** _(default: `/\.static\.njk/`)_ |
| 53 | + |
| 54 | + > _fileMatch_ is an [anymatch](https://github.com/es128/anymatch) that is used to determine which files will be handled by this processor. As an anymatch, it may be a string with globs, a regex, or a function that takes a filename and returns true if it should be handled, or false otherwise. The default will match files that end in `.static.njk`. |
| 55 | +
|
| 56 | +* **fileTransform** _(default: `(filename) => filename.replace(/static\.njk/, '.html')`)_ |
| 57 | + |
| 58 | + > _fileTransform_ converts the input filename into an html filename. It takes a filename as input and returns the new filename with the html extension. If you set the _fileMatch_ property above, you'll probably need to set this option as well to ensure that your output files end with the html extension. |
| 59 | +
|
| 60 | +## Context and Local Variables |
| 61 | +The [html-brunch-static's context](https://github.com/bmatcuk/html-brunch-static#context-layouts-and-partials) will be exposed in your nunjucks files as local variables allowing you to use them in your template. |
| 62 | + |
0 commit comments