Skip to content

Instantly share code, notes, and snippets.

@kaelig
Created August 18, 2015 15:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaelig/23444f2f5a9b4eb211dc to your computer and use it in GitHub Desktop.
Save kaelig/23444f2f5a9b4eb211dc to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
// ----
// libsass (v3.2.5)
// ----
$o-grid-layouts: (A: 340px, X: 800px, Y: 1100px, Z: 1200px);
$_o-grid-layout-names: A, X, Y, Z;
$o-grid-gutters: (default: 10px);
@mixin oGridAddLayout($layout-name, $layout-width, $gutter-width: null) {
$temp-layouts: ();
$temp-gutters: ();
// Add the new layout in the correct position:
// (we want $o-grid-layouts and $o-grid-gutters to ordered from the smallest to the largest layout)
@for $index from 1 through length($o-grid-layouts) {
$previous-layout-width: if($index == 1, 0, map-get($o-grid-layouts, nth($_o-grid-layout-names, $index - 1)));
$current-layout-name: nth($_o-grid-layout-names, $index);
$current-layout-width: map-get($o-grid-layouts, $current-layout-name);
$current-gutter-width: map-get($o-grid-gutters, $current-layout-name);
@if not ($previous-layout-width > $layout-width or $current-layout-width < $layout-width) {
$temp-layouts: map-merge($temp-layouts, ($layout-name: $layout-width));
$temp-gutters: map-merge($temp-gutters, ($layout-name: $gutter-width));
}
$temp-layouts: map-merge($temp-layouts, ($current-layout-name: $current-layout-width));
$temp-gutters: map-merge($temp-gutters, ($current-layout-name: $current-gutter-width));
}
$o-grid-layouts: $temp-layouts !global;
$_o-grid-layout-names: map-keys($o-grid-layouts) !global;
@if $gutter-width {
$o-grid-gutters: map-merge($o-grid-gutters, $temp-gutters) !global;
}
$_o-grid-max-width: map-get($o-grid-layouts, nth($_o-grid-layout-names, -1)) !global;
}
@function oGridGutter($layout-name: 'default') {
@if map-has-key($o-grid-gutters, $layout-name) {
@return $layout-name + " key found in $o-grid-gutters. Has a value: " + (map-get($o-grid-gutters, $layout-name) != null);
}
$layout-index: index($_o-grid-layout-names, $layout-name);
// The first layout (S) should get the default gutter
@if $layout-index == 1 {
@return oGridGutter();
}
$layout: nth($_o-grid-layout-names, $layout-index - 1);
@return oGridGutter($layout);
}
@include oGridAddLayout($layout-name: B, $layout-width: 365px, $gutter-width: 30px);
/* $o-grid-gutters: #{inspect($o-grid-gutters)} */
test {
content: "#{oGridGutter(B)}";
/* WAT */
content: "#{oGridGutter(A)}";
content: "#{oGridGutter(Z)}";
}
/* $o-grid-gutters: (default: 10px, B: 30px) */
test {
content: "B key found in $o-grid-gutters. Has a value: true";
/* WAT */
content: "A key found in $o-grid-gutters. Has a value: false";
content: "Z key found in $o-grid-gutters. Has a value: false";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment