Created
March 30, 2012 23:25
-
-
Save coderanger/2257853 to your computer and use it in GitHub Desktop.
Local grid support for Susy
This file contains 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
@import "susy"; | |
$grid-info-stack: (); | |
@function _stack_push($list, $item) { | |
@return join($item, $list); | |
} | |
@function _stack_top($list) { | |
@return nth($list, 1); | |
} | |
@function _stack_pop($list) { | |
@if length($list) <= 1 { @return (); } | |
$new-list: (); | |
@for $i from 2 through length($list) { | |
$new-list: join($new-list, nth($list, $i)) | |
} | |
@return $new-list; | |
} | |
@function local-grid($t:12, $w:4em, $g:1em, $sg:false) { | |
@if not $sg { | |
$sg: $g; | |
} | |
$grid-info-stack: _stack_push($grid-info-stack, $side-gutter-width); | |
$grid-info-stack: _stack_push($grid-info-stack, $gutter-width); | |
$grid-info-stack: _stack_push($grid-info-stack, $col-width); | |
$grid-info-stack: _stack_push($grid-info-stack, $total-cols); | |
$total-cols: $t; | |
$col-width: $w; | |
$gutter-width: $g; | |
$side-gutter-width: $sg; | |
@return 0; | |
} | |
@function local-grid-pop() { | |
$total-cols: _stack_top($grid-info-stack); | |
$grid-info-stack: _stack_pop($grid-info-stack); | |
$col-width: _stack_top($grid-info-stack); | |
$grid-info-stack: _stack_pop($grid-info-stack); | |
$gutter-width: _stack_top($grid-info-stack); | |
$grid-info-stack: _stack_pop($grid-info-stack); | |
$side-gutter-width: _stack_top($grid-info-stack); | |
$grid-info-stack: _stack_pop($grid-info-stack); | |
@return 0; | |
} | |
@mixin local-grid($t:12, $w:4em, $g:1em, $sg:false) { | |
$ignore: local-grid($t, $w, $g, $sg); | |
} | |
@mixin local-grid-pop { | |
$ignore: local-grid-pop(); | |
} | |
#testinggrid { | |
@include local-grid(6); | |
.a { width: columns-width(); } | |
@include local-grid(20); | |
.b { width: columns-width(); } | |
@include local-grid-pop; | |
.c { width: columns-width(); } | |
@include local-grid-pop; | |
.d { width: columns-width(); } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment