Sha256: 297025ad53b8e2c0947962fb4ccd1b144f1009d7bb0f764f68518ec264bfff47

Contents?: true

Size: 1.05 KB

Versions: 4

Compression:

Stored size: 1.05 KB

Contents

module TableCloth
  module Presenters
    class Default < ::TableCloth::Presenter
      def render_table
        wrapper_tag :table do
          render_header + render_rows
        end
      end

      def render_rows
        wrapper_tag :tbody do
          v.raw objects.inject('') {|r, object| r + render_row(object) }
        end
      end

      def render_row(object)
        wrapper_tag :tr do
          v.raw columns.inject('') {|tds, column| tds + render_td(column, object) }
        end
      end

      def render_td(column, object)
        td_options = column.options[:td_options] || {}
        value = column.value(object, view_context, table)

        if value.is_a?(Array)
          options = value.pop
          value   = value.shift

          td_options.update(options)
        end

        wrapper_tag(:td, value, td_options)
      end

      def render_header
        wrapper_tag :thead do
          wrapper_tag :tr do
            v.raw column_names.inject('') {|tags, name| tags + wrapper_tag(:th, name) }
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
table_cloth-0.3.1.alpha1 lib/table_cloth/presenters/default.rb
table_cloth-0.3.0.beta3 lib/table_cloth/presenters/default.rb
table_cloth-0.3.0.beta2 lib/table_cloth/presenters/default.rb
table_cloth-0.3.0.beta1 lib/table_cloth/presenters/default.rb