Open graingert opened 5 years ago
Looks good. Would you be up for creating a pull request for this?
Seems quite messy to do as the API for, compile -> renderAsync
doesn't
exist
On Fri, 24 May 2019, 14:51 Forbes Lindesay, notifications@github.com wrote:
Looks good. Would you be up for creating a pull request for this?
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/jstransformers/jstransformer-nunjucks/issues/35?email_source=notifications&email_token=AADFATG5MIBKTQ3UI76RVGLPW7XFXA5CNFSM4HPOOKL2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODWFNKMQ#issuecomment-495637810, or mute the thread https://github.com/notifications/unsubscribe-auth/AADFATEB3DEW3INOVPVZ7VLPW7XFXANCNFSM4HPOOKLQ .
You could implement the renderAsync
method: https://github.com/jstransformers/jstransformer#renderasync
That's not allowed as a result of compile
No, I mean you can have a single function renderAsync
that does both compile and render in one go. e.g. https://github.com/jstransformers/jstransformer-rollup only implements renderFileAsync
.
Hmm, this removes any benefit that users might get from precompiling their templates though
On Sat, 25 May 2019, 01:36 Forbes Lindesay, notifications@github.com wrote:
No, I mean you can have a single function renderAsync that does both compile and render in one go. e.g. https://github.com/jstransformers/jstransformer-rollup only implements renderFileAsync.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/jstransformers/jstransformer-nunjucks/issues/35?email_source=notifications&email_token=AADFATDFEQZLAXLETU5AGHLPXCCZ7A5CNFSM4HPOOKL2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODWGZ22I#issuecomment-495820137, or mute the thread https://github.com/notifications/unsubscribe-auth/AADFATF7GJYKAY7MUAHCMDTPXCCZ7ANCNFSM4HPOOKLQ .
I think I have a solution for this, but it snowballed into having to make another PR for test-jstranformer. https://github.com/jstransformers/test-jstransformer/pull/50
I implemented compileAsync. This is enough (I think) to offer the asynchronous support that nunjucks offers. At least it works in my project. But it doesn't pass the tests. This is (again, I think) because the test is wrong. The test assumes that template.fn(locals) returns a string. Hence the test fails when that functions returns a promise, because template.fn(locals).trim() returns an error. By wrapping it in a Promise.resolve() both the situations where template.fn(locals) returns a string or a Promise are covered. This is also how the jstranformer library works, so the tests now better mimick the behavior of the actual library. The test-jstransformer PR also adds a switch for async testing.
If that PR gets accepted, we can update to the latest test-jstransformer release in this repo, and then this PR #42 should pass testing.
https://mozilla.github.io/nunjucks/api.html#asynchronous-support