Skip to content
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

is it possible to extend Bolero HTML Builder CEs with CustomOperation? #302

Closed
BryanWilhite opened this issue Apr 26, 2023 · 3 comments
Closed

Comments

@BryanWilhite
Copy link

BryanWilhite commented Apr 26, 2023

Looking at “Expanding Existing Computational Expressions” suggests to me that, say, ElementBuilder can be extended.

Are the Bolero HTML Builder CEs open to this or do I need to learn more stuff about CEs?

instead of using function like this:

bulmaCardImageContainer  
    NoCssClasses  
    (imageElement  
        NoCssClasses  
        NoAttr  
        $"{feed.feedTitle} feed image"  
        (feed.feedImage |> Option.get |> Uri))

…we can do this:

bulmaCardImageContainer {
    NoCssClasses
    imageElement {
        NoCssClasses  
        NoAttr  
        $"{feed.feedTitle} feed image"  
        feed.feedImage |> Option.get |> Uri
    }
}

…by extending Bolero.Html?

@BryanWilhite
Copy link
Author

Looks like the answer is no:

...computation expressions and custom operators are two orthogonal language features that do not interact in any way...
---Tomas Petricek

@granicz
Copy link
Member

granicz commented Apr 29, 2023

On the contrary, you should be able to augment Bolero.Builders.ElementBuilder with your own custom operators/keywords, following the same convention as for the built-in set. To provide type safety, i.e. where certain features are only available inside a given custom operator like in your example above, you will need extra sub-builder types and quite a bit of boilerplate code. Overall, not a whole lot of gain for a small improvement of notation, but if you do it well (with inlining, etc.) you might just make it more performant than ordinary function calls.

That said, I'd strongly advise against encoding HTML components in F# and use templating instead.

@BryanWilhite
Copy link
Author

thanks @granicz! ... i have opened a SO question to get a better understanding of CEs

with regard to templating, i would be interested in a templating approach where we have something like haml or pug to avoid the verbosity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants