Created
December 3, 2012 23:46
-
-
Save agius/4199131 to your computer and use it in GitHub Desktop.
Gridify app helper
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
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