// @category utilities // simplify checking if a value is defined before outputting it to a property // @mixin if-set // @param $property {String} css property to define // @param $value {String} a valid css value for property // @param $ignore {List} a list of "falsy" values // @usage // =if-set(margin, $margin, $ignore: (5px 10px)); // will only output margin if it is not 5px or 10px @mixin if-set($property, $value: false, $ignore: false) { @if($ignore == false) { $ignore: (0 0px); } @if($value != false and not index(-compass-list($ignore), $value)) { #{$property}: $value; } } $REGISTRY_DO_ONCE: () !default; // a function to prevent routines from executing multiple times // @function do-once // @param $name {String} name of the identifier // @return {Bool} true if the first time invoked, false otherwise @function do-once($name) { @if index($REGISTRY_DO_ONCE, $name) { @return false; } $REGISTRY_DO_ONCE: append($REGISTRY_DO_ONCE, $name); @return true; } // helper to determine if a sprite is already set or sprites are disabled // @function _shouldSetSprite // @private // @param $sprite {SpriteMap} the sprite map to check against // @return {Boolean} should the sprite be set @function _shouldSetSprite($sprite) { @return not $CONFIG_DISABLE_STYLEGUIDE_SPRITES and not $sprite; } // check that a sprite isn't nil or false // @function styleguide-check-sprite // @param $map {SpriteMap} the sprite map to check against // @return {Boolean} is the sprite set @function styleguide-check-sprite($map) { @return not ($CONFIG_DISABLE_STYLEGUIDE_SPRITES and index(false nil, $map)); } // wrapper for sprite() // @function styleguide-sprite // @param $map {SpriteMap} the sprite map // @param $sprite {Sprite} the sprite name // @param $offset-x {Number} the horizontal offset of the sprite position // @param $offset-y {Number} the vertical offset of the sprite position // @return {Sprite} the sprite object or nil @function styleguide-sprite($map, $sprite, $offset-x: 0, $offset-y: 0) { @if not styleguide-check-sprite($map) { @return nil; } @return sprite($map, $sprite, $offset-x, $offset-y); } // wrapper for sprite-position() // @function styleguide-sprite-position // @param $map {SpriteMap} the sprite map // @param $sprite {Sprite} the sprite name // @param $offset-x {Number} the horizontal offset of the sprite position // @param $offset-y {Number} the vertical offset of the sprite position // @return {List} the sprite position or nil @function styleguide-sprite-position($map, $sprite, $offset-x: 0, $offset-y: 0) { @if not styleguide-check-sprite($map) { @return nil; } @return sprite-position($map, $sprite, $offset-x, $offset-y); } // wrapper for sprite-url() // @function styleguide-sprite-url // @param $map {SpriteMap} the sprite map // @return {String} the sprite URL or nil @function styleguide-sprite-url($map) { @if not styleguide-check-sprite($map) { @return nil; } @return sprite-url($map); } // wrapper for sprite-file() // @function styleguide-sprite-file // @param $map {SpriteMap} the sprite map // @param $sprite {Sprite} the sprite name // @return {ImageFile} the image or nil @function styleguide-sprite-file($map, $sprite) { @if not styleguide-check-sprite($map) { @return nil; } @return sprite-file($map, $sprite); } // wrapper for image-width() // @function styleguide-image-width // @param $image {ImageFile} the image // @return {Number} the width of the image or nil @function styleguide-image-width($image) { @if $image == nil { @return nil; } @return image-width($image); } // wrapper for image-height() // @function styleguide-image-height // @param $image {ImageFile} the image // @return {Number} the height of the image or nil @function styleguide-image-height($image) { @if $image == nil { @return nil; } @return image-height($image); }