Skip to content

Instantly share code, notes, and snippets.

@agius
Created December 3, 2012 23:46
Show Gist options
  • Save agius/4199131 to your computer and use it in GitHub Desktop.
Save agius/4199131 to your computer and use it in GitHub Desktop.
Gridify app helper
def gridify(collection, partial, opts = {})
rows = []
coll_copy = collection.dup
cols = opts[:cols] || 3
begin
row = []
cols.times { row << coll_copy.shift }
row.compact!
rows << row
end while coll_copy.present?
width = opts[:col_width] || 3
output = ""
rows.each do |row|
output << "<div class='row-fluid'>\n"
row.each do |col|
output << "<div class='span#{width}'>\n"
output << render({partial: partial, object: col}.merge(opts))
output << "\n</div>"
end
output << "\n</div>"
end
output.html_safe
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment