Created
June 20, 2013 18:01
-
-
Save carchrae/5825054 to your computer and use it in GitHub Desktop.
add this javascript after you load dust.js and it will allow you to reference dot path contexts in nested scopes and globals. see https://github.com/linkedin/dustjs/pull/271 for more details
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
| //supports dot path resolution, function eval, and searching global paths | |
| Context.prototype.getPath = function(cur, down) { | |
| var ctx = this.stack, | |
| len = down.length, | |
| tail = cur ? undefined : this.stack.tail; | |
| if (cur && len === 0) return ctx.head; | |
| ctx = ctx.head; | |
| var i = 0; | |
| while(ctx && i < len) { | |
| if (typeof ctx === "function") { | |
| //evaluate functions and inspect returned value | |
| ctx = ctx.apply(this); | |
| if (ctx) | |
| ctx = ctx[down[i]]; | |
| } | |
| else | |
| ctx = ctx[down[i]]; | |
| i++; | |
| while (!ctx && !cur){ | |
| if (tail){ | |
| ctx = tail.head; | |
| tail = tail.tail; | |
| i=0; | |
| } else if (!cur) { | |
| //finally search this.global. we set cur to true to halt after | |
| ctx = this.global; | |
| cur = true; | |
| i=0; | |
| } | |
| } | |
| } | |
| return ctx; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment