-
Notifications
You must be signed in to change notification settings - Fork 33
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
Making lambdas more like the mustache spec #49
Comments
As an example, I'm doing the following right now: "withCondition" ~> \stree -> pure @SubM $
case condition of
Nothing -> stree
Just cond -> concat
[ [TextBlock $ "#if " <> cond <>"\n"]
, stree
, [TextBlock "#endif\n"]
] and I'm thinking something like the following could be nice: "withCondition" ~> \text render -> do
case condition of
Nothing -> render text
Just cond -> do
result <- render text
return $ Text.unlines
[ "#if " <> cond
, result
, "#endif"
] |
Do you mean this as "in addition" to the other allowed lambdas? In that case that seems like a reasonable addition, since it is also backwards compatible. |
If you would like to implement this, I'd be happy to accept a PR. |
I'd be happy to submit a PR, but I'm not quite sure what the best way forward is. The mustache spec requires that lambdas pass through the raw template text, but data STree a = STree [Node a] Text but I'm not sure how to store the raw text at the same time as parsing it |
I started work in #50. I also added the spec tests related to lambdas, and I'm running into two issues:
|
I have one further comment: I would also be in favor of an optimized version of this whole interface for functions of type |
So actually, However, it's not fully compliant with the mustache spec for lambdas — in fact, none of the current instances fully implement the mustache spec. For example, the mustache spec states that the lambda must be able to inspect the raw template text, and lambdas must be able to return a template that would be rendered. Now, maybe that's fine; since lambdas are optional, we could say that the I don't really have skin in the game, so I'll leave whatever next steps up to you. I did update my PR to add tests for the official lambda spec, which also includes a couple other library changes. Feel free to cherry-pick and/or close the PR, for whatever you decide |
The mustache spec gives this example:
Issue #30 talked about making lambdas easy to use for simple text transformations, but it's still pretty difficult to do anything more complicated. I'm thinking it would be nice if the Haskell API could align more with the API in the mustache spec, something like
The mustache example could then be implemented as
where the first argument is the raw template text.
Thoughts?
The text was updated successfully, but these errors were encountered: