Skip to content

Instantly share code, notes, and snippets.

@kaelig
Last active November 4, 2015 00:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaelig/9cbc2e8aaa35ef9e1257 to your computer and use it in GitHub Desktop.
Save kaelig/9cbc2e8aaa35ef9e1257 to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
// ----
// libsass (v3.2.5)
// ----
// Copyright (c) 2015, salesforce.com, inc. All rights reserved.
// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
// Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
// Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
// Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
$app-version: '1.0.0' !default;
/// Casts a string into a number (integer only)
///
/// @param {String} $value - Value to be parsed
///
/// @return {Number}
/// @author @HugoGiraudel - Simplified by @kaelig to only convert unsigned integers
/// @see http://hugogiraudel.com/2014/01/15/sass-string-to-number/
/// @access private
@function _d-to-number($value) {
$result: 0;
$digits: 0;
$numbers: ('0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9);
@for $i from 1 through str-length($value) {
$character: str-slice($value, $i, $i);
@if $digits == 0 {
$result: $result * 10 + map-get($numbers, $character);
} @else {
$digits: $digits * 10;
$result: $result + map-get($numbers, $character) / $digits;
}
}
@return $result;
}
/// Major revision of a version
///
/// @param {String} $version - Semver version (e.g. '1.0.0')
/// @return {Number} Major revision
///
/// @example scss
/// _d-version-major('1.0.0') // 1
///
/// @access private
@function _d-version-major($version) {
@return _d-to-number(str-slice($version, 0, str-index($version, '.') - 1));
}
/// Minor revision of a version
///
/// @param {String} $version - Semver version (e.g. '1.50.0')
/// @return {Number} Minor revision
///
/// @example scss
/// _d-version-minor('1.50.0') // 50
///
/// @access private
@function _d-version-minor($version) {
$minor-patch: str-slice($version, str-index($version, '.') + 1, str-length($version));
@return _d-to-number(str-slice($minor-patch, 0, str-index($minor-patch, '.') - 1));
}
/// Patch revision of a version
///
/// @param {String} $version - Semver version (e.g. '1.50.25')
/// @return {Number} Patch revision
///
/// @example scss
/// _d-version-patch('1.50.25') // 25
///
/// @access private
@function _d-version-patch($version) {
$minor-patch: str-slice($version, str-index($version, '.') + 1, str-length($version));
@return _d-to-number(str-slice($minor-patch, str-index($minor-patch, '.') + 1, str-length($minor-patch)));
}
/// Output code only until $app-version reaches $version
/// and signal its deprecation to developers
///
/// @require $app-version
/// @param {String} $version - Semver-like version (e.g. '0.200.0')
@mixin deprecate($version) {
@if type-of($version) != string {
@error 'The parameter passed to deprecate() must be a String. Good: deprecate(\'0.1.0\') / Bad: deprecate(0.1.0).';
}
@if & {
$parent: &;
@warn '#{$parent} deprecated in version #{$version}. Current version: #{$app-version}';
}
@if _d-version-major($version) > _d-version-major($app-version) {
@content;
} @else {
@if _d-version-major($version) == _d-version-major($app-version) {
@if _d-version-minor($version) > _d-version-minor($app-version) {
@content;
} @else {
@if _d-version-minor($version) == _d-version-minor($app-version) {
@if _d-version-patch($version) > _d-version-patch($app-version) {
@content;
}
}
}
}
}
}
.test {
@include deprecate('1.0.1') {
content: 'I am still useful';
}
@include deprecate('2.200.1') {
content: 'I am still useful';
}
@include deprecate('0.9.0') {
content: 'I am deprecated';
}
}
.test {
content: 'I am still useful';
content: 'I am still useful';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment