Skip to content

Instantly share code, notes, and snippets.

@KittyGiraudel
Last active August 29, 2015 14:22
Show Gist options
  • Save KittyGiraudel/26ade0f335ac8c1c9e3d to your computer and use it in GitHub Desktop.
Save KittyGiraudel/26ade0f335ac8c1c9e3d to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
// ----
// Sass (v3.4.14)
// Compass (v1.0.3)
// ----
////
/// Here is a way to use `@error` while still supporting Sass 3.3
/// and below, which have no support for the `@error` directive.
////
/// Log a message either with `@error` if supported
/// else with `@warn`, using `function-exists('at-error')`
/// to detect support.
///
/// @param {String} $message - Message to log
@function log($message) {
// The `@warn` version needs to come before `@error` because
// Sass 3.3- chokes on `@error` inside a function as it is
// an unrecognized directive. I believe these engines should
// not even see the `@error` rule since they do not enter the
// `@else` condition however it seems they do, for some reasons.
// Maybe Sass is performing some quick evaluation to crash early
// for cases like this. I'm not sure.
@if feature-exists('at-error') != true {
@warn $message;
} @else {
@error $message;
}
}
/// Log a message either with `@error` if supported or with `@warn`.
///
/// @param {String} $message - Message to log
@mixin log($message) {
// Because functions cannot be called anywhere in Sass,
// we need to hack the call in a dummy condition.
// There are other ways to do this, such as `dummy: log(..)`.
@if log($message) {}
}
// Demo
.foo {
@include log('Message');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment