Created
September 6, 2011 16:15
-
-
Save rondale-sc/1198026 to your computer and use it in GitHub Desktop.
insert_grid Sass function
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment