Skip to content
Permalink
Browse files

Add error function and test all errors

  • Loading branch information...
mirisuzanne committed Feb 6, 2017
1 parent 15c251d commit de0c473a95d99117475f1c023f17423803bb7e7b
@@ -8,6 +8,7 @@
// - susy-normalize-location [function]



// Parse
// -----
/// Parse shorthand span expression
@@ -31,7 +32,7 @@
$shorthand
) {
$span-error: 'Not able to determine column-span from `#{$shorthand}`';
$parse-error: 'Unknown span property:';
$parse-error: 'Unknown shorthand property:';
$options: (
'first': 'location',
'last': 'location',
@@ -62,7 +63,9 @@
$span: join($span, ('x' $item));
}
} @else {
@error '`#{item}` is not a valid column-width';
@return _susy-error(
'`#{$item}` is not a valid column-width',
'susy-parse');
}
} @else {
$return: map-merge($return, ($next: $item));
@@ -82,34 +85,34 @@
} @else if $item == 'all' {
$span: 'all';
} @else if not $span {
@error $span-error;
@return _susy-error($span-error, 'susy-parse');
} @else if ($item == 'at') {
$next: 'location';
} @else if ($item == 'x') {
$next: 'column-width';
} @else if ($item == 'of') {
$of: true;
} @else {
@error '#{$parse-error} `#{$item}`';
@return _susy-error('#{$parse-error} `#{$item}`', 'susy-parse');
}
} @else if ($type == 'number') or ($type == 'list') {
@if not $span {
$span: $item;
} @else if $of {
} @else if $of and not $columns {
$columns: $item;
} @else {
@error '#{$parse-error} `#{$item}`';
@return _susy-error('#{$parse-error} `#{$item}`', 'susy-parse');
}
} @else {
@error '#{$parse-error} `#{$item}`';
@return _susy-error('#{$parse-error} `#{$item}`', 'susy-parse');
}
}
}

@if $span {
$return: map-merge($return, ('span': $span));
} @else {
@error $span-error;
@return _susy-error($span-error, 'susy-parse');
}

@if $columns {
@@ -120,6 +123,7 @@
}



// Susy Normalize
// --------------
/// Normalize the values in a configuration map
@@ -164,6 +168,7 @@
}



// Normalize Columns
// -----------------
/// Normalize `columns` shorthand for Su
@@ -200,6 +205,7 @@
}



// Normalize Span
// --------------
/// Normalize `span` shorthand for Su
@@ -227,6 +233,7 @@
}



// Normalize Spread
// ----------------
/// Normalize `spread` shorthand for Su
@@ -252,6 +259,7 @@
}



// Normalize Location
// ------------------
/// Normalize `location` shorthand for Su
@@ -6,6 +6,7 @@
// - susy-get [function]



// Susy
// ----
/// Custom user configuration map for Susy
@@ -40,6 +41,7 @@
$susy: () !default;
// Susy Defaults
// -------------
/// Configuration map of Susy factory defaults
@@ -95,6 +97,7 @@ $susy-defaults: (
}



// Susy Get
// --------
/// Return the current value of any Susy setting
@@ -113,7 +116,9 @@ $susy-defaults: (
$settings: susy-settings();

@if not map-has-key($settings, $key) {
@error 'There is no Susy setting called `#{$key}`';
@return _susy-error(
'There is no Susy setting called `#{$key}`',
'susy-get');
}

@return map-get($settings, $key);
@@ -1,6 +1,8 @@
// Sass Utilities
// ==============
// - Susy Get Function
// - Susy Get Function [function]
// - Susy Error Output Override [variable]
// - Susy Error [function]



@@ -23,7 +25,9 @@
$type: type-of($function);

@if ($type != 'string') {
@error 'Invalid function-name, [#{$type}] `#{$function}` must be a string';
@return _susy-error(
'Invalid function-name [#{$type}] `#{$function}`, name must be a string.',
'_susy-get-function');
}

@if function-exists('get-function') {
@@ -32,3 +36,25 @@

@return $function;
}



// Susy Error Output Override
// --------------------------
$_susy-error-output-override: false !default;



// Susy Error
// ----------
@function _susy-error(
$message,
$source,
$override: $_susy-error-output-override
) {
@if $override {
@return 'ERROR [#{$source}] #{$message}';
}

@error '[#{$source}] #{$message}';
}
@@ -6,6 +6,7 @@
// - su-valid-location [function]



// Valid Columns
// -------------
/// Check that the `columns` argument is a valid
@@ -24,16 +25,22 @@
$first: nth($columns, 1);

@each $col in $columns {
@if (type-of($col) != 'number') or (not comparable($col, $first)) {
$error: false;

@if (type-of($col) != 'number') or (not comparable($col, $first)) or (unitless($col) and not unitless($first)) or (unitless($first) and not unitless($col)) {
$actual: '[#{type-of($columns)}] `#{inspect($columns)}`';
@error '#{$actual} is not a value for $columns.';
@return _susy-error(
'#{$actual} is not a list of comparable lengths, valid for $columns.',
'su-valid-columns');
}

}

@return $columns;
}



// Valid Gutters
// -------------
/// Check that the `gutters` argument is a valid number
@@ -54,18 +61,31 @@
$type: type-of($gutters);

@if ($type == 'number') {
@if unitless($gutters) and (not unitless(nth($columns, 1))) {
@error 'Gutters must have units for a static grid.';
$first: nth($columns, 1);

@if (unitless($gutters) and not unitless($first)) {
@return _susy-error(
'Gutters must have units for a static grid.',
'su-valid-gutters');
}

@if (not comparable($gutters, $first)) {
@return _susy-error(
'Gutter and column units must be comparable.',
'su-valid-gutters');
}

@return $gutters;
}

$actual: '[#{$type}] `#{inspect($gutters)}`';
@error '#{$actual} is not a value for $gutters.';
@return _susy-error(
'#{$actual} is not a value for $gutters.',
'su-valid-gutters');
}



// Valid Spread
// ------------
/// Check that the `spread` argument is a valid
@@ -87,10 +107,13 @@
}

$actual: '[#{type-of($spread)}] `#{inspect($spread)}`';
@error '#{$actual} is not a value for $spread.';
@return _susy-error(
'#{$actual} is not a normalized [0 | 1 | -1] value for `$spread`.',
'su-valid-spread');
}



// Valid Location
// --------------
/// Check that the `location` argument is a valid number,
@@ -117,14 +140,22 @@
@if $location {
@if (type-of($location) != 'number') or (not unitless($location)) {
$actual: '[#{type-of($location)}] `#{$location}`';
@error '#{$actual} is not a value for $location.';
@return _susy-error(
'#{$actual} is not a unitless number for $location.',
'su-valid-location');
} @else if (round($location) != $location) {
@error 'Location (`#{$location}`) must be a 1-indexed intiger position.';
} @else if ($location > $count) {
@error 'Position `#{$location}` does not exist in grid `#{$columns}`.';
@return _susy-error(
'Location (`#{$location}`) must be a 1-indexed intiger position.',
'su-valid-location');
} @else if ($location > $count) or ($location < 1) {
@return _susy-error(
'Position `#{$location}` does not exist in grid `#{$columns}`.',
'su-valid-location');
} @else if ($location + $span - 1 > $count) {
$details: 'grid `#{$columns}` for span `#{$span}` at `#{$location}`';
@error 'There are not enough columns in #{$details}';
@return _susy-error(
'There are not enough columns in #{$details}.',
'su-valid-location');
}
}

0 comments on commit de0c473

Please sign in to comment.
You can’t perform that action at this time.