Last active
August 29, 2015 14:07
-
-
Save Undistraction/a53e1eb3431c2d3de5cd to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ---- | |
// Sass (v3.4.4) | |
// Compass (v1.0.1) | |
// ---- | |
// LIB | |
// ------------------------------------------------------------------------- | |
@function core-process-to-four-values($values) { | |
$length: length($values); | |
// Convert all values to 4 values | |
@if $length < 4 { | |
@if length($values) == 3 { | |
// (T,L+R,B) We need to add the 2nd prop again as the last prop | |
$values: append($values, nth($values, 2)); | |
} @else if $length == 2 { | |
// (T+B, L+R) We need to duplicate | |
$values: append($values, $values); | |
} @else { | |
// (T+R+B+L) We need to duplicate 4 times | |
$values: append($values, $values, $values, $values); | |
} | |
} | |
@return $values; | |
} | |
// Process value if it isn't already a valid number | |
@function core-process-value($value, $orientation) { | |
@if core-should-parse-value($value) { | |
$value: core-parse-value-filter($value); | |
$value: core-resolve-value-filter($value, $orientation); | |
} | |
@return $value; | |
} | |
@function core-process-values($values) { | |
$values: core-process-to-four-properies($values); | |
$processed-values: (); | |
$orientation: vertical; | |
@each $value in $values { | |
@if core-should-parse-value($value) { | |
$value: core-parse-value-filter($value); | |
$value: core-resolve-value-filter($value, $orientation); | |
} | |
$processed-values: append($processed-values, $value); | |
} | |
@return $processed-values; | |
} | |
// 1. Check if the value maps to one of our keywords and if so, swap out the value | |
// This is just a hook to be overridden. By default we just pass back the value | |
@function core-parse-value-filter($value){ | |
@return $value; | |
} | |
// 2. Check if the resolved value is unitless. If so multiply the value by the rhythm | |
// unit we are using | |
// This is just a hook to be overridden. By default we just pass back the value | |
@function core-resolve-value-filter($value, $orientation){ | |
@return $value; | |
} | |
@mixin padding($value) { | |
$value: core-process-values($value); | |
padding: #{$value}; | |
} | |
@mixin padding-top($value) { | |
$value: core-process-value($value, vertical); | |
padding-top: #{$value}; | |
} | |
@mixin padding-right($value) { | |
$value: core-process-value($value, horizontal); | |
padding-right: #{$value}; | |
} | |
@mixin padding-bottom($value) { | |
$value: core-process-value($value, vertical); | |
padding-bottom: #{$value}; | |
} | |
@mixin padding-left($value) { | |
$value: core-process-value($value, horizontal); | |
padding-left: #{$value}; | |
} | |
// UTIL | |
// ------------------------------------------------------------------------- | |
$core-valid-unitless-values: "auto" "initial" "inherit" 0; | |
@function core-should-parse-value($value){ | |
@return core-is-valid-unitless($value) or core-is-number_with_unit($value); | |
} | |
@function core-is-valid-unitless($value) { | |
@return not not index($core-valid-unitless-values, $value); | |
} | |
@function core-is-number_with_unit($value) { | |
@return not (type-of($value) == "number" and not unitless($value)); | |
} | |
// Test Defaults | |
// ------------------------------------------------------------------------- | |
.Default-padding-top { | |
@include padding-top(10px); | |
} | |
.Default-padding-right { | |
@include padding-right(10px); | |
} | |
// APP | |
// ------------------------------------------------------------------------- | |
$rhythm-units-map: ( | |
single: 1, | |
double: 2, | |
triple: 3, | |
quadruple: 4, | |
half: 0.5, | |
third: 0.33333333333, | |
quarter: 0.25 | |
); | |
$rhythm-map: ( | |
vertical: 12px, | |
horizontal: 16px | |
); | |
// If the value isn't a united number or a known keyword, look up the keyword | |
// in the $rhythm-units-map (which will resolve to a unitless number) | |
@function core-parse-value-filter($key){ | |
@if map-has-key($rhythm-units-map, $key) { | |
@return map-get($rhythm-units-map, $key); | |
} @else { | |
@error 'Unsupported key'; | |
} | |
} | |
// Multiply the unitless number with the appropriate rhythm-unit | |
// in the $rhythm-units-map (depending on vertical or horizontal orientation) | |
@function core-resolve-value-filter($value, $orientation){ | |
@return map-get($rhythm-map, $orientation) * $value; | |
} | |
// Test Custom | |
// ------------------------------------------------------------------------- | |
.padding-top { | |
@include padding-top(single); | |
} | |
.padding-right { | |
@include padding-right(single); | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.Default-padding-top { | |
padding-top: 10px; | |
} | |
.Default-padding-right { | |
padding-right: 10px; | |
} | |
.padding-top { | |
padding-top: 12px; | |
} | |
.padding-right { | |
padding-right: 16px; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment