在 SCSS 部分中使用 Rails 3.1 资源路径
我有以下设置:
app/assets/stylesheets/application.css.scss
/*
*= require_self
*= require fancybox
*/
/* COLORS.. */
/* MIXINS... */
/* FONT STACKS... */
/* IMPORTS */
@import "reset";
@import "supergrid";
@import "rails";
@import "app";
@import "forms";
@import "layout";
在我的各个部分中,我的资产路径确实存在问题。当在 application.css.scss
或清单加载的任何内容中时,我可以使用:
.example { background-image: image-path("background.png"); }
但是,当我使用部分时,例如我的 _layout.css.scss
部分,当我尝试相同的操作时,背景图像属性只是从编译的文件中省略。似乎 SCSS 资产助手在部分中不可用?
有没有人让它工作,我错过了一些明显的东西吗?或者根本不可能在部分中使用资产助手?如果是这样,这就是一个非常非常大的问题,因为我的整个应用程序结构依赖于在部分之间共享的 SCSS 变量和 mixin。
我知道变量和 mixin 不会在 sprocket 清单中共享,因此如果部分无法访问资产助手,那么我将考虑必须将所有内容连接到单个 scss 文件中,这几乎违背了 Sass 和 Sprockets 的目的。
任何帮助将非常感激!
I have the following setup:
app/assets/stylesheets/application.css.scss
/*
*= require_self
*= require fancybox
*/
/* COLORS.. */
/* MIXINS... */
/* FONT STACKS... */
/* IMPORTS */
@import "reset";
@import "supergrid";
@import "rails";
@import "app";
@import "forms";
@import "layout";
In my various partials I'm having a real problem with the asset paths. When inside application.css.scss
or anything loaded by the manifest, I can use:
.example { background-image: image-path("background.png"); }
However, when I'm using a partial, such as my _layout.css.scss
partial, when I try the same thing the background-image property is simply omitted from the compiled file. It seems the SCSS asset helpers are not available inside partials?
Has anyone gotten this to work, am I missing something obvious? Or is it simply impossible to use asset helpers in partials? If so this is a major, MAJOR problem, as my entire app structure depends on SCSS variables and mixins which are shared among the partials.
I know that variables and mixins are not shared across the sprockets manifest, so if partials cannot access the asset helpers then I'm looking at having to concatenate everything into a single scss file, which pretty much defeats the purpose of both Sass and Sprockets.
Any help would be very much appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
奇怪的是,它应该可以工作..只有几个想法:
image-path('background.png')
替换为asset-url('background.png', image)
或image-url('background.png')
require_self
Strange, it should work.. Just few ideas:
image-path('background.png')
withasset-url('background.png', image)
orimage-url('background.png')
require_self
from application.css.scss