r0man / sablono

Lisp/Hiccup style templating for Facebook's React in ClojureScript.
Eclipse Public License 1.0
694 stars 66 forks source link

Custom Tags #46

Open sritchie opened 9 years ago

sritchie commented 9 years ago

I know it explicitly says NOT to do this in the README... BUT, let me make the pitch.

I've written a bunch of components in Om-Bootstrap that could easily be hooked into Sablono's renderer, if I were able to extend specific (namespaced) keywords in the markup to call out to my om-bootstrap components.

For example,

[:div
  [::b/button {:bs-style "primary"}
    [:a "Anchor tag"]]]

::b/button would pass the options and children into om-bootstrap.button/button.

What do you think? Is this a feature you guys would be interested in?

r0man commented 9 years ago

Hi Sam, could you provide more details on how this should work? Roman

sritchie commented 9 years ago

Hey r0man,

I'd replace react-fn with a multimethod:

https://github.com/r0man/sablono/blob/master/src/sablono/compiler.clj#L72

that way the user could extend it to different tags.

r0man commented 9 years ago

Hi Sam,

makeing react-fn a multimethod is not a big deal. However, I think we need a better name for the function. Patch with tests welcome, and ideally without any additional dependencies.

Roman

sritchie commented 9 years ago

Okay, I should have some time to play with this in the next week or so. Thanks!

dsvensson commented 9 years ago

Updates?

sritchie commented 9 years ago

Haven't worked on this, but converting that function to a multimethod should do it easily.

pangloss commented 9 years ago

I'd also love to be able to plug custom element tags into sablono.

If this is hung up on deciding on a name, how about element-constructor?

sritchie commented 9 years ago

I think it's just hung up on someone coding up the multimethod implementation. I'm just not using sablono in my work, so haven't gotten around to it.

— Sent from Mailbox

On Fri, Jul 31, 2015 at 4:00 PM, Darrick Wiebe notifications@github.com wrote:

I'd also love to be able to plug custom element tags into sablono.

If this is hung up on deciding on a name, how about element-constructor?

Reply to this email directly or view it on GitHub: https://github.com/r0man/sablono/issues/46#issuecomment-126831065

zcaudate commented 7 years ago

I would really like this feature because then you can plug-in different renderers and do things closer to jsx: https://react.semantic-ui.com/views/card#card-example-card

[:sem/card 
  [:sem/image ...]
  [:sem/card.header]]
bendlas commented 7 years ago

I'm in love with the idea of allowing qualified keywords as sablono hiccup tag names, to call constructor functions but there is a big caveat: the sablono interpreter + advanced optimization:

Since clojurescript function names are subject to renaming, but keywords aren't, the interpreter won't be able to construct such elements, unless all used constructor functions are marked ^:export.

This is really sub-optimal, but maybe rum and om can be persuaded to change their def* forms accordingly ...