Skip to content

Instantly share code, notes, and snippets.

@rondale-sc
Created September 6, 2011 16:15
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/1198026 to your computer and use it in GitHub Desktop.
Save rondale-sc/1198026 to your computer and use it in GitHub Desktop.
insert_grid Sass function
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