Sha256: 2ec058409fc2b303438fe4e96e88fc2cb2e3ff2f4fb4fa322afcac44c6e6b7e8

Contents?: true

Size: 1.07 KB

Versions: 1

Compression:

Stored size: 1.07 KB

Contents

module SimpleTableFor
  module Helpers
    # Creates a table field
    # See table_for for details
    def field(content, options = {})
      content_tag :td, content, options
    end

    # Creates a table
    # Usage:
    #   <%= table_for @posts, %w[Title Text Date Comments\ count -] do |post| %>
    #     <%= field post.title %>
    #     <%= field post.text %>
    #     <%= field post.date %>
    #     <%= field post.comments.count %>
    #     <%= field link_to('View', post) %>
    #   <% end %>
    def table_for(collection, headers, options = {})
      options = Defaults.get.merge options

      content_tag :table, options do
        concat (content_tag :thead do
          content_tag :tr do
            headers.map do |header|
              concat(content_tag :th, header)
            end
          end
        end)

        concat (content_tag :tbody do
          collection.map do |obj|
            concat (content_tag :tr do
              capture{ yield obj }
            end)
          end
        end)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
simple_table_for-0.2.0 lib/simple_table_for/helpers.rb