safe-get-function
is a utility that allows you to write code using get-function
today. It is particularly useful to authors of libraries, frameworks and other utilities who want to make their code compatible with past, present and future versions of Sass.
call($name)
is deprecated in favor of call(get-function($name))
with the introduction of first-class functions in Sass 3.5.0.
The official recommendation is to update your code to get ready for Sass 4.0.0 and use get-function
as soon as Sass 3.5.0 is released. Not only you'd have to wait for Sass 3.5.0 to get released, but you'd also be writing code that doesn't work in older versions of Sass. safe-get-function
was created to allow authors to write code compatible with older and future versions at the same time.
h1 {
content: call(safe-get-function($name), $arguments...);
}
You have a few options:
- A good ol’ copy-paste of index.scss to your codebase
- or using npm
npm install sass-safe-get-function --save
- or even bower
bower install kaelig/sass-safe-get-function --save
@import 'path/to/sass-safe-get-function/index.scss';
Instead of get-function
, use safe-get-function
:
@function foo($x) { @return $x; }
h1 {
@if (function-exists('get-function')) {
content: call(get-function('foo'), 'Only displays in Sass 3.5.0 and up');
} @else {
content: call('foo', 'Only displays in Sass 3.3.x and 3.4.x');
}
}
@import 'path/to/sass-get-function/index.scss';
@function foo($x) { @return $x; }
h1 {
content: call(safe-get-function('foo'), 'Displays in Sass 3.3.x and up!');
}
Clone the repository, then:
gem install bundler
npm install
npm test
Thank you to @chriseppstein for inspiring this library.