Class: SimpleDataPresentation::SimpleTable::Head

Inherits:
Base
  • Object
show all
Defined in:
lib/simple_data_presentation/simple_table/head.rb

Instance Method Summary collapse

Methods inherited from Base

#item, #value

Constructor Details

#initialize(context, resource_class, options = {}, &content_block) ⇒ Head

Returns a new instance of Head.



2
3
4
5
6
7
8
# File 'lib/simple_data_presentation/simple_table/head.rb', line 2

def initialize(context, resource_class, options = {}, &content_block)
  @context = context
  @options = options
  @resource_class = resource_class
  @search = @context.instance_variable_get(:"@search") if @context.instance_variable_get(:"@search").present? && @context.instance_variable_get(:"@search").klass == @resource_class
  @content_block = content_block
end

Instance Method Details

#render!Object



30
31
32
33
# File 'lib/simple_data_presentation/simple_table/head.rb', line 30

def render!
  content = @context.capture self, &@content_block
  @context.raw @context. :thead, @context.(:tr, content, (@options[:row_html])), @options[:html]
end

#title(*args, &block) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/simple_data_presentation/simple_table/head.rb', line 10

def title(*args, &block)
  options = args.extract_options!
  content = if block.present?
    @context.capture(@resource_class, &block)
  else
    sort_attribute = options[:sort_by] || (args.any? ? args.join("_").to_sym : nil)
    label = if options[:label].is_a?(Symbol)
      @resource_class.human_attribute_name options[:label]
    elsif !options[:label].nil?
      options[:label]
    elsif sort_attribute.present?
      label = @resource_class.human_attribute_name sort_attribute
      abbr_label = @resource_class.human_attribute_name "#{sort_attribute}_abbr", default: ""
      abbr_label.present? ? @context.(:abbr, abbr_label, title: label) : label
    end
    !@search.nil? && options[:sortable] != false ? @context.sort_link(@search, sort_attribute, label) : label
  end
  @context. :th, content, options[:html]
end