def table_filters
      <<-HTML if table_builder.filters
        <div class='table-filters'>
          <h3>Filters</h3>
          #{table_builder.filters.map do |filter|
            filter.display
          end.join("\n")}
          #{table_builder.clear_filter}
        </div>
      HTML
    end

    # create a table pagination object
    def table_pagination
      @table_pagination ||= TablePagination.new(options)
    end

    # find the class of the data passed in 
    def data_class
      data.first.class
    end

    # create the sortable headers from columns given
    def create_header
      order = options[:order].split(' ')
      table_columns.map do |column|
        if column.sortable
          if order[0] == column.sortable.to_s
            url = TableMe::UrlBuilder.url_for(options, order: "#{column.sortable.to_s} #{order[1].downcase == 'asc' ? 'desc' : 'asc'}")
            klass = order[1]
          else
            url = TableMe::UrlBuilder.url_for(options, order: "#{column.sortable.to_s} asc")
            klass = nil
          end
          "<th><a #{"class='#{klass}'" if klass} href='#{url}'>#{column.name.to_s.split('_').join(' ').titleize}</a></th>"
        else
          "<th>#{column.name.to_s.split('_').join(' ').titleize}</th>"
        end
      end.join.html_safe
    end

    # create table rows based on data for each row using columns as a template
    def table_rows
      data.map do |d|
        <<-HTML
          <tr class="#{cycle('odd', 'even')}">
            #{table_column_for(d)}
          </tr>
        HTML
      end.join.html_safe
    end

    # cycle through an array of items, for now this is for row striping
    # Row striping can be handled by css, so this might just get removed.
    def cycle *items
      @cycle_items = items if @cycle_items.nil? || @cycle_items.empty?
      @cycle_items.pop
    end

    # it would ne nicer to encapsulate this into the column class, but then we have
    # to set it up like a view so capture works. For now, I'll leave this here, I'm not
    # sure if the encapsulation is worth the overhead
    def table_column_for data
      table_columns.map do |column|
        "<td>#{column.content ? capture(data, &column.content) : data[column.name]}</td>"
      end.join
    end

    # create a table builder instance
    def table_builder
      @builder ||= TableMe::Builder.new(options)
    end

    # get column names from the table_builder
    def col_names
      table_builder.names
    end

    # get table columns from the table_builder
    def table_columns
      table_builder.columns
    end

    # pass in the block given to the table_for_presenter if it exists
    # else just create a column for every column in the data object
    def process_data_attributes
      if @block
        capture(table_builder, &@block)
        if table_builder.columns.empty?
          build_all_columns
        end
      else
        build_all_columns
      end
    end

    # create a column for every column in the data object
    def build_all_columns
      data.first.attribute_names.each do |attribute|
        table_builder.column(attribute)
      end 
    end

  end
def table_filters
      <<-HTML if table_builder.filters
        <div class='table-filters'>
          <h3>Filters</h3>
          #{table_builder.filters.map do |filter|
            filter.display
          end.join("\n")}
          #{table_builder.clear_filter}
        </div>
      HTML
    end

    # create a table pagination object
    def table_pagination
      @table_pagination ||= TablePagination.new(options)
    end

    # find the class of the data passed in 
    def data_class
      data.first.class
    end

    # create the sortable headers from columns given
    def create_header
      order = options[:order].split(' ')
      table_columns.map do |column|
        if column.sortable
          if order[0] == column.sortable.to_s
            url = TableMe::UrlBuilder.url_for(options, order: "#{column.sortable.to_s} #{order[1].downcase == 'asc' ? 'desc' : 'asc'}")
            klass = order[1]
          else
            url = TableMe::UrlBuilder.url_for(options, order: "#{column.sortable.to_s} asc")
            klass = nil
          end
          "<th><a #{"class='#{klass}'" if klass} href='#{url}'>#{column.name.to_s.split('_').join(' ').titleize}</a></th>"
        else
          "<th>#{column.name.to_s.split('_').join(' ').titleize}</th>"
        end
      end.join.html_safe
    end

    # create table rows based on data for each row using columns as a template
    def table_rows
      data.map do |d|
        <<-HTML
          <tr class="#{cycle('odd', 'even')}">
            #{table_column_for(d)}
          </tr>
        HTML
      end.join.html_safe
    end

    # cycle through an array of items, for now this is for row striping
    # Row striping can be handled by css, so this might just get removed.
    def cycle *items
      @cycle_items = items if @cycle_items.nil? || @cycle_items.empty?
      @cycle_items.pop
    end

    # it would ne nicer to encapsulate this into the column class, but then we have
    # to set it up like a view so capture works. For now, I'll leave this here, I'm not
    # sure if the encapsulation is worth the overhead
    def table_column_for data
      table_columns.map do |column|
        "<td>#{column.content ? capture(data, &column.content) : data[column.name]}</td>"
      end.join
    end

    # create a table builder instance
    def table_builder
      @builder ||= TableMe::Builder.new(options)
    end

    # get column names from the table_builder
    def col_names
      table_builder.names
    end

    # get table columns from the table_builder
    def table_columns
      table_builder.columns
    end

    # pass in the block given to the table_for_presenter if it exists
    # else just create a column for every column in the data object
    def process_data_attributes
      if @block
        capture(table_builder, &@block)
        if table_builder.columns.empty?
          build_all_columns
        end
      else
        build_all_columns
      end
    end

    # create a column for every column in the data object
    def build_all_columns
      data.first.attribute_names.each do |attribute|
        table_builder.column(attribute)
      end 
    end

  end
create table filters if they exist