我使用的是 vanilla Sass(没有 Compass/SUZY/Bourbon/etc.),但我无法确定将 *.rb 文件放在哪里。我不是 Ruby 程序员,但我确实找到了一个别人编写的函数可以满足我的需要。我尝试过搜索,但得到的结果是死胡同。
官方文档本身没有提供任何线索,只提供了如何创建自定义函数:http://sass-lang.com/docs/yardoc/Sass/Script/Functions.html#adding_custom_functions http://sass-lang.com/docs/yardoc/Sass/Script/Functions.html#adding_custom_functions
sass styles.scss styles.css -r custom.rb
LoadError: no such file to load -- static/sass/modules/lib/custom.rb 在尝试此解决方案时(尽管能够 VI 该文件):http://www.seancolombo.com/2010/07/28/how-to-make-and-use-a-custom-sass-function/ http://www.seancolombo.com/2010/07/28/how-to-make-and-use-a-custom-sass-function/
这是我能找到的最接近的问题,但我没有使用 Compass 或 Rails,所以这些解决方案对我来说没有任何意义:如何加载 Sass::Script::Functions 模块的扩展? https://stackoverflow.com/questions/8690372/how-do-i-load-extensions-to-the-sassscriptfunctions-module
我想将自定义函数保留在模块目录中(其中包含我自己的自定义 Bootstrap 库)。但如果它必须去其他地方,我可以忍受。
在 Rails 4 中,这非常简单。在 config/initializer/ 文件夹中创建一个 sass.rb 文件并将模块放入其中。
例如,采用这个随机函数:https://gist.github.com/chriseppstein/1561650 https://gist.github.com/chriseppstein/1561650
module Sass::Script::Functions
def random(*args)
#...buncha code
end
end
只需将其放在 config/initializers/sass.rb 中,您就可以在任何 .scss/sass 样式表中访问它,例如:
.greet{
position: absolute;
top: random(200px);
left: random(200px);
height: random(200px);
width: random(200px);
background-color: blue;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)