-
Notifications
You must be signed in to change notification settings - Fork 479
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
Add Node.js require() handler for .dust files #330
Conversation
+1 |
After using this for a while in production, I have found that it is useful to make |
How does this change relate to this other piece of work I saw recently? https://github.com/michaelleeallen/dustjs-require |
That is for AMD-style modules, this is for node-style modules. It is mostly useful for making dust templates available by the same syntax in node and in a CommonJS frontend. I have been using it to load templates using relative filenames, so that a template file can be stored in the same directory as the view that consumes it, and the view doesn't need any knowledge of the directory structure in order to say |
This is something we should have. Can I assume it is backwards compatible? If someone was referring to a template with an extension will they need to change their code? I know there are a few other bug fixes in the 2.3.X milestone which may have priority over this. |
@jjclark1982 Can you update your code to the latest? I believe this is good enough to merge. |
I am on honeymoon for the next week so it is hard to push code directly. Paging @aazlant to this thread. |
new code should look like this:
|
This handler is backwards-compatible with older versions of node and dust: it won't conflict with other ways of loading templates. Although it will publish the template under its full filename even if required with a shorter path, so some aliasing in 'dust.cache' is necessary to make the best use of memory while still allowing sub views to be loaded with their shortest names via '{>subview}' Separating the template, render function and stream function like this is very forwards-compatible: it leaves an obvious place to add things like a 'reload()' function for cache invalidation during development. And it leaves the template block function available for onLoad manipulation. |
@jjclark1982 can you fix the merge conflicts on this? This has been re-mentioned recently per #516 as a potential solution. |
Sure, I'll resolve the conflicts. |
I am not sure how to add this to the test suite, but here is the code I used to test this functionality:
Notably missing from this implementation is a way to require a |
When working on server code with templates in individual
.dust
files, it is convenient to be able torequire()
those files into useful modules, like so:This patch provides a
require()
handler to make that possible.