def template
@template ||= @eruby.new <<-EOS
<%#encoding:UTF-8%><table<%= @id ? %( id="\#{@id}") : nil %> class="tableblock frame-<%= attr :frame, 'all' %> grid-<%= attr :grid, 'all'%><%= role? ? " \#{role}" : nil %>" style="<%
if !(option? 'autowidth') %>width:<%= attr :tablepcwidth %>%; <% end %><%
if attr? :float %>float: <%= attr :float %>; <% end %>"><%
if title? %>
<caption class="title"><%= captioned_title %></caption><%
end
if (attr :rowcount) >= 0 %>
<colgroup><%
if option? 'autowidth'
@columns.each do %>
<col><%
end
else
@columns.each do |col| %>
<col style="width:<%= col.attr :colpcwidth %>%;"><%
end
end %>
</colgroup><%
[:head, :foot, :body].select {|tsec| !@rows[tsec].empty? }.each do |tsec| %>
<t<%= tsec %>><%
@rows[tsec].each do |row| %>
<tr><%
row.each do |cell| %>
<<%= tsec == :head ? 'th' : 'td' %> class="tableblock halign-<%= cell.attr :halign %> valign-<%= cell.attr :valign %>"#{attribute('colspan', 'cell.colspan')}#{attribute('rowspan', 'cell.rowspan')}<%
cell_content = ''
if tsec == :head
cell_content = cell.text
else
case cell.style
when :asciidoc
cell_content = %(<div>\#{cell.content}</div>)
when :verse
cell_content = %(<div class="verse">\#{template.preserve_endlines(cell.text, self)}</div>)
when :literal
cell_content = %(<div class="literal"><pre>\#{template.preserve_endlines(cell.text, self)}</pre></div>)
when :header
cell.content.each do |text|
cell_content = %(\#{cell_content}<p class="tableblock header">\#{text}</p>)
end
else
cell.content.each do |text|
cell_content = %(\#{cell_content}<p class="tableblock">\#{text}</p>)
end
end
end %><%= (@document.attr? 'cellbgcolor') ? %( style="background-color:\#{@document.attr 'cellbgcolor'};") : nil
%>><%= cell_content %></<%= tsec == :head ? 'th' : 'td' %>><%
end %>
</tr><%
end %>
</t<%= tsec %>><%
end
end %>
</table>
EOS
end