Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds support for Spaces #138

Merged
merged 1 commit into from
Jul 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion dist/_include-media.scss
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,26 @@ $im-no-media-breakpoint: 'desktop' !default;
///
$im-no-media-expressions: ('screen', 'portrait', 'landscape') !default;

///
/// Find first char which is not a space
///
/// @param {String} $string - String to search
/// @param {String} $direction ['left'] - Either 'left' or 'right' to indicate search direction
///
/// @return {Number} - Index of first non-space character
///
@function first-index($string, $direction: 'left') {
@for $i from 1 through str-length($string) {
$index: if($direction == 'left', $i, -$i);

@if str-slice($string, $index, $index) != ' ' {
@return $index;
}
}

@return 0;
}

////
/// Cross-engine logging engine
/// @author Hugo Giraudel
Expand Down Expand Up @@ -322,7 +342,7 @@ $im-no-media-expressions: ('screen', 'portrait', 'landscape') !default;
///
@function get-expression-value($expression, $operator) {
$operator-index: str-index($expression, $operator);
$value: str-slice($expression, $operator-index + str-length($operator));
$value: trim(str-slice($expression, $operator-index + str-length($operator)));

@if map-has-key($breakpoints, $value) {
$value: map-get($breakpoints, $value);
Expand Down Expand Up @@ -469,6 +489,21 @@ $im-no-media-expressions: ('screen', 'portrait', 'landscape') !default;
@return $value * map-get($units, $unit);
}

///
/// Trim's a string by removing leading and trailing spaces
///
/// @param {String} $string - String to trim
///
/// @return {String} - String without spaces
///
@function trim($string) {
@return str-slice(
$string,
first-index($string, 'left'),
first-index($string, 'right')
);
}

///
/// This mixin aims at redefining the configuration just for the scope of
/// the call. It is helpful when having a component needing an extended
Expand Down
19 changes: 19 additions & 0 deletions src/helpers/_first-index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
///
/// Find first char which is not a space
///
/// @param {String} $string - String to search
/// @param {String} $direction ['left'] - Either 'left' or 'right' to indicate search direction
///
/// @return {Number} - Index of first non-space character
///
@function first-index($string, $direction: 'left') {
@for $i from 1 through str-length($string) {
$index: if($direction == 'left', $i, -$i);

@if str-slice($string, $index, $index) != ' ' {
@return $index;
}
}

@return 0;
}
2 changes: 1 addition & 1 deletion src/helpers/_parser.scss
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
///
@function get-expression-value($expression, $operator) {
$operator-index: str-index($expression, $operator);
$value: str-slice($expression, $operator-index + str-length($operator));
$value: trim(str-slice($expression, $operator-index + str-length($operator)));

@if map-has-key($breakpoints, $value) {
$value: map-get($breakpoints, $value);
Expand Down
14 changes: 14 additions & 0 deletions src/helpers/_trim.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
///
/// Trim's a string by removing leading and trailing spaces
///
/// @param {String} $string - String to trim
///
/// @return {String} - String without spaces
///
@function trim($string) {
@return str-slice(
$string,
first-index($string, 'left'),
first-index($string, 'right')
);
}
7 changes: 6 additions & 1 deletion tests/parse-expression.scss
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ $tests-parse-expression: map-merge($media-expressions, (
'>=desktop': '(min-width: 1024px)',
'≥desktop': '(min-width: 1024px)',
'<=desktop': '(max-width: 1024px)',
'≤desktop': '(max-width: 1024px)'
'≤desktop': '(max-width: 1024px)',


'> phone': '(min-width: 321px)',
'>= tablet': '(min-width: 768px)',
'≥ desktop': '(min-width: 1024px)'
));

@include run(test('parse-expression', $tests-parse-expression));