-
Notifications
You must be signed in to change notification settings - Fork 641
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added option to customize the wrapper for precompiled templates #302
Conversation
That's what If you are calling this API directly, you can use This isn't much different though, and maybe easier to use. This will be backwards-incompatible though. Not sure how much is built off the current API. That's my only major concern with changing it. Might need to add a deprecation noticed for the next version and merge this in 2 versions if we want to do this. |
Thanks @jlongster for reviewing this. I didn't understand this very well: isn't _precompile a private function, and as such is not part of the API? So the BW-incompatible change is the new property "wrapper" on the "opts" object of "function precompile(input, opts)"? The thing I'm trying to prevent with this is the global variable. I want to store the actual precompiled template, and not a empty shell which just call the global variable. [edit] Now I see, I can just use the compiler directly. But I'll have to reimplement the file and directory loading routines :/ |
That's not what I meant, you definitely shouldn't have to do that.
I don't know what you mean by empty shell. When a file is precompiled you get the whole JS code for it back, and if you pass Yes, it will always also put it on The story for "code splitting" or lazily loading templates isn't the best. The primary use case is to load everything at once, but this could certainly be improved. |
Thanks for the clarifications, and sorry for my stubbornness :o) When I said empty shell, I meant the function returned by The code returned by These are sensible defaults, I'm not arguing with that. But if I could get only the compiled template, without the global variable, I would be happy :) I know nunjucks need all the templates I call with Thanks again! I'm just too excited with this lib because it's the best template language I ever found for JS! |
Ah, I see you have a custom loader. Neat. I'm open to refactoring this since the |
This is very useful for the Node.js env, because in some env the fs module can not be used to load template, the only way is to precompile the templates into js file and use require to load it as module. |
Can you give me an idea of what you're considering refactor here? Can this be considered for 2.0 (#347)? |
@rhengles I'm taking a look at this again, and I think we could do this with a minor bump (1.2 -> 1.3). I'd like to review this a little more before accepting it though. |
Ok I'm definitely looking at this again. If we break the precompile API it may be reason enough for 2.0. No need to worry about bumping the major version. |
You've convinced me, I'll merge this in and play with it locally to make sure everything works. |
Added option to customize the wrapper for precompiled templates
Actually, it looks like this is backwards-compatible. I thought you replaced the |
👍 💯 Thanks man! |
Users can use this options to store templates in modules, for example.