Skip to content
Permalink
Browse files

feat: feat: add custom extensions

  • Loading branch information...
dmelikhov
dmelikhov committed Mar 1, 2019
1 parent 03862bb commit 399f77d9afe6d62d0315a03d8f7c5d76cf2233a0
Showing with 44 additions and 1 deletion.
  1. +43 −0 lib/entity/extensions.js
  2. +1 −1 lib/loader.js
@@ -0,0 +1,43 @@
const Entity = require('./');

/**
* Filters Entity
* @type {module.Extensions}
*/
module.exports = class Extensions extends Entity {
/**
* Represents filters
* @param {Njk} env
* @param {Object} exts
*/
constructor(env, exts) {
super(env);

this.init(exts);
}

/**
* Initializes extensions
* @param {Object} exts
*/
init(exts) {
if (typeof exts === 'object' && exts !== null) {
const filtersKeys = Object.keys(exts);

if (filtersKeys.length) {
filtersKeys.forEach(item => this.addFilter(item, exts[item]));
}
}
}

/**
* Add extension to environment
* @param {string} name
* @param {Function} extension
*/
addExtension(name, extension) {
this.env.addExtension(name, extension);

return this;
}
};
@@ -32,7 +32,7 @@ module.exports = class Loader {
this.env = new nunjucks.Environment(
new Njk(
this.options.root,
path => this.contextLoader.addDependency(path),
pathname => this.contextLoader.addDependency(pathname),
),
);

0 comments on commit 399f77d

Please sign in to comment.
You can’t perform that action at this time.