Skip to content

Instantly share code, notes, and snippets.

@kaelig
Created November 3, 2015 09:28
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/d2e315cc8bc3cb52194c to your computer and use it in GitHub Desktop.
Save kaelig/d2e315cc8bc3cb52194c to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
// ----
// libsass (v3.2.5)
// ----
$debug: true;
$app-version: '0.200.0';
// @author Hugo Giraudel
@function number($string) {
// Matrices
$strings: '0' '1' '2' '3' '4' '5' '6' '7' '8' '9';
$numbers: 0 1 2 3 4 5 6 7 8 9;
// Result
$result: 0;
$divider: 0;
$minus: false;
// Looping through all characters
@for $i from 1 through str-length($string) {
$character: str-slice($string, $i, $i);
$index: index($strings, $character);
@if $character == '-' {
$minus: true;
}
@else if $character == '.' {
$divider: 1;
}
@else {
@if not $index {
$result: if($minus, $result * -1, $result);
@return _length($result, str-slice($string, $i));
}
$number: nth($numbers, $index);
@if $divider == 0 {
$result: $result * 10;
}
@else {
// Move the decimal dot to the left
$divider: $divider * 10;
$number: $number / $divider;
}
$result: $result + $number;
}
}
@return if($minus, $result * -1, $result);
}
/// Major revision of a version
/// @param {String} $version - Semver version (e.g. '1.0.0')
/// @returns {Number} Major revision
/// @example scss
/// _version-major('1.0.0') // 1
/// @private
@function _version-major($version) {
@return number(str-slice($version, 0, str-index($version, '.') - 1));
}
/// Minor revision of a version
/// @param {String} $version - Semver version (e.g. '1.50.0')
/// @returns {Number} Minor revision
/// @example scss
/// _version-minor('1.50.0') // 50
/// @private
@function _version-minor($version) {
$minor-patch: str-slice($version, str-index($version, '.') + 1, str-length($version));
@return 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')
/// @returns {Number} Patch revision
/// @example scss
/// _version-patch('1.50.25') // 25
/// @private
@function _version-patch($version) {
$minor-patch: str-slice($version, str-index($version, '.') + 1, str-length($version));
@return 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
///
/// @requires $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: &;
@if ($debug) {
@warn '#{$parent} deprecated in version #{$version}. Current version: #{$app-version}';
}
}
@if _version-major($version) > _version-major($app-version) {
@content;
} @else {
@if _version-major($version) == _version-major($app-version) {
@if _version-minor($version) > _version-minor($app-version) {
@content;
} @else {
@if _version-minor($version) == _version-minor($app-version) {
@if _version-patch($version) > _version-patch($app-version) {
@content;
}
}
}
}
}
}
.test {
@include deprecate('1.0.0') {
content: 'I am still useful';
}
@include deprecate('0.200.1') {
content: 'I am still useful';
}
@include deprecate('0.199.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