我正在使用Rails 3.1.rc5构建我的第一个独立Rails应用程序.我的问题是我希望我的网站有条件地呈现各种CSS文件.我正在使用Blueprint CSS,我试图在screen.css大多数情况下渲染sprockets/rails ,print.css只有在打印时,并且ie.css只有从Internet Explorer访问该站点时.
不幸的是,清单中的默认*= require_tree命令application.css包含assets/stylesheets目录中的所有内容,并导致令人不快的CSS混乱.我目前的解决方法是一种蛮力方法,我单独指定所有内容:
在application.css中:
*= require_self
*= require home.css
...
*= require blueprint/screen.css
Run Code Online (Sandbox Code Playgroud)
在我的样式表部分(haml):
<!--[if lt IE 9]
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
![endif]-->
= stylesheet_link_tag "application"
= stylesheet_link_tag 'blueprint/print', media: 'print'
<!--[if lt IE8]]
= stylesheet_link_tag 'blueprint/ie'
![endif]-->
= javascript_include_tag "application"
Run Code Online (Sandbox Code Playgroud)
这可行,但它不是特别漂亮.我已经做了几个小时的搜索甚至到目前为止,但我希望有一些更容易的方法,我刚刚错过了.如果我甚至可以有选择地渲染某些目录(不包括子目录),那么整个过程就会变得不那么严格.
谢谢!