class SimpleModelView::CollectionTableHeaderBuilder

Attributes

collection[R]
template[R]

Public Class Methods

new(template, collection) click to toggle source
# File lib/simple_model_view/collection_table_header_builder.rb, line 9
def initialize(template, collection)
  @template = template
  @collection = collection
end

Public Instance Methods

actions(*_args, **options) click to toggle source
# File lib/simple_model_view/collection_table_header_builder.rb, line 24
def actions(*_args, **options)
  th_html_attributes = merge_html_attrs default_header_html, options[:header_html].to_h
  template.content_tag :th, options[:title].to_s, **th_html_attributes
end
column(attr_name, *_args, **options) click to toggle source
# File lib/simple_model_view/collection_table_header_builder.rb, line 14
def column(attr_name, *_args, **options)
  title = options[:title]
  title ||= if collection_class
              collection_class.human_attribute_name attr_name
            else
              attr_name.to_s.humanize
            end
  template.content_tag :th, title, options[:header_html] || {}
end

Private Instance Methods

collection_class() click to toggle source
# File lib/simple_model_view/collection_table_header_builder.rb, line 31
def collection_class
  return @collection_class unless @collection_class.nil?

  @collection_class =
    if defined?(ActiveRecord::Relation) && collection.class < ActiveRecord::Relation
      collection.new.class
    else
      false
    end
end
default_header_html() click to toggle source
# File lib/simple_model_view/collection_table_header_builder.rb, line 42
def default_header_html
  SimpleModelView.collection_header_html
end