Module: ActiveAdminAddons::InputOptionsHandler

Included in:
InputBase, SelectHelpers
Defined in:
lib/activeadmin_addons/support/input_helpers/input_options_handler.rb

Instance Method Summary collapse

Instance Method Details

#attr_optionsObject



23
24
25
# File 'lib/activeadmin_addons/support/input_helpers/input_options_handler.rb', line 23

def attr_options
  @attr_options || {}
end

#control_attributesObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/activeadmin_addons/support/input_helpers/input_options_handler.rb', line 3

def control_attributes
  result = {}
  result[:class] = css_classes.compact.join(" ") if css_classes.any?

  data_attr_options.each do |attribute, item|
    result[:data] ||= {}
    result[:data][attribute] = formatted_option_value(item)
  end

  attr_options.each do |attribute, item|
    result[attribute] = formatted_option_value(item)
  end

  result
end

#css_classesObject



27
28
29
# File 'lib/activeadmin_addons/support/input_helpers/input_options_handler.rb', line 27

def css_classes
  @css_classes || []
end

#data_attr_optionsObject



19
20
21
# File 'lib/activeadmin_addons/support/input_helpers/input_options_handler.rb', line 19

def data_attr_options
  @data_attr_options || {}
end

#get_data_attr_value(attr_name) ⇒ Object



50
51
52
53
54
55
# File 'lib/activeadmin_addons/support/input_helpers/input_options_handler.rb', line 50

def get_data_attr_value(attr_name)
  item = data_attr_options[attr_name.to_sym]
  return unless item

  item[:value]
end

#load_attr(attr_name, options = {}) ⇒ Object



36
37
38
39
# File 'lib/activeadmin_addons/support/input_helpers/input_options_handler.rb', line 36

def load_attr(attr_name, options = {})
  @attr_options ||= {}
  @attr_options[attr_name.to_sym] = load_option_attr(attr_name, options)
end

#load_class(class_attr) ⇒ Object



41
42
43
44
45
46
47
48
# File 'lib/activeadmin_addons/support/input_helpers/input_options_handler.rb', line 41

def load_class(class_attr)
  @css_classes ||= []
  return if class_attr.blank?

  class_attr = class_attr.strip
  @css_classes << class_attr
  class_attr
end

#load_data_attr(attr_name, options = {}) ⇒ Object



31
32
33
34
# File 'lib/activeadmin_addons/support/input_helpers/input_options_handler.rb', line 31

def load_data_attr(attr_name, options = {})
  @data_attr_options ||= {}
  @data_attr_options[attr_name.to_sym] = load_option_attr(attr_name, options)
end