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



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

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



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

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

#awesome_nested_set_actions(options = {}) ⇒ Object



56
57
58
59
60
61
62
# File 'app/resource_renderers/table_resource_renderer.rb', line 56

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

  column_options = { as: :awesome_nested_set }
  column_options[:scope] = scope if scope.present?
  column :awesome_nested_set_actions, column_options
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

#columns(*args) ⇒ Object



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

def columns(*args)
  _ = args.extract_options!
  columns = *args || resource_class.attribute_names
  columns.collect do |name|
    column name
  end.join.html_safe
end

#render(&block) ⇒ Object



14
15
16
17
18
# File 'app/resource_renderers/table_resource_renderer.rb', line 14

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

#timestampsObject



20
21
22
23
# File 'app/resource_renderers/table_resource_renderer.rb', line 20

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

#userstampsObject



26
27
28
29
# File 'app/resource_renderers/table_resource_renderer.rb', line 26

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