views:

296

answers:

3

In my stylesheets directory I have application.css, ie_fixes.css, and a themes directory. The themes directory has about twenty css files in it. All of these stylesheets, minus the ie_fixes, are needed application wide, hence they are included in the application layout. The ie_fixes.css only needs to be included when the user's browser is IE. I would like to be able to include everything in the themes folder in a single, concise line of code.

Rails provides an easy way to include all stylesheets by doing this:

stylesheet_link_tag :all, :recursive => true

Fancy, but the problem with this is it includes my ie_fixes.css in every browser, blowing my IE conditional comments out of the water. So my question is, is there an easy way to include all stylesheets for a subdirectory without having to specify each file name?

I've tried different variations of stylesheet_link_tag 'themes/', :recursive => true to no avail. It seems all this method does is prepend the stylehseet directory and append .css if necessary.

+1  A: 

could you just include it in another directory instead, and within your conditional IE statement in the head tag, point it to that directory?

This would still allow you to get the fancy stylesheets :all when you need it.

pjammer
That would involve mucking up the root stylesheet directory with all the themes, which is why the themes subdirectory exists.
thorncp
i take it that your ie_fixes.css only applies to IE browsers right? and i guess what you are saying is that each theme has to also inherit from this ie_fixes.css file when appropriate too? ie screws everything up :-) best of luck.
pjammer
Yes, the ie_fixes only applies to IE. No, the themes don't require IE fixes, it fixes something totally different. Basically I want to include every css for every browser except for the ie_fixes, which is to only be included for IE.
thorncp
Yeah, but what if you just moved the IE stylesheet to another directory? You could then load it from there.
MattMcKnight
thorncp
check out http://github.com/jystewart/theme_support I use it for my themeing needs. It may give you hints on you can handle your theme stylesheets outside of root. Also, i don't see why you can't put your ie_fixes.css somewhere else, so that :all can't get it and use your conditional logic in your head for just ie browsers. best of luck.
pjammer
+2  A: 

Well one solution would be to combine all of your CSS files (except the IE one) into one file. And then include the IE specific file as needed.

You'll want to do this anyways, as 20 http connections (2 at a time max) would take forever.

Tyler Smith
That's what `:cache => true` is for ;)
thorncp
the first load will still be slow though
corroded
+1  A: 

After scouring the web for what seemed like ages and not finding anything, I finally decided to come up with my own way. I anticipate using this again in future projects, so I created it as a plugin.

http://github.com/thorncp/improved-includes

thorncp