forked from salesforce-ux/sass-deprecate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.scss
164 lines (148 loc) · 6.58 KB
/
index.scss
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
// 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;
/// Deprecation mode
///
/// ### Available modes:
/// - `disabled`: output all the 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
// @link 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
/// @require $deprecate-mode
/// @param {String} $version - SemVer-like version (e.g. '2.0.0')
/// @param {String} $message - Reason about why the code will be deprecated or possible workaround (e.g. 'Use .new-thing 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 (function-exists('deprecate-version-greater-than')) {
// A custom version comparison engine was found:
// rely on it to check if $version is greater than $app-version,
@if (deprecate-version-greater-than($version, $app-version)) {
@content;
$deprecation-found: false;
}
} @else {
// No custom version comparison engine was found:
// fall back to simple version comparison tests.
@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}';
}
}
}
}
}