-
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
make tap
helper work with function-valued context variables; add tests
#93
Conversation
Hey Rod ! Let me double check ! Thanks for the detailed explanation and the pr ./Vee On Jul 16, 2012, at 11:59 AM, Rod [email protected] wrote:
|
var base_context = { }; | ||
dust.renderSource("plain text. {@tapper value=\"plain text\"/}", base_context, function(err, out) { | ||
try { | ||
unit.ifError(err); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we use jasmie rather than the old test suite?
Do you mind updating the jas mine tests
Will merge the changes soon
any update on tests will be appreciated. thanks |
I am going to add the jasmine-test |
Sorry everyone. I've had this on my todo list for a while but I haven't yet had a chance to dig into the jasmine-test part of it. (If no one else jumps on it first, can someone point me to specifically where in the current repo this test should go?) For what it's worth, while it was news to me as well, it seems that the
Ideally we'd literally only render the "dust functions" in this method, and against that standard this pull request is still a tiny bit of a hack. There could be non-dust functions that expect one or more arguments. But this patch brings us a lot closer to the objective. Since dust doesn't have a way to pass an argument to the "context functions", the vast majority of them probably aren't expecting one anyway. A more definitive way to do this would be to somehow unambiguously mark the |
@rodw first of all, thanks for your time. Second I have migrated your test to jasmine, you can take a look here: LinkedInAttic/dustjs-helpers@5f59b59. Regarding to the check, we are discussing how to resolve it. |
This pull request addresses a problem with the
tap
function recently added to dust-helpers.js.Tap doesn't always work properly when it encounters references to context keys that resolve to functions as opposed to scalar values.
For instance, given a base context object that includes a function:
Dust will generally resolve a reference to
foo
by evaluating the function. I.e. the template{foo}
will resolve tobar
.In some circumstances the
tap
function doesn't quite do that--yielding an error or a blank/undefined value.Specifically, suppose we're creating a helper function named
example
that accepts an inline-parameter namedvalue
. We'd like to use thetap
helper function (helper-helper-function?) to allowexample
to handle things like:in a dust-like way.But while tap works as expected for
when
an_object_reference
resolves to a string, it gives an error withan_object_reference
resolves to a JavaScript function.The underlying cause for this is that the
tap
method usestypeof input === 'function'
to identify the input values that need to be "rendered" with dust, but not every input function is a dustbody
-style function.The change in this pull request is to check to see if
input
is a zero-argument function, in which casetap
evaluates the function (i.e.output = input()
) rather than trying to tap and render it as a dust template.Unit tests for several
tap
cases are included in the patch.