Sha256: 6adfea7ac3b9939b51c2a76cebed2c01a4066edb6081fbe3f8156328f7ea72b8

Contents?: true

Size: 1.33 KB

Versions: 40

Compression:

Stored size: 1.33 KB

Contents

module Manage
  module ApplicationHelper

    def collection_table collection, resource_class, no_items_text

      if collection.empty?
        return content_tag(:h3, resource_class.model_name.human(count: 2)) + content_tag(:p,  no_items_text)
      else
        rows = []

        ths = resource_class.attribute_names.collect do |attr|
          content_tag(:td, truncate(resource_class.human_attribute_name(attr).to_s, length: 50))
        end.join('').html_safe
        rows << content_tag(:tr, ths)

        collection.each do |item|
          tds = resource_class.attribute_names.collect do |attr|
            content_tag(:td, truncate(item.public_send(attr).to_s, length: 50))
          end.join('').html_safe

          rows << content_tag(:tr, tds)
        end
        content_tag(:h3, resource_class.model_name.human(count: 2)) +
        content_tag(:table, rows.join('').html_safe)
      end
    end

    def condensed_table resource_class, cols=2
      rows = []
      resource_class.attribute_names.each_slice(cols).each do |slice|
        row = slice.collect do |attr|
          content_tag(:td, resource_class.human_attribute_name(attr)) +
          content_tag(:td, resource.public_send(attr))
        end
        rows << content_tag(:tr, row.join('').html_safe)
      end

      content_tag :table, rows.join('').html_safe
    end

  end
end

Version data entries

40 entries across 40 versions & 1 rubygems

Version Path
manage-1.4.3 app/helpers/manage/application_helper.rb
manage-1.4.2 app/helpers/manage/application_helper.rb
manage-1.4.1 app/helpers/manage/application_helper.rb
manage-1.4 app/helpers/manage/application_helper.rb
manage-1.3.52 app/helpers/manage/application_helper.rb
manage-1.3.51 app/helpers/manage/application_helper.rb
manage-1.3.50 app/helpers/manage/application_helper.rb
manage-1.3.49 app/helpers/manage/application_helper.rb
manage-1.3.48 app/helpers/manage/application_helper.rb
manage-1.3.47 app/helpers/manage/application_helper.rb
manage-1.3.46 app/helpers/manage/application_helper.rb
manage-1.3.45 app/helpers/manage/application_helper.rb
manage-1.3.44 app/helpers/manage/application_helper.rb
manage-1.3.43 app/helpers/manage/application_helper.rb
manage-1.3.42 app/helpers/manage/application_helper.rb
manage-1.3.40 app/helpers/manage/application_helper.rb
manage-1.3.39 app/helpers/manage/application_helper.rb
manage-1.3.38 app/helpers/manage/application_helper.rb
manage-1.3.37 app/helpers/manage/application_helper.rb
manage-1.3.36 app/helpers/manage/application_helper.rb