-
Notifications
You must be signed in to change notification settings - Fork 110
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
Fix inconsistency with add operator, Added switch/case, Added default pipeline, Filter block with format function (take 3) #136
base: master
Are you sure you want to change the base?
Conversation
Hey @maxime1907 so this is your PR, come to life again! Just to be clear, this:
Correct? There's been some back-and-forth throughout the comments so I want to make sure I have it straight. (If that's the case, there's not even really breaking changes to existing stuff, just feature adds, which is cool.) @annismckenzie you said in #95 that you wanted to add more tests:
Are you all good now? Otherwise I guess I can give this branch a spin. |
@@ -174,7 +174,7 @@ func TestEvalActionNode(t *testing.T) { | |||
RunJetTest(t, data, nil, "actionNode_Add3Minus", `{{ 2+1+4-3 }}`, fmt.Sprint(2+1+4-3)) | |||
|
|||
RunJetTest(t, data, nil, "actionNode_AddIntString", `{{ 2+"1" }}`, "3") | |||
RunJetTest(t, data, nil, "actionNode_AddStringInt", `{{ "1"+2 }}`, "12") | |||
RunJetTest(t, data, nil, "actionNode_AddStringInt", `{{ "1"+2 }}`, "3") |
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.
@tooolbox It does change the behavior of the + as can be seen by this test.
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.
Got it. Yeah some other discussion on that in #32
So yeah, I see the breaking change...but in thinking about it, how many people intended "1"+2 = "12"
?
I will look for this scenario in my tests but now I doubt it's an issue.
No, the default pipeline (I don't really really know what it does OTOH right now… 😅) and the filter block need unit tests. |
@maxime1907 how do you feel about adding unit tests for these things, since you added the features? Otherwise someone may come along and break your desired behavior with a later PR. It seems like you're making Jet (somewhat) compatible with the Perl templating engine, and I don't think any of us have experience with that. |
...Probably we should land this at some point. |
There's a lot in this PR, and I'm not sure if I understand all that's happening, so please someone correct me if I'm wrong:
I'll go through these points one-by-one:
It would be great if @maxime1907 could chime in, since they authored the original PR, but everyone else's feedback is just as welcome, of course. No matter what we decide on with this PR, I'd also like to split it up into one PR per feature to make it easier to discuss and review. |
No objections.
Agreed. @maxime1907 was apparently basing this off of some perl templating which used the keyword as a way to set values to variables if they were falsey. I feel like we could accomplish that a different way.
Sure.
I am rather keen on being able to say "pipe this block through a formatter", and I'm less fond of storing the result of a block in a variable and then pipelining it. An example for me is templating an email, where sections of it need to be quoted-printable. The template becomes quite straightforward with just a
I...think I track? Instead of this: {{ filter format("<-- %v -->") }}
This is
formatted text
{{ end }} output:
Something like this: {{ filter myFilter }}
This is
formatted text
{{ end }} output:
I mean, more powerful, perhaps less obvious from the template what's occurring. But if I need to make stuff quoted-printable, that's hardly visible from the template either. |
Can you elaborate on this? I think it would be very useful for people working with long strings, since this way the editor highlighting applies, while keeping the possibility of using functions and pipelines and if/else etc. on those strings, using the existing syntax. (This is pretty much what was requested in #167.) |
At this point I'm not actually 1000% sure what the tradeoffs are that we're discussing, so I think we should just rewind back slightly. This is what I think would be useful: {{ filter myFilter }}
This is
formatted text
{{ end }} output:
Doing What I get from what you're saying is it would be more like this: {{ block xyz}}
{{ return `
<html></html>
`}}
{{ end }}
{{ exec("xyz") | myFiler | anotherFilter }} It accomplishes the same thing, it just seems more clunky. If Anyway, there's not a huge difference here I think, if I have the lay of the land right, but that's how I would cast my lot. |
Okay, I think I didn't do a good job explaining how I would want filters to work. Let me start with example code:
Assuming
and registered as a function with Jet, the example Jet code will give you this:
So in essence, (speaking in Go pseudo code), I propose making
(This omits for simplicity the splitting of the piped value at newlines.) This way, filters are just functions of a certain signature that you register with Jet, and blocks can be used as value independently of the filter functionality (i.e. would be a better solution for #167). |
I see what you're saying. I think the only difference is: Option 1{{ set foo }}
some lines
making up
a block
{{ end }}
{{ foo | filter: makeComment }} Option 2{{ filter makeComment }}
some lines
making up
a block
{{ end }} I feel like (2) is more...straightforward, less indirection. Less powerful though, I admit. Option (1) may be easier to implement, since you could reuse all the expression pipelining stuff, so that would be a point in its favor. Looking at it objectively, it seems like a style preference, and both would be just fine. If you implement (1) I would have nada to complain about and just be happy to have the feature so I can ditch some weird hacks I did 😉 ...Was about to post this, and then I thought: do we even need the filter thing? If we have |
GitHub is driving me nuts with their PR collaboration between contributors and maintainers. The same thing that happened in #93 now happened in #95 again. SIGH.
This is the rebased version of #95 onto the current master.