Class: TableCollectionRenderer::Header

Inherits:
Object
  • Object
show all
Defined in:
app/collection_renderers/table_collection_renderer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource_class, helper) ⇒ Header

Returns a new instance of Header.



6
7
8
9
10
# File 'app/collection_renderers/table_collection_renderer.rb', line 6

def initialize(resource_class, helper)
  @resource_class, @helper = resource_class, helper
  @controller = helper.instance_variable_get('@_controller')
  @view_context = @controller.view_context
end

Instance Attribute Details

#controllerObject

Returns the value of attribute controller.



3
4
5
# File 'app/collection_renderers/table_collection_renderer.rb', line 3

def controller
  @controller
end

#helperObject Also known as: h

Returns the value of attribute helper.



3
4
5
# File 'app/collection_renderers/table_collection_renderer.rb', line 3

def helper
  @helper
end

#resource_classObject

Returns the value of attribute resource_class.



3
4
5
# File 'app/collection_renderers/table_collection_renderer.rb', line 3

def resource_class
  @resource_class
end

#view_contextObject

Returns the value of attribute view_context.



3
4
5
# File 'app/collection_renderers/table_collection_renderer.rb', line 3

def view_context
  @view_context
end

Instance Method Details

#acts_as_list_actions(options = {}) ⇒ Object



54
55
56
# File 'app/collection_renderers/table_collection_renderer.rb', line 54

def acts_as_list_actions(options = {})
  column(:acts_as_published_actions)
end

#acts_as_published_actionsObject



50
51
52
# File 'app/collection_renderers/table_collection_renderer.rb', line 50

def acts_as_published_actions
  column(:acts_as_published_actions)
end

#association(*args, &block) ⇒ Object



18
19
20
21
22
# File 'app/collection_renderers/table_collection_renderer.rb', line 18

def association(*args, &block)
  options = args.extract_options!
  options[:as] = :association   
  column(*args, options, &block)
end

#column(attribute_name, options = {}) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'app/collection_renderers/table_collection_renderer.rb', line 24

def column(attribute_name, options = {})
  return column_with_sorting(attribute_name, options) if ransack_query.present? && options.has_key?(:sortable) && options[:sortable] != false

  label = if @resource_class.respond_to?(:human_attribute_name)
    @resource_class.human_attribute_name(attribute_name)
  else
    attribute_name
  end
  helper.(:th, label, id: "table-header-#{attribute_name}")
end

#columnsObject



35
36
37
38
39
# File 'app/collection_renderers/table_collection_renderer.rb', line 35

def columns
  resource_class.attribute_names.collect do |name|
    column name
  end.join.html_safe
end

#render(&block) ⇒ Object



12
13
14
15
16
# File 'app/collection_renderers/table_collection_renderer.rb', line 12

def render(&block)
  helper.(:tr) do
    block.call(self)
  end
end

#timestampsObject



41
42
43
44
# File 'app/collection_renderers/table_collection_renderer.rb', line 41

def timestamps
  column(:created_at, sortable: true) +
  column(:updated_at, sortable: true)
end

#userstampsObject



46
47
48
49
# File 'app/collection_renderers/table_collection_renderer.rb', line 46

def userstamps
  column(:creator, sortable: true) +
  column(:updater, sortable: true)
end