Class: TableResourceRenderer

Inherits:
ResourceRenderer::ResourceRenderer::Base show all
Defined in:
app/resource_renderers/table_resource_renderer.rb

Instance Attribute Summary

Attributes inherited from ResourceRenderer::ResourceRenderer::Base

#helper, #resource

Instance Method Summary collapse

Methods inherited from ResourceRenderer::ResourceRenderer::Base

#association, #display, #initialize, #resource_class

Constructor Details

This class inherits a constructor from ResourceRenderer::ResourceRenderer::Base

Instance Method Details

#acts_as_list_actions(options = {}) ⇒ Object



46
47
48
49
50
51
52
# File 'app/resource_renderers/table_resource_renderer.rb', line 46

def acts_as_list_actions(options = {})
  scope = options[:scope]

  column_options = { as: :acts_as_list }
  column_options[:scope] = scope if scope.present?
  column :acts_as_list_actions, column_options
end

#acts_as_published_actionsObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/resource_renderers/table_resource_renderer.rb', line 29

def acts_as_published_actions
  link_path = helper.controller.url_for(action: :toggle_published, id: resource.to_param)
  column(:published_actions) do |resource| 
    if resource.published?
      helper.link_to(link_path, class: 'btn btn-xs btn-danger btn-responsive', method: :post) do
        helper.(:span, nil, class: 'glyphicon glyphicon-eye-close') +
        helper.(:span, helper.t('.unpublish', default: helper.t('acts_as_published.actions.unpublish')), class: 'btn-text')
      end
    else
      helper.link_to(link_path, class: 'btn btn-xs btn-success btn-responsive', method: :post) do
        helper.(:span, nil, class: 'glyphicon glyphicon-eye-open') +
        helper.(:span, helper.t('.publish', default: helper.t('acts_as_published.actions.publish')), class: 'btn-text')
      end
    end
  end
end

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



2
3
4
# File 'app/resource_renderers/table_resource_renderer.rb', line 2

def column(attribute_name, options = {}, &block)
  build_table_data(attribute_name, options, &block)
end

#columnsObject



6
7
8
9
10
# File 'app/resource_renderers/table_resource_renderer.rb', line 6

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/resource_renderers/table_resource_renderer.rb', line 12

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

#timestampsObject



18
19
20
21
# File 'app/resource_renderers/table_resource_renderer.rb', line 18

def timestamps
  column(:created_at) +
  column(:updated_at)
end

#userstampsObject



24
25
26
27
# File 'app/resource_renderers/table_resource_renderer.rb', line 24

def userstamps
  column(:creator) +
  column(:updater)
end