Class: TwitterBuilderHelper::ActionsColumnDefinition

Inherits:
ColumnDefinition show all
Defined in:
app/helpers/twitter_builder_helper.rb

Instance Attribute Summary

Attributes inherited from ColumnDefinition

#align, #title, #value_extractor

Instance Method Summary collapse

Constructor Details

#initializeActionsColumnDefinition

Returns a new instance of ActionsColumnDefinition.



17
18
19
20
# File 'app/helpers/twitter_builder_helper.rb', line 17

def initialize
  self.title = I18n.t('admin.common.actions')
  @actions = []
end

Instance Method Details

#action(method, options = {}) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/helpers/twitter_builder_helper.rb', line 45

def action(method, options = {})
  @actions << case method
                when :edit
                  [->(item) { edit_link(send("edit_admin_#{item.class.name.underscore.sub('/', '_')}_path", item)) }, options]
                when :delete
                  [->(item) { delete_link([:admin, item]) }, options]
                when Proc
                  [method, options]
                else
                  raise "unsupported method: #{method.inspect}"
              end
end

#col_classObject



26
27
28
# File 'app/helpers/twitter_builder_helper.rb', line 26

def col_class
  "col-xs-#{cols}"
end

#colsObject



22
23
24
# File 'app/helpers/twitter_builder_helper.rb', line 22

def cols
  @cols || @actions.size % 2 + @actions.size / 2
end

#cols=(value) ⇒ Object



30
31
32
# File 'app/helpers/twitter_builder_helper.rb', line 30

def cols=(value)
  @cols = value
end

#value(item, context = self) ⇒ Object



34
35
36
37
38
39
40
41
42
43
# File 'app/helpers/twitter_builder_helper.rb', line 34

def value(item, context = self)
  @actions.collect do |action|
    options = action.second
    if options[:if]
      context.instance_exec(item, &action.first) if options[:if].call(item)
    else
      context.instance_exec(item, &action.first)
    end
  end.compact.join(' ').html_safe
end