Global-variable-exists raises errors in Sass

I am using ternary statement to initialize a variable in Sass. This allows me to set some of my default variables to the same that Zurb Foundation uses, but if I chose not to include the Foundation module then things shouldn't fall on their heads.

$nav-link-icon-color: if( global-variable-exists($topbar-link-color), $topbar-link-color, #fff) !default;

      

This worked fine until I switched to Sass 3.4. Right after that, I started getting this error:

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

was initialized when I check it. This is a string with the value #fff, declared as Foundation:

$topbar-link-color: #fff !default;

      

I even tried passing an uninitialized variable to global-variable-exists()

:

$nav-link-icon-color: if( global-variable-exists($happy-scrappy), $happy-scrappy, #fff) !default;

      

But Sass hates so much too:

error sass/style.scss (Line 21 of sass/partials/_navigation-icons.scss: Undefined variable: "$happy-scrappy".)

      

This is very strange to me since the whole point global-variable-exists()

is, I know by checking if the variable exists. It seems that the parameter sent to global-variable-exists()

is not being handled correctly, but I don't know.

I tried uninstalling all versions of Sass and Compass, then reinstalling and finally reloading to no avail. I even went back to Sass 3.3.14 which I used before and the same errors persist.

compass 1.0.1 Sass 3.4.0 Foundation 5.3.3 ruby ​​2.0.0p481 Win 7 64 bit

Edit: After further research, my wrong way to do this worked in sass 3.2.19 and compass 0.12.2.

+3


source to share


1 answer


The "problem" persists because you are using this feature incorrectly. The docs paint a very clear idea of ​​how this function is intended to be used:

$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 */ }
}

      

See how variables are not passed to a function? This is because it expects a string that contains the name of the variable , not the variable itself. Passing the variable itself will defeat the purpose of the function: you cannot pass variables that do not exist for functions or mixins.



So ... just let go $

:

$nav-link-icon-color: if( global-variable-exists(topbar-link-color), $topbar-link-color, #fff) !default;

      

+10


source







All Articles