Fork me on GitHub
#garden
<
2016-03-30
>
adamkowalski05:03:38

I am trying to use the > operator in garden and I am not sure how what is the moral equivalent of div > span { … }

adamkowalski05:03:20

I tried [“div > span” {…}] and [:div [:> [:span {…}]]] but nothing seems to work

niamu05:03:27

[“div > span” {…}] should work actually. There’s also the garden.selectors/> function that you can look into.

adamkowalski05:03:57

when I look at what [“div > span”] produces it makes div &gt span

adamkowalski05:03:22

and I don’t get how to use the selectors/>, do you have any resource you can recommend that documents it or shows an example usage

niamu13:03:20

@adamkowalski: I assume you’re using garden in ClojureScript and having sablono or something similar render your CSS? That explains why the > character is getting escaped. You’ll need to use sablono’s :dangerouslySetInnerHTML: https://github.com/r0man/sablono#setting-innerhtml-of-a-dom-node

niamu13:03:28

To accomplish the same effect in pure garden without a string you would have to require the garden.selectors :as s namespace and then use the > function like so: (css [(s/> :div :span) {…}]

adamkowalski16:03:52

Thanks, that helps a lot. I am using reagent, and using a [:style (garden/css ...)] to actually load in the styles which seems to be the issue. Do you have a recommended way other than dangerously seting the inner html? I've heard of using the good.style/installStyles ... method, but I'm wondering if there is a best practice to follow.

niamu16:03:15

@adamkowalski: Good question. I’m still experimenting with all of that myself. I don’t have experience with Reagent, but I’m sure there must be a way to do the setInnerHTML with it as well to solve the problem.

niamu16:03:08

As for best practice, I imagine most would still advise handling CSS in external files. The dream for me is building some sort of macro that evaluates all of the styles inside each component and compiles that to an external file for use in production and the “setInnerHTML” hack can be used for development purposes.

niamu16:03:23

Ultimately I think we’re headed to a place where all of your components and the styles for those components exist together in cljc files that can be rendered by both the server and the client. That way we’ll have the benefit of server-side rendering with external, cacheable stylesheets and the simplicity of having all of the styles for components be packaged in the component itself.

niamu16:03:55

Now that I’m looking at the documentation, goog.style/installStyles may solve the problem: (style/installStyles (css [(s/> :div :span) {…}]))

niamu16:03:55

But that may be tricky in development when you want to be changing styles as you’ll also need to manage the uninstalling of those styles as well.

adamkowalski16:03:24

What you could do if you wanted an aggregate css file from all your individual components is to use a core.async channel. Essentially have one channel which is waiting for arbitrary css to come to it, and then it can auto generate the external css. Then like what om next does, where the root component grabs the query it's children need. You could recursively grab the styles the child needs

adamkowalski16:03:42

And yeah that's my concern with goog.style, you need to uninstall the styles after each change and install the newest ones

niamu17:03:11

I like that core.async idea. Need to find time to play around with this stuff more.