Skip to content

Instantly share code, notes, and snippets.

@kaelig
Created January 18, 2016 08:47
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/c3c14924340429c01d64 to your computer and use it in GitHub Desktop.
Save kaelig/c3c14924340429c01d64 to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
// ----
// libsass (v3.3.2)
// ----
// Scroll to the end to see the example
// Copyright (c) 2015-2016, 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.
/// Application version
/// @type String
$app-version: '1.0.0' !default;
/// Mode:
/// - disabled: output all code, even if deprecated
/// - silent: disable all warnings but don't output deprecated code
/// - verbose: show all warnings, even for code that is *about* to be deprecated
/// - sensible (default): output warnings when deprecated code is detected
/// - fail: prevent compilation when deprecated code is found
///
/// @type String
$deprecate-mode: 'sensible' !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')
/// @param {String} $message - Reason about why the code will be deprecated or possible workaround (e.g. 'Use .xxx instead')
@mixin deprecate($version, $message: null) {
@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).';
}
// Plugin is disabled. Output anyway.
@if ('disabled' == $deprecate-mode) {
@content;
} @else {
@if not ('silent' == $deprecate-mode) {
// Assume we found code that is (or is about to be) deprecated
$deprecation-found: true;
@if ('verbose' == $deprecate-mode) {
@if (&) {
$parent: &;
@warn '#{$parent} will be deprecated in #{$version}. Current version: #{$app-version}.';
} @else {
@warn 'Some code will be deprecated in #{$version}. Current version: #{$app-version}.';
}
}
// Define if the code is actually deprecated
@if (_d-version-major($version) > _d-version-major($app-version)) {
@content;
$deprecation-found: false;
} @else {
@if (_d-version-major($version) == _d-version-major($app-version)) {
@if (_d-version-minor($version) > _d-version-minor($app-version)) {
@content;
$deprecation-found: false;
} @else {
@if (_d-version-minor($version) == _d-version-minor($app-version)) {
@if (_d-version-patch($version) > _d-version-patch($app-version)) {
@content;
$deprecation-found: false;
}
}
}
}
}
@if ($deprecation-found) {
$message: if($message, '\AREASON: #{$message}', '');
@if ('fail' == $deprecate-mode) {
@error 'Deprecated code was found. Remove it to continue.#{$message}';
} @else {
@warn 'Deprecated code was found, it should be removed before its release.#{$message}';
}
}
}
}
}
.test {
@include deprecate('1.0.1') {
content: 'I am still useful';
}
@include deprecate('2.200.1') {
content: 'I am still useful until 2.200.1';
}
@include deprecate('0.9.0') {
content: 'I am deprecated (not in the output)';
}
}
.test {
content: 'I am still useful';
content: 'I am still useful until 2.200.1';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment