<% table.define :table do |options| %> <%= content_tag :table, options[:table_html] do %> <%= table.render :thead %> <%= table.render :tbody %> <% end %> <% end %> <% table.define :thead do |options| %> <%= content_tag :thead, 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_columns %> <% end %> <% end %> <% table.define :header_columns do |options| %> <% table.columns.each do |column| %> <%= table.render :header_column, column, column.options %> <% end %> <% end %> <% table.define :header_column do |column, options| %> <%= content_tag :th, table_for_header_html(column, options) do %> <%= table.render "#{column.name}_header", column, column.options %> <% end %> <% end %> <% table.define :edit_header do %><% end %> <% table.define :show_header do %><% end %> <% table.define :delete_header do %><% end %> <% table.columns.each do |column| %> <% table.define "#{column.name}_header" do |column, options| %> <% if options[:sortable] %> <%= table_for_sort_link(column, options) %> <% else %> <%= options[:label] ? options[:label] : column.name.to_s.titleize %> <% end %> <% end %> <% end %> <% table.define :tbody do |options| %> <%= content_tag :tbody, options[:tbody_html] do %> <%= table.render :rows %> <% end %> <% end %> <% table.define :rows do |options| %> <% records.each do |record| %> <%= table.render :row, record %> <% end %> <% end %> <% table.define :row do |record, options| %> <%= content_tag :tr, table_for_evaluated_options(record, options[:row_html]) do %> <%= table.render :columns, record %> <% end %> <% end %> <% table.define :columns do |record, options| %> <% table.columns.each do |column| %> <%= table.render :column, record, column, column.options %> <% end %> <% end %> <% table.define :column do |record, column, options| %> <%= content_tag :td, table_for_evaluated_options(record, column, options[:column_html]) do %> <%= table.render column.name, record, column, column.options %> <% end %> <% end %> <% table.define :edit, :action => :edit, :link_label => "Edit" do |record, column, options| %> <%= link_to options[:link_label], [options[:action], options[:scope], record].flatten, options[:link_html] %> <% end %> <% table.define :show, :action => nil, :link_label => "Show" do |record, column, options| %> <%= link_to options[:link_label], [options[:action], options[:scope], record].flatten, options[:link_html] %> <% end %> <% table.define :delete, :action => nil, :link_html => {}, :link_label => "Delete" do |record, column, options| %> <% confirm = options[:confirm] ? options[:confirm] : "Are you sure you want to delete this #{record.class.to_s.titleize}?" %> <% method = options[:method] ? options[:method] : "delete" %> <%= link_to options[:link_label], [options[:action], options[:scope], record].flatten, {:method => method, :confirm => confirm}.merge(options[:link_html]) %> <% end %> <% table.columns.each do |column| %> <% table.define "#{column.name}" do |record, column, options| %> <%= record.send(column.name) %> <% end %> <% end %> <%= table.render :table %>