<% table.define :table do |options| %> <%= content_tag :table, options[:table_html] do %> <%= table.render :header %> <%= table.render :body %> <%# Purposely no default implementation for the tfoot block given, since most tables do not have footers (provided to for easy hook to add a footer). %> <%= table.render :footer %> <% end %> <% end %> <% table.define :header do |options| %> <%= table.content_tag_with_block options[:thead_tag], options[:thead_html] do %> <%= table.render :header_row %> <% end %> <% end %> <% table.define :header_row do |options| %> <%= content_tag :tr, options[:header_row_html] do %> <%= table.render :header_column, :collection => table.columns %> <% end %> <% end %> <% table.define :header_column do |column, options| %> <%= content_tag :th, table.header_column_html(column, options) do %> <%= table.render "#{column.name}_header", column, column.options %> <% end %> <% end %> <%# Define a header block for each column, named using that column's name with the word "_header" appended to it %> <% table.define lambda {|column| "#{column.name}_header" }, :collection => table.columns do |column, options| %> <%= table.header_cell_content(column, options) %> <% end %> <% table.define :body do |options| %> <%= table.content_tag_with_block options[:tbody_tag], options[:tbody_html] do %> <%= table.render :data_row, :collection => records %> <% end %> <% end %> <% table.define :data_row do |record, options| %> <% table.set_current_record(record) %> <%= content_tag :tr, table.call_each_hash_value_with_params(options[:data_row_html], record) do %> <%= table.render :data_column, record, :collection => table.columns %> <% end %> <% end %> <% table.define :data_column do |column, record, options| %> <%= content_tag :td, table.call_each_hash_value_with_params(options[:data_column_html], record, column) do %> <%= table.render column.name, record, column, column.options %> <% end %> <% end %> <%# Define a block for each column, named using that column's name %> <% table.define lambda {|column| column.name }, :collection => table.columns, :link_html => {} do |record, column, options| %> <%= table.cell_content(record, column, options) %> <% end %> <% table.define :footer do |options| %> <%= table.content_tag_with_block options[:tfoot_tag], options[:tfoot_html] do %> <%= table.render :footer_row %> <% end %> <% end if table.defined?(:footer_content) %> <% table.define :footer_row do |options| %> <%= content_tag :tr, options[:footer_row_html] do %> <%= table.render :footer_column %> <% end %> <% end if table.defined?(:footer_content) %> <% table.define :footer_column do |options| %> <%= content_tag :td, {:colspan => table.columns.length}.merge(table.blocks[:footer_content].options[:footer_column_html] || {}) do %> <%= table.render :footer_content %> <% end %> <% end if table.defined?(:footer_content) %> <%= table.render :table %>