我正在使用类似三元的语句来初始化Sass中的变量.这允许我将一些我的默认变量设置为与Zurb Foundation使用的相同的东西,但是如果我决定不包括Foundation模块,那么事情就不应该落到他们的头上.
$nav-link-icon-color: if( global-variable-exists($topbar-link-color), $topbar-link-color, #fff) !default;
这一点工作正常,直到我升级到Sass 3.4.紧接着,我开始收到此错误:
error sass/style.scss (Line 20 of sass/partials/_navigation-icons.scss: $name: #ffffff is not a string for `global-variable-exists')
$topbar-link-color
我检查时已初始化.它是一个值为#fff的字符串,由Foundation声明如下:
$topbar-link-color: #fff !default;
我甚至尝试将未初始化的变量传递到global-variable-exists()
:
$nav-link-icon-color: if( global-variable-exists($happy-scrappy), $happy-scrappy, #fff) !default;
但Sass仍然讨厌这样:
error sass/style.scss (Line 21 of sass/partials/_navigation-icons.scss: Undefined variable: "$happy-scrappy".)
这对我来说很奇怪,因为global-variable-exists()
你知道这一点,检查变量是否存在.似乎发送的参数global-variable-exists()
没有被正确解析,但我不知道.
我已经尝试卸载所有版本的Sass和Compass,然后重新安装,最后重新启动无济于事.我甚至还回到了之前使用的Sass 3.3.14,同样的错误仍然存在.
罗盘1.0.1 Sass 3.4.0基础5.3.3 ruby 2.0.0p481 Win 7 64位
编辑:经过进一步的研究,我做错的方法是在sass 3.2.19和指南针0.12.2中工作.
"问题"仍然存在,因为您错误地使用了该功能.该文档画得非常清晰地描述了这个功能是打算如何使用:
$a-false-value: false; // global-variable-exists(a-false-value) => true .foo { $some-var: false; @if global-variable-exists(some-var) { /* false, doesn't run */ } }
看看没有变量传递给函数?那是因为它需要一个包含变量名称的字符串,而不是变量本身.传入变量本身会破坏函数的用途:你不能将不存在的变量传递给函数或mixin.
所以......放下$
:
$nav-link-icon-color: if( global-variable-exists(topbar-link-color), $topbar-link-color, #fff) !default;