Created
March 22, 2012 04:25
-
-
Save rondale-sc/2155905 to your computer and use it in GitHub Desktop.
ruby-loves-sass-gists
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
module Sass::Script::Functions | |
def insert_grid(columns, width_string) | |
assert_type columns, :Number | |
assert_type width_string, :String | |
width = width_string.match(/\A(\d+)(\w+)\z/)[1] | |
type = width_string.match(/\A(\d+)(\w+)\z/)[2] | |
raise StandardError, "You must set width_string with unit ie '960px'. " unless ["px","em", "pt", "%"].include?(type) | |
grid, grid_segment_width = "", 0 | |
columns.times do |col| | |
grid += "grid_#{col + 1}: {width:#{grid_segment_width += (width.to_i / columns)}#{type}}\n" | |
end | |
grid += ".column {margin:0,10px;overflow:hidden;float:left;display:inline;}" | |
Sass::Script::String.new(grid) | |
end | |
end |
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
$grid-width: 960px !default; | |
$grid-columns: 12 !default; | |
@function grid-width($column, $columns: $grid-columns, $width: $grid-width) { | |
@return $width / $columns * $column; | |
} | |
@mixin insert-grid($columns: $grid-columns, $width: $grid-width, $base-class: "column") { | |
.#{$base-class} { | |
margin: 0 10px; | |
overflow: hidden; | |
float: left; | |
display: inline; | |
} | |
@for $c from 1 through $columns { | |
.grid_#{$c} { | |
width: grid-width($c, $columns, $width); | |
@extend .#{$base-class}; | |
} | |
} | |
} | |
@include insert-grid; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment