garden

2016-03-30T05:03:38.000004Z

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

2016-03-30T05:04:20.000005Z

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

niamu 2016-03-30T05:08:27.000006Z

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

2016-03-30T05:42:57.000007Z

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

2016-03-30T05:43:22.000008Z

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

niamu 2016-03-30T13:38:20.000009Z

@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

niamu 2016-03-30T13:43:28.000011Z

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) {…}]

2016-03-30T16:19:52.000013Z

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.

niamu 2016-03-30T16:27:15.000014Z

@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.

niamu 2016-03-30T16:29:08.000015Z

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.

niamu 2016-03-30T16:32:23.000016Z

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.

niamu 2016-03-30T16:36:55.000017Z

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

niamu 2016-03-30T16:37:55.000018Z

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.

2016-03-30T16:38:24.000019Z

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

2016-03-30T16:39:42.000020Z

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

niamu 2016-03-30T17:01:11.000021Z

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