开发者

Include all stylesheets in a subdirectory in Rails

开发者 https://www.devze.com 2022-12-14 20:13 出处:网络
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

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.


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.


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消