<% table.define :table do |options| %> <%= content_tag :table, options[:table_html] do %> <%= table.use :thead %> <%= table.use :tbody %> <% end %> <% end %> <% table.define :thead do |options| %> <%= content_tag :thead, options[:thead_html] do %> <%= table.use :header_row %> <% end %> <% end %> <% table.define :header_row do |options| %> <%= content_tag :tr, options[:header_row_html] do %> <%= table.use :header_columns %> <% end %> <% end %> <% table.define :header_columns do |options| %> <% table.columns.each do |column| %> <%= table.use :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.use "#{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.use :rows %> <% end %> <% end %> <% table.define :rows do |options| %> <% records.each do |record| %> <%= table.use :row, record %> <% end %> <% end %> <% table.define :row do |record, options| %> <%= content_tag :tr, table_for_evaluated_options(record, options[:row_html]) do %> <%= table.use :columns, record %> <% end %> <% end %> <% table.define :columns do |record, options| %> <% table.columns.each do |column| %> <%= table.use :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.use 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| %> <%= link_to options[:link_label], [options[:action], options[:scope], record].flatten, {:method => "delete", :confirm => "Are you sure you want to delete this #{record.class.to_s.titleize}?"}.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.use :table %>