Class: Maglev::Editor::Settings::Select::SelectComponent

Inherits:
BaseComponent
  • Object
show all
Defined in:
app/components/maglev/editor/settings/select/select_component.rb

Instance Attribute Summary

Attributes inherited from BaseComponent

#definition, #i18n_scope, #input_scope, #paths, #value

Instance Method Summary collapse

Methods inherited from BaseComponent

#after_initialize, #call, #default_placeholder, #fetch_path, #initialize, #input_name, #input_source, #label, #placeholder

Constructor Details

This class inherits a constructor from Maglev::Editor::Settings::BaseComponent

Instance Method Details

#choicesObject



8
9
10
11
12
13
14
# File 'app/components/maglev/editor/settings/select/select_component.rb', line 8

def choices
  (definition.options[:select_options] || []).map do |option|
    option_label, option_value = extra_option_label_and_value(option)

    [translate_choice(option_value, default: option_label), option_value]
  end
end

#extra_option_label_and_value(option) ⇒ Object



16
17
18
# File 'app/components/maglev/editor/settings/select/select_component.rb', line 16

def extra_option_label_and_value(option)
  option.is_a?(Hash) ? option.values_at(:label, :value) : [option, option]
end

#translate_choice(choice, default: nil) ⇒ Object



20
21
22
# File 'app/components/maglev/editor/settings/select/select_component.rb', line 20

def translate_choice(choice, default: nil)
  ::I18n.t("#{i18n_scope}.settings.#{definition.id}_options.#{choice}", default: default)
end