Skip to content

Instantly share code, notes, and snippets.

@rondale-sc
Created March 22, 2012 04:25
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 rondale-sc/2155905 to your computer and use it in GitHub Desktop.
Save rondale-sc/2155905 to your computer and use it in GitHub Desktop.
ruby-loves-sass-gists
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
$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