6.1.0 • Published 1 year ago

@pattern-lab/engine-nunjucks v6.1.0

Weekly downloads
20
License
MIT
Repository
github
Last release
1 year ago

The Nunjucks engine for Pattern Lab / Node

Installing

To install the Nunjucks PatternEngine in your edition, run npm install @pattern-lab/engine-nunjucks.

Supported features

Level of Support is more or less full. Partial calls and lineage hunting are supported. Nunjucks does not support the mustache-specific syntax extensions, style modifiers and pattern parameters, because their use cases are addressed by the core Nunjucks feature set. Pattern Lab's listitems feature is still written in the mustache syntax.

Extending the Nunjucks instance

To add custom filters or make customizations to the nunjucks instance, add the following to patternlab-config.json:

  {
    ...
    "engines": {
      "nunjucks": {
        "extend": [
          "nunjucks-extensions/*.js"
        ]
      }
    }
  }

...or use the default file name: patternlab-nunjucks-config.js (in the root of your Pattern Lab project).

Each file providing extensions should export a function with the Nunjucks environment as parameter.

module.exports = function (env) {
  [YOUR CUSTOM CODE HERE]
};

Example: patternlab-nunjucks-config.js file that uses lodash and adds three custom filters.

var _shuffle = require('lodash/shuffle'),
  _take = require('lodash/take');

exports = module.exports = function (env) {
  env.addFilter('shorten', function (str, count) {
    return str.slice(0, count || 5);
  });

  env.addFilter('shuffle', (arr) => {
    return _shuffle(arr);
  });

  env.addFilter('take', (arr, number) => {
    return _take(arr, number);
  });
};

What Nunjucks features are missing?

I have not yet figured out a way to support variables in pattern includes. I'm thinking it might be possible to use Nunjucks precompile feature to get the compiled partial name before returning it to Pattern Lab, but just a thought at this point.

6.1.0

1 year ago

6.0.0

2 years ago

5.16.1

3 years ago

5.15.1

3 years ago

5.14.3

4 years ago

5.14.0

4 years ago

5.10.1

5 years ago

5.10.0

5 years ago

5.0.0

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.5-alpha.0

6 years ago

0.1.4-beta.2

6 years ago

0.1.4-beta.1

6 years ago

0.1.4-beta.0

6 years ago

0.1.4-alpha.4

6 years ago

0.1.4-alpha.3

6 years ago

0.1.4-alpha.2

7 years ago

0.1.4-alpha.1

7 years ago