Translate RoR Code to Java
- by mnml
Hi, for some reasons I am trying to translate the following RoR view code to a Java Groovy view:
<%
modulo_artists = @artists.length % 3
base = @artists.length / 3
base = base.ceil
case modulo_artists
when 0
cols = [base, base, base]
when 1
cols = [base, base + 1, base]
when 2
cols = [base + 1, base, base + 1]
end
counter = 0
%>
<% id_hash = {"0" => "url('/images/actorsbg.png');", "1" => "url('/images/musiciansbg.png');", "2" => "url('/images/artistsbg.png') no-repeat; color: #FFF;", "3" => "url('/images/fashionbg.png')"} %>
<div id="artists_<%=params[:artist_cat]%>" style="background: <%= id_hash[params[:artist_cat]] %>;" >
<table border="0" width="660" height="164" cellpadding="0" cellspacing="0">
<tr valign="middle">
<% 3.times do |i| %>
<td width="220" align="center" style="padding-right: 15px;">
<% cols[i].times do %>
<h1><a href="/artists/show/<%= @artists[counter].urlname %>" ><%= @artists[counter].name %></a></h1>
<% counter = counter + 1 %>
<% end %>
</td>
<% end %>
</tr>
</table>
</div>
This is what I got so far:
#{extends 'main.html' /}
%{
modulo_artists = artists.size() % 3
base = artists.size() / 3
base = Math.ceil(base)
if(modulo_artists == 0)
cols = [base, base, base]
else if(modulo_artists == 1)
cols = [base, base + 1, base]
else if(modulo_artists == 2)
cols = [base + 1, base, base + 1]
endif
counter = 0
}%
<div id="artists_${artist_cat}" style="background:${id_hash};" >
<table border="0" width="660" height="164" cellpadding="0" cellspacing="0">
<tr valign="middle">
#{list items:1..3, as:'i'}
<td width="220" align="center" style="padding-right: 15px;">
#{list items:cols[i]}
<h1><a href="@{Artists.show(artists.get(counter).name.replaceAll(" ", "-"))}" >${artists.get(counter).name}</a></h1>
%{ counter = counter + 1 }%
#{/list}
</td>
#{/list}
</tr>
</table>
</div>
The idea is to keep the items organised in 3 columns like 1|0|1 4|5|4 or 5|4|5 for example