Closed ben657 closed 8 years ago
Thanks! I may be making assumptions but if you wanted to transform the data before outputting to a template then you can use Nunjucks' built-in filters... https://mozilla.github.io/nunjucks/templating.html#builtin-filters
Is that on track? Could be possible to extend upon that if not everything is covered... certainly would require some creativity :)
@ben657 I wonder if this could be accomplished like this... http://stackoverflow.com/a/30920598
Perhaps a filters
object could be added to the schema where each custom filter is a path to a module's file.
Yeah, having the ability to add filters would be a good step. Could have filters as an object with keys being the name, values being the relative file to require, which should export a function.
100% agree :)
{
...
"filters": {
"markdown": "filters/markdown.js"
}
}
That would be nice because if you are really crafty you can require modules in your filters.
I added a start, but it's untested. I just assumed the stackoverflow article is all that needs to be done.
I feel like it should work, but nunjucks doesn't seem to pickup the filter...
@ben657 Have a look if you are curious :)
@ben657 Got it working... you can test out 1.8.0
:)
You can find a working template example here... https://github.com/howardroark/webapp
Sorry for the silence, been busy recently, finally got a chance to try this out!
Nice! Is it working out for you? I also added the option supply files that work with "inquirer.js" to prompt for data.
Just got the templates written out, haven't got a use for the filters yet but will be going back and using them. Questions don't seem to be working though, got "questions": "template/prompts.js"
in the template.json, but it doesn't seem to be getting run.
Maybe open and issue and post the contents of that file or a pseudo version that is similar? I really didn't test that feature very carefully... cause I don't use it :P
This file has become a bit wacky I feel... https://github.com/howardroark/pollinate/blob/develop/lib/extend.js
My bad actually, hadn't updated my global install of pollinate :P Do agree with extend.js though, seems like there should be a flow that fits it better
Good news! Yeah... I thought it was a good idea to have, but sorta just chucked it in :P At least it works!
First off, great little tool!
Would be nice to be able to do some parsing of the passed in options though, things like capitalising a name and having that available to templates too. Maybe give a js file which could export a function to do some work on the data.
e.g.
Then
{{ capitalName }}
would be available in templates.