Created
March 21, 2012 09:46
-
-
Save anoras/2145853 to your computer and use it in GitHub Desktop.
Yes, I know this is wrong
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # See, I need to have handlebars.js load partials from mongodb. | |
| # So I start by monkey patching handlebars `invoke partial` function... | |
| handlebars.VM.original_invokePartial = handlebars.VM.invokePartial | |
| handlebars.VM.invokePartial = (partial, name, context, helpers, partials, data) -> | |
| # Then I try to find the partial in the DB... | |
| Partial.findOne { fullpath: name.split '.' }, (err, p) => | |
| if p? | |
| # ..and I use the loaded partial if it exists | |
| handlebars.VM.original_invokePartial(p.partial, name, context, helpers, partials, data) | |
| else | |
| # ..or I just let handlebars go about its business if it doesn't exist | |
| handlebars.VM.original_invokePartial(partial, name, context, helpers, partials, data) | |
| # The problem is that since `invokePartial` is called from deep within handlebars, I have no way to | |
| # make this play nice with node's async model. I either need to make my monkey patch do a blocking DB-operation, | |
| # or I need to do something else. Suggestions appreciated. Thanks. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment