测试是否定义了 Sass 函数 [英] Test whether a Sass function is defined

查看:53
本文介绍了测试是否定义了 Sass 函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何测试 Sass 函数是否存在?

How can I test if a Sass function exists?

我有一个使用自定义 Sass 函数的 Sass 包.但是,在 Ruby 之外(例如 libsass),可能未定义该函数并提供回退:

I have a Sass package that uses a custom Sass function. However, outside Ruby (e.g. libsass), that function may not be defined and a fallback is provided:

<代码>url: if($bootstrap-sass-asset-helper, twbs-font-path('name.eot'), 'name.eot')

我想根据是否声明 twbs-font-path$bootstrap-sass-asset-helper 的值设置为 true 或 false.

I would like to set the value of $bootstrap-sass-asset-helper to true or false depending on whether twbs-font-path is declared.

推荐答案

当前版本的 Sass 有一个 function-exists 函数.完整示例:

The current version of Sass has a function-exists function. Full example:

.foo {
  @if function-exists(myfunc) {
    exists: true;
  }
  @else {
    exists: false;
  }
}

这是 v3.3(2014 年 3 月)的新功能,因此您可能需要更新 Sass gem 才能使用它.

This is new functionality to v3.3 (March 2014), so you may need to update your Sass gem to utilize it.

Sass v3.3 还添加了其他存在性测试:

Sass v3.3 adds other existence tests too:

variable-exists($name)
global-variable-exists($name)
mixin-exists($name)

更多关于 Sass v3.3.

这篇关于测试是否定义了 Sass 函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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