Class: Locomotive::LocalesInput

Inherits:
Formtastic::Inputs::CheckBoxesInput
  • Object
show all
Defined in:
app/inputs/locomotive/locales_input.rb

Instance Method Summary collapse

Instance Method Details

#choice_html(choice) ⇒ Object



32
33
34
35
36
37
38
# File 'app/inputs/locomotive/locales_input.rb', line 32

def choice_html(choice)
  check_box_without_hidden_input(choice) <<
  template.(:label,
    choice_label(choice),
    label_html_options.merge(:for => choice_input_dom_id(choice), :class => nil)
  )
end

#choice_label(choice) ⇒ Object



40
41
42
43
# File 'app/inputs/locomotive/locales_input.rb', line 40

def choice_label(choice)
  text = I18n.t("locomotive.locales.#{choice}")
  template.image_tag("locomotive/icons/flags/#{choice}.png", :alt => text, :size => '24x24') << text
end

#choice_wrapping(html_options, &block) ⇒ Object



25
26
27
28
29
30
# File 'app/inputs/locomotive/locales_input.rb', line 25

def choice_wrapping(html_options, &block)
  template.(:div,
    template.capture(&block),
    html_options
  )
end

#choice_wrapping_html_options(choice) ⇒ Object



49
50
51
52
53
# File 'app/inputs/locomotive/locales_input.rb', line 49

def choice_wrapping_html_options(choice)
  super.tap do |options|
    options[:class] = "entry #{checked?(choice) ? 'selected' : ''}"
  end
end

#choices_group_wrapping(&block) ⇒ Object



17
18
19
20
21
22
23
# File 'app/inputs/locomotive/locales_input.rb', line 17

def choices_group_wrapping(&block)
  template.(:div,
    template.capture(&block) +
    template.(:div, '', :class => 'clear'),
    choices_group_wrapping_html_options
  )
end

#choices_group_wrapping_html_optionsObject



45
46
47
# File 'app/inputs/locomotive/locales_input.rb', line 45

def choices_group_wrapping_html_options
  { :class => 'list' }
end

#hidden_fields?Boolean

Returns:



55
56
57
# File 'app/inputs/locomotive/locales_input.rb', line 55

def hidden_fields?
  false
end

#to_htmlObject



4
5
6
7
8
9
10
11
12
13
14
15
# File 'app/inputs/locomotive/locales_input.rb', line 4

def to_html
  input_wrapping do
    label_html <<
    choices_group_wrapping do
      collection.map { |choice|
        choice_wrapping(choice_wrapping_html_options(choice)) do
          choice_html(choice)
        end
      }.join("\n").html_safe
    end
  end
end