Skip to content

Commit 7ec7fc0

Browse files
committed
🎉 first commit
1 parent 8fe5c3d commit 7ec7fc0

File tree

6 files changed

+4182
-0
lines changed

6 files changed

+4182
-0
lines changed

README.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,62 @@
1+
![Release](https://img.shields.io/npm/v/nunjucks-brunch-static.svg)
2+
13
# nunjucks-brunch-static
24
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+

brunch-config.coffee

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module.exports.config =
2+
paths:
3+
public: '.'
4+
watched: ['src']
5+
6+
files:
7+
javascripts:
8+
joinTo: 'index.js'
9+
10+
modules:
11+
wrapper: false
12+
definition: false
13+
14+
npm:
15+
enabled: false
16+
17+
sourceMaps: false
18+
19+
overrides:
20+
production:
21+
optimize: false

index.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
var NunjucksBrunchStatic, _, nunjucks;
2+
3+
nunjucks = require('nunjucks');
4+
5+
_ = {
6+
merge: require('lodash.merge')
7+
};
8+
9+
NunjucksBrunchStatic = (function() {
10+
class NunjucksBrunchStatic {
11+
constructor(config1) {
12+
var ref, ref1;
13+
this.config = config1;
14+
if ((ref = this.config) != null ? ref.fileMatch : void 0) {
15+
this.handles = this.config.fileMatch;
16+
delete this.config.fileMatch;
17+
}
18+
if ((ref1 = this.config) != null ? ref1.fileTransform : void 0) {
19+
this.transformPath = this.config.fileTransform;
20+
delete this.config.fileTransform;
21+
}
22+
}
23+
24+
transformPath(filename) {
25+
return filename.replace(/\.static\.njk$/, '.html');
26+
}
27+
28+
compile(data, filename, options, context, callback) {
29+
var env, opts;
30+
opts = _.merge({}, this.config, options != null ? options.nunjucks : void 0);
31+
env = nunjucks.configure(opts);
32+
return env.renderString(data, context, callback);
33+
}
34+
35+
};
36+
37+
NunjucksBrunchStatic.prototype.handles = /\.static\.njk$/;
38+
39+
NunjucksBrunchStatic.prototype.acceptsContext = true;
40+
41+
return NunjucksBrunchStatic;
42+
43+
}).call(this);
44+
45+
module.exports = function(config) {
46+
return new NunjucksBrunchStatic(config);
47+
};
48+

0 commit comments

Comments
 (0)