Skip to content

Instantly share code, notes, and snippets.

@rafapolo
Last active August 29, 2015 14:07
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 rafapolo/817c28addb41f1859ca9 to your computer and use it in GitHub Desktop.
Save rafapolo/817c28addb41f1859ca9 to your computer and use it in GitHub Desktop.
define número de elementos por colunas
# backend
def category_itens_per_col(total)
return case total
when 0..3 then 1
when 4..6 then 2
when 7..9 then 3
else 4
end
end
# frontend
- itens = category_itens_per_col(Category.count)
- Category.all.each_slice(itens) do |cs|
.col
- i = 0
- cs.each do |c|
%p{style:'padding:10px'}
= set_spacing(i)
%a{href: url_to_category(c), class: 'category_item', img: c.image.url(:regular)}= c.name
- i+=1
# css
.col
margin-left: 60px
display: inline-block
vertical-align: text-top
@rafapolo
Copy link
Author

set_spacing(3) => "   "

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment