如何向 Sass 添加自定义函数(通过 Sass::Script::Functions)? [英] How do I add custom functions to Sass (via Sass::Script::Functions)?

查看:47
本文介绍了如何向 Sass 添加自定义函数(通过 Sass::Script::Functions)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 vanilla Sass(没有 Compass/SUZY/Bourbon/等),但我无法弄清楚将 *.rb 文件放在哪里.我不是 Ruby 程序员,但我确实找到了其他人编写的可以满足我需要的函数.我试过搜索,但我想出的结果是死胡同.

I am using vanilla Sass (no Compass/SUZY/Bourbon/etc.) and I'm having trouble figuring out where to put my *.rb file. I am not a Ruby programmer, but I did find a function someone else wrote that does what I need. I've tried searching, but the results I've come up with are dead ends.

官方文档本身没有提供任何线索,只有如何创建自定义函数:http://sass-lang.com/docs/yardoc/Sass/Script/Functions.html#adding_custom_functions

The official docs themselves offer no clues, only how to create a custom function: 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/

LoadError: no such file to load -- static/sass/modules/lib/custom.rb while trying this solution (despite being able to VI the file): http://www.seancolombo.com/2010/07/28/how-to-make-and-use-a-custom-sass-function/

这是我能找到的最接近的 SO 问题,但我没有使用 Compass 或 Rails,所以这些解决方案对我没有任何意义:如何加载扩展到 Sass::Script::Functions模块?

This is the closest SO question I could find, but I'm not using Compass or Rails so the solutions don't make any sense to me: How do I load extensions to the Sass::Script::Functions module?

我想将我的自定义函数保存在我的模块目录中(其中包含我自己的自定义 Bootstrap 库).但如果它必须去其他地方,我可以接受.

I would like to keep my custom functions within my modules directory (which contains my own custom Bootstrap library). But if it has to go elsewhere, I can live with that.

推荐答案

尝试按照第二个链接中的说明进行操作,但指定 ruby​​ 文件的绝对路径.在我的机器上,如果给定了相对路径,则 SASS 似乎在查找文件时遇到问题.

Try following the instructions from your second link, but specify an absolute path to your ruby file. On my machine, it looks like SASS has issues finding the file if it's given a relative path.

这篇关于如何向 Sass 添加自定义函数(通过 Sass::Script::Functions)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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