From 012dcf2489d0fe541d9ed788708adcfa347821ca Mon Sep 17 00:00:00 2001 From: Ian Rose Date: Tue, 4 Nov 2014 08:16:27 -0500 Subject: [PATCH 1/4] adds floating point warn --- _typesettings.scss | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/_typesettings.scss b/_typesettings.scss index 2c8601d..a6874aa 100644 --- a/_typesettings.scss +++ b/_typesettings.scss @@ -81,10 +81,18 @@ $ms-up2: $ms-up1 * $ms-ratio; // [5] $ms-up3: $ms-up2 * $ms-ratio; // [6] $ms-up4: $ms-up3 * $ms-ratio; // [7] +// Warning message text for when an integer is not used in rhythm functions +$float-point-warn: 'Vertical Rhythm is broken, use an interger (whole) not float (decimal) for $lines'; + //============================================================================== // Helper function(s) //============================================================================== +// Check if value is a floating point number and returns true or false +@function is-float($value) { + @return type-of($value) == number and floor(abs($value)) != abs($value); +} + // Returns a number without a unit. For example 16px becomes 16 @function stripUnits($number) { @return $number / ($number * 0 + 1); @@ -98,12 +106,18 @@ $ms-up4: $ms-up3 * $ms-ratio; // [7] // Returns an EM value that is a multiple of our defined base vertical unit. For // example 3 becomes 1.125em @function emRhythm($lines: $base-vertical-unit, $font-size: $base-em-font-size) { + @if(is-float($lines)) { + @warn $float-point-warn; + } @return (stripUnits($lines) * stripUnits($base-vertical-unit)) / (stripUnits($font-size) * stripUnits($base-font-size)) + 0em; } // Returns a unitless number that is a multiple of our defined base vertical unit. // For example 3 becomes 1.125 @function unitlessRhythm($lines: $base-line-multi, $font-size: $base-em-font-size) { + @if(is-float($lines)) { + @warn $float-point-warn; + } @return ($lines * stripUnits($base-vertical-unit)) / (stripUnits($font-size) * stripUnits($base-font-size)); } From 3889a233d41aa450bf51085a844d63eb848f361a Mon Sep 17 00:00:00 2001 From: Ian Rose Date: Tue, 4 Nov 2014 10:56:58 -0500 Subject: [PATCH 2/4] test if value is an integer or not --- _typesettings.scss | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/_typesettings.scss b/_typesettings.scss index a6874aa..5516485 100644 --- a/_typesettings.scss +++ b/_typesettings.scss @@ -82,15 +82,15 @@ $ms-up3: $ms-up2 * $ms-ratio; // [6] $ms-up4: $ms-up3 * $ms-ratio; // [7] // Warning message text for when an integer is not used in rhythm functions -$float-point-warn: 'Vertical Rhythm is broken, use an interger (whole) not float (decimal) for $lines'; +$not-integer-txt: ' value breaks vertical rhythm. Use an interger (whole number) for $lines.'; //============================================================================== // Helper function(s) //============================================================================== -// Check if value is a floating point number and returns true or false -@function is-float($value) { - @return type-of($value) == number and floor(abs($value)) != abs($value); +// Check if value is an integer and returns true or false +@function is-int($number) { + @return type-of($number) == number and floor(abs($number)) == abs($number); } // Returns a number without a unit. For example 16px becomes 16 @@ -106,8 +106,8 @@ $float-point-warn: 'Vertical Rhythm is broken, use an interger (whole) not float // Returns an EM value that is a multiple of our defined base vertical unit. For // example 3 becomes 1.125em @function emRhythm($lines: $base-vertical-unit, $font-size: $base-em-font-size) { - @if(is-float($lines)) { - @warn $float-point-warn; + @if is-int($lines) == false { + @warn #{$lines} + $not-integer-txt; } @return (stripUnits($lines) * stripUnits($base-vertical-unit)) / (stripUnits($font-size) * stripUnits($base-font-size)) + 0em; } @@ -115,8 +115,8 @@ $float-point-warn: 'Vertical Rhythm is broken, use an interger (whole) not float // Returns a unitless number that is a multiple of our defined base vertical unit. // For example 3 becomes 1.125 @function unitlessRhythm($lines: $base-line-multi, $font-size: $base-em-font-size) { - @if(is-float($lines)) { - @warn $float-point-warn; + @if is-int($lines) == false { + @warn #{$lines} + $not-integer-txt; } @return ($lines * stripUnits($base-vertical-unit)) / (stripUnits($font-size) * stripUnits($base-font-size)); } From ec7127c714b60b96ca5a743a917b46f9e51df5b5 Mon Sep 17 00:00:00 2001 From: Ian Rose Date: Sun, 9 Nov 2014 08:14:03 -0500 Subject: [PATCH 3/4] updated comment --- _typesettings.scss | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_typesettings.scss b/_typesettings.scss index 5516485..d6b7c40 100644 --- a/_typesettings.scss +++ b/_typesettings.scss @@ -81,7 +81,7 @@ $ms-up2: $ms-up1 * $ms-ratio; // [5] $ms-up3: $ms-up2 * $ms-ratio; // [6] $ms-up4: $ms-up3 * $ms-ratio; // [7] -// Warning message text for when an integer is not used in rhythm functions +// Warning text for when an integer is not used in rhythm functions $not-integer-txt: ' value breaks vertical rhythm. Use an interger (whole number) for $lines.'; //============================================================================== From d87ac8aa14fc4414b4fd4a577da781a0cbdd1bf7 Mon Sep 17 00:00:00 2001 From: Ian Rose Date: Sun, 9 Nov 2014 08:14:16 -0500 Subject: [PATCH 4/4] added floating number to test --- test/test.css | 3 +++ test/test.scss | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/test/test.css b/test/test.css index 5e0d79a..a8dd60f 100644 --- a/test/test.css +++ b/test/test.css @@ -158,3 +158,6 @@ hr { border-top-style: solid; border-top-width: 1px; padding-top: 1.4375em; } + +.div { + margin-bottom: 0.45em; } diff --git a/test/test.scss b/test/test.scss index cdd8df7..eb55087 100644 --- a/test/test.scss +++ b/test/test.scss @@ -1 +1,5 @@ -@import "../typesettings"; \ No newline at end of file +@import "../typesettings"; + +.div { + margin-bottom: emRhythm(1.2); +}