SASS、Rails 3.1:在供应商/资产中加载样式表 [英] SASS, Rails 3.1: Loading stylesheets in vendor/assets

查看:56
本文介绍了SASS、Rails 3.1:在供应商/资产中加载样式表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 SASS 在 Rails 3.1(sass-rails 3.1) 应用程序中加载样式表.例如,app/assets/stylesheets 中的 sass 部分使用 application.sass -

I'm using SASS to load stylesheets in a Rails 3.1(sass-rails 3.1) app. For example, sass partials in app/assets/stylesheets are loaded using @import in application.sass -

 @import "pages/common"
 @import "pages/**/*"
 @import "jquery-ui.css"

现在,我还想加载vendor/assets/stylesheets.请注意,我没有使用 require vendor,因为 @import pages/* 似乎是 sass 推荐的做法.此处的文件将是 css,而不是 sassscss.我不能使用 @import ../../../vendor/assets/stylesheets/* 因为它只适用于 sassscss文件.

Now, I also want to load vendor/assets/stylesheets. Note that I'm not using require vendor, as @import pages/* seems to be the sass recommended way of doing it. Files here will be css, and not sass or scss. I cannot use @import ../../../vendor/assets/stylesheets/* as it works only for sass and scss files.

有没有办法做到这一点?

Is there any way of doing this ?

更新

我现在拥有的是这个.

application.css.scss

//= require_tree .
//= require vendor
//= require_self

这包括上面提到的所有 sass 部分.

This includes all the sass partials mentioned above. The require vendor in

vendor/assets/stylesheets/vendor.css 看起来像

//= require_tree .

这种方法的一个警告是 sass mixins(用户定义和插件)和公共变量并非在所有部分中都可用.我现在拥有的是一个 _common_imports.sass,这是我 @import 在所有部分中的第一件事.

A caveat of this approach is that sass mixins(user defined & plugins) and common variables are not available in all partials. What I have now is a _common_imports.sass which I @import first thing in all partials.

common_imports.sass

@import "colors"
@import "compass/css3/gradient"
@import "compass/css3/border-radius"
@import "compass/css3/box-shadow"

在所有部分中导入 common_imports 感觉很重复.

Importing common_imports in all partials feels very repetitive.

推荐答案

如果我理解正确,我认为这可能会有所帮助.

If I'm understanding you correctly, I think this might help.

将以下内容添加到 config/application.rb 中,在 class Application < 中Rails::Application 块:

Add the following to config/application.rb, inside the class Application < Rails::Application block:

config.sass.load_paths << File.expand_path('../../lib/assets/stylesheets/')
config.sass.load_paths << File.expand_path('../../vendor/assets/stylesheets/')

我刚刚将上述内容添加到应用程序中,现在以下指令都可以使用:

I've just added the above to an app, and the following directives are now both working:

  • 导入Sass:
    @import 'grid'app/assets/stylesheets/application.css.scss 中找到文件vendor/assets/stylesheets/_grid.scss;
  • 导入常规 CSS:
    @import 'background',再次在 application.css.scss 中找到 vendor/assets/stylesheets/background.css.
  • Import Sass:
    @import 'grid' in app/assets/stylesheets/application.css.scss finds the file vendor/assets/stylesheets/_grid.scss;
  • Import regular CSS:
    @import 'background', again in application.css.scss, finds vendor/assets/stylesheets/background.css.

这有帮助吗?对不起,如果我误解了这个问题!

Does that help? Sorry if I've misunderstood the problem!

这篇关于SASS、Rails 3.1:在供应商/资产中加载样式表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆