是否可以将 application.css 更改为 application.css.sass ?

发布于 2024-12-09 05:52:31 字数 824 浏览 2 评论 0原文

我想将 application.css 文件更改为 sass 文件并使用 @import 提取所有必要的文件。然后我想将 application.css.sass @import 到页面特定的 sass 文件中。这一切在开发中都工作得很好,但是当我将其推送到 Heroku 上的生产环境时,我收到此错误:

Error compiling CSS asset
Sass::SyntaxError:  File to import not found or unreadable: application

application.css.sass:

@import "reset"
@import "typography"
@import "buttons"
@import "junk"

$yellow: #f0f090
$orange: #f89818
$blue1: #184898
$blue2: #4888c8

body
 background: ...
 ...
 /* all the rest of the app-wide styling */

uniquePage.css.sass:

@import "application"
/*page specific styling*/

然后需要与我调用的 application.css 不同的内容的页面

!!! 5
%html
  %header       
    = stylesheet_link_tag "uniquePage"

I would like to change my application.css file to a sass file and use @import to pull all the necessary files. Then I want to @import the application.css.sass into page specific sass files. This all works beautifully in development, but when I push it to production env on heroku I get this error:

Error compiling CSS asset
Sass::SyntaxError:  File to import not found or unreadable: application

application.css.sass:

@import "reset"
@import "typography"
@import "buttons"
@import "junk"

$yellow: #f0f090
$orange: #f89818
$blue1: #184898
$blue2: #4888c8

body
 background: ...
 ...
 /* all the rest of the app-wide styling */

uniquePage.css.sass:

@import "application"
/*page specific styling*/

Then on the pages that need stuff different from application.css I call

!!! 5
%html
  %header       
    = stylesheet_link_tag "uniquePage"

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

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

发布评论

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

评论(3

恍梦境° 2024-12-16 05:52:31

在 Rails 3.1 中,application.css 旨在用作清单文件。您不应该重命名它,也不应该在其中放置除 require 或 include 指令之外的内容。

根据您的目的使用不同的文件名。

另请注意,SCSS @import 语法 就像使用部分。如果您想要@import application,则要导入的文件应命名为_application,而不是application

In Rails 3.1, application.css is intended to be used as a manifest file. You shouldn't rename it, nor you should place content inside it except require or include directives.

Use a different file name for your purpose.

Also note that the SCSS @import syntax it's like using a partial. If you want to @import application the file to be imported should be called _application, not application.

记忆之渊 2024-12-16 05:52:31

您应该将其更改为 application.scss :)

请检查这两个 RailsCast:

http:// /railscasts.com/episodes/279-understanding-the-asset-pipeline

http://railscasts.com/episodes/282-upgrading-to-rails-3 -1

+1 对 Simone 的建议

you should change it to application.scss :)

please check these two RailsCasts:

http://railscasts.com/episodes/279-understanding-the-asset-pipeline

http://railscasts.com/episodes/282-upgrading-to-rails-3-1

+1 on Simone's suggestions

凉薄对峙 2024-12-16 05:52:31

那么我想问题就变成了,如何为不同的 css 集制作不同的清单文件?

有几种方法可以做到这一点:

1.每页工作表

这就是您现在正在做的事情,但我会稍微不同地组织工作表,在应用程序和唯一页面中使用@imports。 (而不是将应用程序导入到唯一页面中)。

2.仅对这些页面使用第二个工作表

您可以使用第二个工作表仅包含该页面的更改。所有页面都有申请表,并且在唯一页面上添加第二个标签,仅进行所需的更改。这会花费您额外的 http 请求。

3.重新组织您的 CSS

除非额外的 CSS 很大,否则您最好进行重构以将代码包含在主文件中。可以很容易地将额外的类添加到唯一页面的 body 标记中,并调整任何 CSS 以供页面使用它。

您仍然可以将该 CSS 放入唯一页面的文件中(以帮助维护),然后将其 @import 到您的主文件中。

作为一般规则,除非 CSS 更改很大,否则我会尝试将它们合并到主 CSS 中,否则选择选项 1。

Then I guess the question becomes, how do I make different manifest files for different css sets?

There are several ways to do this:

1. Per page sheets

This is what you are doing now, but I would organise the sheets slightly differently, using @imports in both application and the unique page. (Rather than importing application into the unique page).

2. Use a second sheet for just those pages

You can have a second sheet with just the changes for that page. All pages have the application sheet, and a second tag is added on the unique page with just the required changes. This costs you an extra http request.

3. Reorganize your CSS

Unless the extra CSS is substantial, you may be better off refactoring to include the code in your main file. It is easy to add an extra class to the body tag of the unique page and adjust any CSS to for the page to use that.

You can still put that CSS in a file for the unique page (to help with maintenance), and @import it to your main file.

As a general rule, unless the CSS changes are substantial, I would try to merge them into the main CSS, otherwise go for option 1.

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