您可以测试是否存在mixin吗? [英] Can you test if a mixin exists?

查看:85
本文介绍了您可以测试是否存在mixin吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这里提出一个简短的问题(希望如此).您可以测试是否存在mixin吗?例如

Sass quick question (hopefully) here. Can you test for the existence of a mixin? e.g.

@if thumbnail-mixin {} @else { //define mixin }.

理想情况下,我会使用@unless,但这仅存在于fork上.我知道您可以覆盖mixin,但我在想是否可以使用默认的mixin,而不是在每种情况下都必须指定N个变量.

Ideally I'd use @unless, but that only exists on a fork. I'm aware you can overwrite a mixin but I'm thinking more if you can have a default mixin, rather than having to specify N variables in every case.

推荐答案

Sass当前没有本机功能来确定是否存在混合.

Sass does not currently have native functionality to determine if a mixin exists or not.

https://github.com/nex3/sass/issues/561#issuecomment-14430978

您可以创建一个用Ruby编写的Sass函数:

You could create a Sass function written in Ruby:

def mixin_exists(mixin_name)
    if(environment.mixin(mixin_name.value))
      Sass::Script::Bool.new(true)
    else
      Sass::Script::Bool.new(false)
    end
end

或者您可以使用 sass-utilities Compass扩展,其中包含此功能.

Or you could use the sass-utilities Compass extension, which has this function included.

这篇关于您可以测试是否存在mixin吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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