Class: Formtastic::FormBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/formtastic/globalize_inputs.rb

Instance Method Summary collapse

Instance Method Details

#globalize_inputs(*args, &proc) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/formtastic/globalize_inputs.rb', line 3

def globalize_inputs(*args, &proc)
  index = options[:child_index] || "#{self.object.class.to_s}-#{self.object.object_id}"
  linker = ActiveSupport::SafeBuffer.new
  fields = ActiveSupport::SafeBuffer.new
  
  ::I18n.available_locales.each do |locale|
    active_class = ::I18n.locale == locale ? "in active" : ""
    linker << self.template.(:li,
      self.template.(:a,
        ::I18n.t("translation.#{locale}"),
        :href => "#lang-#{locale}",
        :"data-toggle" => "tab"
      ),
      class: "#{active_class}",
    )
    fields << self.template.(:div,
      self.semantic_fields_for(*(args.dup << self.object.translation_for(locale)), &proc),
      :id => "lang-#{locale}",
      class: "tab-pane fade #{active_class}"
    )
  end

  linker = self.template.(:ul, linker, class: "nav nav-tabs language-selection")
  fields = self.template.(:div, fields, class: "tab-content")

  html = self.template.(:div,
    linker + fields,
    id: "language-tabs-#{index}",
    class: "tabbable tabs-left"
  )
end