在大型 Rails 项目中管理 CSS

发布于 2024-08-17 00:06:00 字数 231 浏览 5 评论 0原文

在大型 Rails 项目中处理 CSS 的好方法有哪些?理想情况下,我希望能够在每个部分中包含 CSS 或 CSS 文件的链接。

我尝试过使用 content_for 和 Yields,它允许我将 CSS 插入到页面头部,其中的部分位于其他地方,但是某些部分被多次使用,这会导致样式链接加倍。

我理想的解决方案是能够为插入头部的每个部分添加一个样式表链接标签,然后在生产中这些链接将被整理成一个仅包含一次的大样式表。

What are some good methods for handling CSS in large Rails projects? Ideally I'd like to be able to include CSS or a link to a CSS file per partial.

I've played around with using content_for and yields which allows me to insert CSS into the head of the page with partials that are located elsewhere, however some partials get used more than once which would result in a double up of style links.

My ideal solution would be the ability to have a stylesheet link tag per partial that is inserted into the head, then in production these links will be collated into one big stylesheet that is only included once.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

往事随风而去 2024-08-24 00:06:00

您应该考虑查看 Sass指南针。 Sass 为您提供了一种生成 CSS 的绝妙方法。 Compass 为您提供了一个框架来更轻松地管理所有 Sass 样式表和 mixin。

Sass 让 CSS 再次变得有趣。

Compass 是一个样式表创作框架,可让您的样式表和标记更易于构建和维护。使用 Compass,您可以使用 Sass 而不是 CSS 编写样式表。

You should consider looking into Sass and Compass. Sass gives you a brilliant way to generate CSS. Compass gives you a framework to manage all your Sass stylesheets and mixins more easily.

Sass makes CSS fun again.

Compass is a stylesheet authoring framework that makes your stylesheets and markup easier to build and maintain. With compass, you write your stylesheets in Sass instead of CSS.

吃颗糖壮壮胆 2024-08-24 00:06:00

Compass 是一个很棒的库,但我更喜欢更简单的解决方案。就像 Samuel 提到的,这是矫枉过正。但是,我确实认为 Sass(尤其是 3.0)值得学习。 Mixins、变量、函数都是 CSS 应该具备的东西 :)

我部署到 Heroku,这使得将样式表编译到磁盘变得很棘手。所以我写了一个简单的解决方法,我在这里描述:

http://avandamiri.com/2010/09/15/managing-styles-with-sass-on-heroku.html

技巧是让服务器根据请求编译它们,然后使用 Varnish 缓存结果。我希望它有帮助。

Compass is a great library, but I prefer much more minimal solutions. Like Samuel, mentioned, it is overkill. But, I do think Sass (especially 3.0) is worth getting into. Mixins, variables, functions are all things CSS should have :)

I deploy to Heroku, which makes compiling stylesheets to disk tricky. So I wrote a simple workaround which I describe here:

http://avandamiri.com/2010/09/15/managing-styles-with-sass-on-heroku.html

The trick is to have the server compile them on request and then cache result with Varnish. I hope it helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文