Closed zomars closed 6 years ago
There is no gulp plugin yet, but gulp workflow being based on piping streams into each other, it's trivial to have Twing included in that type of workflow. From the top of my head, something like this should work:
var through = require('through2');
let Twing = require('twing');
let loader = new Twing.TwingLoaderFilesystem('.');
let gulpPlugin = function(file) {
let s = through(function(file, encoding, callback) {
let twing = new Twing.TwingEnvironment(loader);
twing.render(file.toString()).then(
function(data) {
callback(null, data);
}
);
});
s.write(file);
return s;
};
let plugin = gulpPlugin('index.html.twig');
plugin.pipe(process.stdout);
That should make a nice starting point. What do you think?
Interesting I'll take a dive and see what can I accomplish.
Good! Let me know how it goes. I close the issue for now but feel free to comment.
I've got it working so far. I'm getting some error but I'm guessing is because of the coverage not being 100% yet:
TypeError: extension.getFilters is not a function
I will keep tinkering with it to see how far I can go.
Hmmm. That's not normal. Can you give me a test case for that error so that I look at it?
This is exciting. I have a bunch of projects on gulp-twig, looking forward to dropping in Twing and trying it out.
@zomars, @olets, we now have an official gulp plugin:
@ericmorand sweeeet
I recommend bumping Twing to at least v1 (I'd just add 1 and do 1.9.0). npm semver matching doesn't kick in until v1, so gulp-twing's current "twing": "^0.8.1"
is effectively "twing": "0.8.1"
@olets, you're right but I'm not comfortable bumping to v1.0+ before everything is fully tested and documented. And Twing is a peer dependency so it's actually ok.
V1.0 is just 3-4 weeks away if everything keep on going smooth.
Ah yes indeed I missed the peer dependency aspect. Looking forward to trying it out!
Can you provide an example? I actually use Nunjucks and it gets the job done, but, I would like to keep the syntax the most twig-like as possible. The reason being that I like to code my templates in a static manner first and then turning them into a theme for a CMS like Bolt or Wordpress.