Class: Locomotive::LocaleInput

Inherits:
Formtastic::Inputs::TextInput
  • Object
show all
Includes:
Formtastic::Inputs::Base::Choices
Defined in:
app/inputs/locomotive/locale_input.rb

Instance Method Summary collapse

Instance Method Details

#available_locales_to_htmlObject



13
14
15
16
17
18
19
# File 'app/inputs/locomotive/locale_input.rb', line 13

def available_locales_to_html
  template.(:div,
    Locomotive.config.locales.map do |locale|
      template.(:div, locale_to_html(locale).html_safe, :class => 'entry')
    end.join.html_safe +
    template.(:div, '', :class => 'clear'), :class => 'list')
end

#choice_input_dom_id(choice) ⇒ Object



30
31
32
33
34
35
36
37
# File 'app/inputs/locomotive/locale_input.rb', line 30

def choice_input_dom_id(choice)
  [
    builder.custom_namespace,
    sanitized_object_name,
    association_primary_key || method,
    choice_html_safe_value(choice)
  ].compact.reject { |i| i.blank? }.join("_")
end

#locale_to_html(locale) ⇒ Object



21
22
23
24
25
26
27
28
# File 'app/inputs/locomotive/locale_input.rb', line 21

def locale_to_html(locale)
  text = I18n.t("locomotive.locales.#{locale}")

  builder.radio_button(:locale, locale, :id => choice_input_dom_id(locale)) +
  template.(:label,
    template.image_tag("locomotive/icons/flags/#{locale}.png", :alt => text, :size => '24x24') +
    text, :for => choice_input_dom_id(locale))
end

#to_htmlObject



6
7
8
9
10
11
# File 'app/inputs/locomotive/locale_input.rb', line 6

def to_html
  input_wrapping do
    label_html <<
    self.available_locales_to_html
  end
end