Module: FormtasticBootstrap::Inputs::Base::Timeish

Included in:
DateSelectInput, DatetimeSelectInput, TimeSelectInput
Defined in:
lib/formtastic-bootstrap/inputs/base/timeish.rb

Constant Summary collapse

FRAGMENT_CLASSES =
{
  :year   => "col-xs-2",
  :month  => "col-xs-3",
  :day    => "col-xs-1",
  :hour   => "col-xs-offset-3 col-xs-1",
  :minute => "col-xs-1",
  :second => "col-xs-1"
}
FRAGMENT_PLACEHOLDERS =
{
  :year   => nil,
  :month  => nil,
  :day    => nil,
  :hour   => nil,
  :minute => nil,
  :second => nil
}

Instance Method Summary collapse

Instance Method Details

#fragment_class(fragment) ⇒ Object



56
57
58
# File 'lib/formtastic-bootstrap/inputs/base/timeish.rb', line 56

def fragment_class(fragment)
  (options[:fragment_classes] || self.class::FRAGMENT_CLASSES)[fragment.to_sym]
end

#fragment_html(fragment) ⇒ Object



41
42
43
44
45
46
# File 'lib/formtastic-bootstrap/inputs/base/timeish.rb', line 41

def fragment_html(fragment)
  template.(:div, :class => fragment_class(fragment)) do
    opts = input_options.merge(:prefix => fragment_prefix, :field_name => fragment_name(fragment), :default => value, :include_blank => include_blank?)
    template.send(:"select_#{fragment}", value, opts, fragment_input_html_options(fragment))
  end
end

#fragment_input_html_options(fragment) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/formtastic-bootstrap/inputs/base/timeish.rb', line 48

def fragment_input_html_options(fragment)
  input_html_options.tap do |options|
    options[:id] = fragment_id(fragment)
    options[:class] = ((options[:class] || "").split << "form-control").join(" ")
    options[:placeholder] = fragment_placeholder(fragment)
  end
end

#fragment_placeholder(fragment) ⇒ Object



60
61
62
# File 'lib/formtastic-bootstrap/inputs/base/timeish.rb', line 60

def fragment_placeholder(fragment)
  (options[:fragment_placeholders] || self.class::FRAGMENT_PLACEHOLDERS)[fragment.to_sym]
end

#row_wrapping(&block) ⇒ Object



34
35
36
37
38
39
# File 'lib/formtastic-bootstrap/inputs/base/timeish.rb', line 34

def row_wrapping(&block)
  template.(:div,
    template.capture(&block).html_safe,
    :class => 'row'
  )
end

#to_htmlObject



23
24
25
26
27
28
29
30
31
32
# File 'lib/formtastic-bootstrap/inputs/base/timeish.rb', line 23

def to_html
  bootstrap_wrapping do
    hidden_fragments <<
    row_wrapping do
      fragments.map do |fragment|
        fragment_html(fragment.to_sym)
      end.join.html_safe
    end
  end
end