Rails Sass:变量不通过@import 传递 [英] Rails Sass: variables are not passed with @import

查看:53
本文介绍了Rails Sass:变量不通过@import 传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 twitter bootstrap 和 sass 的 rails 项目.scss 文件被组织成文件夹,所以我有更好的概述.现在我想为包含我的颜色等的全局变量定义一个文件,并将这些值传递给其他文件,这样我的冗余代码就更少了.虽然所有代码都被正确导入和应用,变量不起作用.

I have a rails project which uses twitter bootstrap and sass. The scss files are structured into folders so I have a better overview. Now I want to define a file for global variables which contains my colors etc. and pass those values down to other files so I have less redundant code. While all code is properly imported and applied, variables don't work.

这是当前设置:

样式表/application.css.scss

stylesheets/application.css.scss

/*
 *= require_self
 *= require_tree
 */


/*
stylesheets/
|
|– base/
|   |– _reset.scss       # Reset/normalize
|   |– _typography.scss  # Typography rules
|
|– components/
|   |– _buttons.scss     # Buttons
|   |– _messages.scss    # Nachrichten
|   |– _dropdown.scss    # Dropdown
|
|– helpers/
|   |– _globals.scss     # Sass Variables
|   |– _functions.scss   # Sass Functions
|   |– _mixins.scss      # Sass Mixins
|   |– _helpers.scss     # Class & placeholders helpers

//more files omitted
|
|– vendors/
|   |– _bootstrap_and_overrides.css   # Bootstrap
|   |– _scaffolds.scss   # Bootstrap

|
|
`– main.scss             # primary Sass file
*/

我没有使用 =require 方法,因为它不允许使用变量和 mixin(我想使用).

I'm not using the =require method as it does not allow the use of variables and mixins (which I'd like to use).

我还使用包含所有导入的 main.scss.样式表/main.scss

I also use a main.scss which contains all the imports. stylesheets/main.scss

@import "bootstrap-sprockets";
@import "bootstrap";

@import "helpers/globals";

@import "base/normalize";
@import "base/grid";
@import "base/typography";

@import "components/buttons";
@import "components/tables";
//other files omitted

helpers/globals.scss 包含颜色定义:样式表/helpers/globals.scss

The helpers/globals.scss contains the color definitions: stylesheets/helpers/globals.scss

$background-light : #4e4d4a;

文件 component/tables.scss 应该使用该变量.

The file component/tables.scss is supposed to use that variable.

.table-striped > tbody > tr:nth-child(2n+1) > {
  tr, td, th {
    background-color: $background-light;
  }
}

根据网络上的大多数信息和官方 SASS 指南,这应该可以正常工作,因为我声明了变量并在使用它的文件之前导入了相应的文件.当然,没有找到变量:未定义变量:"$background-light".

According to most information on the web and the official SASS-guide this should work as I declared the variable and import the according file before the file that uses it. Certainly, the variable is not found: Undefined variable: "$background-light".

整个过程看起来很简单,但我已经没有想法了.我需要在我的环境文件中设置一些东西还是需要更改我的 application.css.scss?或者引导程序可能会干扰这里?

The whole procedure seems rather simple but I'm running out of ideas. Do I need to set something in my environment files or do I need to change my application.css.scss? Or might bootstrap interfere here?

预先感谢您的帮助.

推荐答案

如上所述,我最近遇到了一些资产无法按预期工作的经历.我收到的建议是使用:

Noting above, I've recently had some experience with assets not working as expected. The recommendation I received was to use:

rake assets:clobber

这将清理管道.

https://github.com/rails/sprockets-rails/blob/master/README.md

这篇关于Rails Sass:变量不通过@import 传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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