You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've created a fork of the kit and will soon be at the stage to contribute something potentially useful but as suggested in the Guide lines for contributing I'm explaining the enhancement here before asking somebody to spend time code reviewing a pull request.
In short:
Will keep filters neatly in their place and make them automatically available to nunjucks
Provide a suite of functional filters for manipulating data, strings, arrays, objects, etc.
At length:
Currently out-of-the-box (unless I've missed something) adding a new filter to Nunjucks express means doing the following in server.js:
nunjucks.ready(function(env) {
// First custom filter.
env.addFilter('sayHi', function(name) {
return 'Ayup ' + name '!';
});
// Second custom filter.
env.addFilter('sayBye', function(name) {
return 'Ta-ta ' + name '!';
});
// etc.
// and so on.
});
As a start I've created lib/filters.js and in there you would simply do:
"fi" meaning "filter item". (You'll see why that name in the PR).
This keeps a potentially growing list of filters in their own place (with the possibility for further organisation/tidying if required).
Along with that, I can add a collection of useful filters with huge credit and thanks going to @TheFuzzball who wrote a lot them and has kindly given permission for their use. Allowing manipulating of strings, objects, arrays, etc. Essentially a thin layer between Nunjucks and lodash.
This could give us a basis for defining pattern schemas as discussed with @timpaul, @htmlandbacon, @gemmaleigh and others recently. I'll stop here and we could go into more detail about that another time.
If I do a PR, would it be preferable for two branches/PRs. One for simply making it easier to add custom nunjucks filters in their own file. One for adding the suite of useful filters (reduce, merge, etc)?
The text was updated successfully, but these errors were encountered:
Wow - good stuff! Yes, keeping things like filters out of routes.js is a good idea and will make it easier to upgrade the kit over time. I think 2 PRs is a good idea too.
Hi,
I've created a fork of the kit and will soon be at the stage to contribute something potentially useful but as suggested in the Guide lines for contributing I'm explaining the enhancement here before asking somebody to spend time code reviewing a pull request.
In short:
At length:
Currently out-of-the-box (unless I've missed something) adding a new filter to Nunjucks express means doing the following in
server.js
:As a start I've created
lib/filters.js
and in there you would simply do:"fi" meaning "filter item". (You'll see why that name in the PR).
This keeps a potentially growing list of filters in their own place (with the possibility for further organisation/tidying if required).
Along with that, I can add a collection of useful filters with huge credit and thanks going to @TheFuzzball who wrote a lot them and has kindly given permission for their use. Allowing manipulating of strings, objects, arrays, etc. Essentially a thin layer between Nunjucks and lodash.
This could give us a basis for defining pattern schemas as discussed with @timpaul, @htmlandbacon, @gemmaleigh and others recently. I'll stop here and we could go into more detail about that another time.
If I do a PR, would it be preferable for two branches/PRs. One for simply making it easier to add custom nunjucks filters in their own file. One for adding the suite of useful filters (reduce, merge, etc)?
The text was updated successfully, but these errors were encountered: