-
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
Allow helpers to return primitives #647
Conversation
6a49792
to
b10c41f
Compare
Looks good. My only question is, what is the difference between |
At the top of the function chunk gets aliased to this. On Tue, Apr 28, 2015, 9:18 AM Steven [email protected] wrote:
|
Got it. Thanks. |
if (ret instanceof Chunk) { | ||
return ret; | ||
} | ||
return chunk.reference(ret, context, 'h'); |
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.
Let's have this accept a filters param from the helper and pass it to chunk.reference. 'h' will still be the default though.
Otherwise, looks good!
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.
I really like this. Thanks for the idea!
d070fe3
to
a538b8c
Compare
} | ||
return ret; | ||
return chunk.reference(ret, context, 'h', filters); |
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.
I know this isn't going to be easy but we should support pragmas
and not hardcode the h
here.
e.g.
{%esc:s}
{@unsafe}{~n}
{%esc:h}
{@unsafe}
{/esc}
{/esc}
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.
Super legit, let me dive into that.
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.
Thanks for the great catch. Test cases added.
f0778d0
to
3f2bbc5
Compare
To clarify from discussion offline with Jimmy: Currently you can write a context helper that does this:
But you can't write a helper that does the same thing:
So this is just intended to normalize these. |
3f2bbc5
to
b72bd8f
Compare
As discussed in the WTF I've removed support for a So the new capability is only to normalize the behavior of global helpers and context helpers. |
Hahaha @jimmyhchan I read the code for
Dust already automatically passes |
eb3ee28
to
bb28633
Compare
Previously returning a primitive would crash rendering with no way to recover. You can still return a Chunk and do more complex work if you need to. Helpers act like references or sections depending on if they have a body. When they have no body, they act like a reference and look in `params.filters` for filters to use. When they have a body, they act like a section. You can return thenables and streams normally. {@return value="<Hello>" filters="|s" /} {@return value="<Hello>"}{.} World{/return} Closes linkedin#645
bb28633
to
746603b
Compare
Allow helpers to return primitives Previously returning a primitive would crash rendering with no way to recover. You can still return a Chunk and do more complex work if you need to. Helpers act like references or sections depending on if they have a body. When they have no body, they act like a reference and look in `params.filters` for filters to use. When they have a body, they act like a section. You can return thenables and streams normally. {@return value="<Hello>" filters="|s" /} {@return value="<Hello>"}{.} World{/return} Closes #645
Previously returning a primitive would crash rendering with no way to recover.
Primitives are always HTML-escaped
with no way to turn that offunless you override with afilters
param. If you need to adjust the escaping, you need to return a Chunk and do the work yourself.Closes #645