From 2875ee28b844e6a4bb3506b909661d9d3a484a82 Mon Sep 17 00:00:00 2001 From: Reda Lemeden Date: Fri, 3 Oct 2014 17:32:05 +0200 Subject: [PATCH] Refactor private functions - Closes #243 - Use null instead of nil (closes #234) - Ignore case for string variables (closes #235) - Remove extraneous @else (closes #237) - Use is-even where appropriate (closes #238) - Remove ternaries (closes #239) - Remove camel case (closes #240) - Refactor is-display-table (closes #241) --- .../functions/_new-breakpoint.scss | 2 +- .../stylesheets/functions/_private.scss | 30 +++++++------------ app/assets/stylesheets/grid/_direction.scss | 4 +-- app/assets/stylesheets/grid/_display.scss | 2 +- app/assets/stylesheets/grid/_media.scss | 20 ++++++------- app/assets/stylesheets/grid/_omega.scss | 4 +-- app/assets/stylesheets/grid/_private.scss | 12 ++------ app/assets/stylesheets/grid/_visual-grid.scss | 2 +- 8 files changed, 29 insertions(+), 47 deletions(-) diff --git a/app/assets/stylesheets/functions/_new-breakpoint.scss b/app/assets/stylesheets/functions/_new-breakpoint.scss index 3fda4d18..cab41e60 100644 --- a/app/assets/stylesheets/functions/_new-breakpoint.scss +++ b/app/assets/stylesheets/functions/_new-breakpoint.scss @@ -34,7 +34,7 @@ $query: $default-feature nth($query, 1) $total-columns; } - @else if length($query) % 2 == 0 { + @else if is-even(length($query)) { $query: append($query, $total-columns); } diff --git a/app/assets/stylesheets/functions/_private.scss b/app/assets/stylesheets/functions/_private.scss index 44d2fad8..0ee224ad 100644 --- a/app/assets/stylesheets/functions/_private.scss +++ b/app/assets/stylesheets/functions/_private.scss @@ -25,16 +25,12 @@ @if length($span) == 3 { $container-columns: nth($span, 3); @return $container-columns; - } - - @else if length($span) == 2 { + } @else if length($span) == 2 { $container-columns: nth($span, 2); @return $container-columns; } - @else { - @return $grid-columns; - } + @return $grid-columns; } @function container-shift($shift: $shift) { @@ -43,16 +39,12 @@ @if length($shift) == 3 { $container-columns: nth($shift, 3); @return $container-columns; - } - - @else if length($shift) == 2 { + } @else if length($shift) == 2 { $container-columns: nth($shift, 2); @return $container-columns; } - @else { - @return $parent-columns; - } + @return $parent-columns; } // Generates a striped background @@ -70,9 +62,7 @@ $values: append($values, $transparent $column-offset, comma); $values: append($values, $color $column-offset, comma); $column-offset: $column-offset + $column-width; - } - - @else { + } @else { $values: append($values, $color $column-offset, comma); $values: append($values, $transparent $column-offset, comma); $column-offset: $column-offset + $gutter-width; @@ -84,9 +74,9 @@ // Layout direction @function get-direction($layout, $default) { - $direction: nil; + $direction: null; - @if $layout == LTR or $layout == RTL { + @if to-upper-case($layout) == "LTR" or to-upper-case($layout) == "RTL" { $direction: direction-from-layout($layout); } @else { $direction: direction-from-layout($default); @@ -96,9 +86,9 @@ } @function direction-from-layout($layout) { - $direction: nil; + $direction: null; - @if $layout == LTR { + @if to-upper-case($layout) == "LTR" { $direction: right; } @else { $direction: left; @@ -110,7 +100,7 @@ @function get-opposite-direction($direction) { $opposite-direction: left; - @if $direction == left { + @if $direction == "left" { $opposite-direction: right; } diff --git a/app/assets/stylesheets/grid/_direction.scss b/app/assets/stylesheets/grid/_direction.scss index e1de3453..2bda7cb9 100644 --- a/app/assets/stylesheets/grid/_direction.scss +++ b/app/assets/stylesheets/grid/_direction.scss @@ -20,9 +20,9 @@ @mixin direction($direction: left-to-right) { $scope-direction: $layout-direction; - @if $direction == left-to-right { + @if to-lower-case($direction) == "left-to-right" { $layout-direction: LTR !global; - } @else if $direction == right-to-left { + } @else if to-lower-case($direction) == "right-to-left" { $layout-direction: RTL !global; } diff --git a/app/assets/stylesheets/grid/_display.scss b/app/assets/stylesheets/grid/_display.scss index 4d0c2994..5dbcee44 100644 --- a/app/assets/stylesheets/grid/_display.scss +++ b/app/assets/stylesheets/grid/_display.scss @@ -19,7 +19,7 @@ */ @mixin display($display: block) { $scope-display: $container-display-table; - $container-display-table: if($display == table, true, false) !global; + $container-display-table: $display == table !global; @content; diff --git a/app/assets/stylesheets/grid/_media.scss b/app/assets/stylesheets/grid/_media.scss index 0ea2d257..b3297d45 100644 --- a/app/assets/stylesheets/grid/_media.scss +++ b/app/assets/stylesheets/grid/_media.scss @@ -64,28 +64,28 @@ } @else { - $loopTo: length($query); - $mediaQuery: 'screen and '; + $loop-to: length($query); + $media-query: 'screen and '; $default-grid-columns: $grid-columns; $grid-columns: $total-columns !global; - @if length($query) % 2 != 0 { - $grid-columns: nth($query, $loopTo) !global; - $loopTo: $loopTo - 1; + @if not is-even(length($query)) { + $grid-columns: nth($query, $loop-to) !global; + $loop-to: $loop-to - 1; } $i: 1; - @while $i <= $loopTo { - $mediaQuery: $mediaQuery + '(' + nth($query, $i) + ': ' + nth($query, $i + 1) + ') '; + @while $i <= $loop-to { + $media-query: $media-query + '(' + nth($query, $i) + ': ' + nth($query, $i + 1) + ') '; - @if ($i + 1) != $loopTo { - $mediaQuery: $mediaQuery + 'and '; + @if ($i + 1) != $loop-to { + $media-query: $media-query + 'and '; } $i: $i + 2; } - @media #{$mediaQuery} { + @media #{$media-query} { @content; $grid-columns: $default-grid-columns !global; } diff --git a/app/assets/stylesheets/grid/_omega.scss b/app/assets/stylesheets/grid/_omega.scss index 2defcd1b..ea1dcbdf 100644 --- a/app/assets/stylesheets/grid/_omega.scss +++ b/app/assets/stylesheets/grid/_omega.scss @@ -31,8 +31,8 @@ * } */ @mixin omega($query: block, $direction: default) { - $table: if(belongs-to(table, $query), true, false); - $auto: if(belongs-to(auto, $query), true, false); + $table: belongs-to(table, $query); + $auto: belongs-to(auto, $query); @if $direction != default { @include -neat-warn("The omega mixin will no longer take a $direction argument. To change the layout direction, use the direction(){...} mixin."); diff --git a/app/assets/stylesheets/grid/_private.scss b/app/assets/stylesheets/grid/_private.scss index b1953368..4c4e18c1 100644 --- a/app/assets/stylesheets/grid/_private.scss +++ b/app/assets/stylesheets/grid/_private.scss @@ -3,7 +3,7 @@ $fg-column: $column; $fg-gutter: $gutter; $fg-max-columns: $grid-columns; $container-display-table: false !default; -$layout-direction: nil !default; +$layout-direction: LTR !default; @function flex-grid($columns, $container-columns: $fg-max-columns) { $width: $columns * $fg-column + ($columns - 1) * $fg-gutter; @@ -31,13 +31,5 @@ $layout-direction: nil !default; } @function is-display-table($container-is-display-table, $display) { - $display-table: false; - - @if $container-is-display-table == true { - $display-table: true; - } @else if $display == table { - $display-table: true; - } - - @return $display-table; + @return $container-is-display-table == true or $display == table; } diff --git a/app/assets/stylesheets/grid/_visual-grid.scss b/app/assets/stylesheets/grid/_visual-grid.scss index f06deb80..9a99bfb7 100644 --- a/app/assets/stylesheets/grid/_visual-grid.scss +++ b/app/assets/stylesheets/grid/_visual-grid.scss @@ -30,7 +30,7 @@ } @each $breakpoint in $visual-grid-breakpoints { - @if $breakpoint != nil { + @if $breakpoint { @include media($breakpoint) { @include grid-column-gradient(gradient-stops($grid-columns)); }