formtastic_date_as_string 0.0.4 → 0.0.5.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -2,3 +2,4 @@
2
2
  .bundle
3
3
  Gemfile.lock
4
4
  pkg/*
5
+ bin/*
data/Gemfile CHANGED
@@ -2,3 +2,5 @@ source "http://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in formtastic_date_as_string.gemspec
4
4
  gemspec
5
+
6
+ gem 'rake', '0.8.7'
@@ -9,9 +9,20 @@ Formtastic::SemanticFormBuilder.class_eval do
9
9
  string_input method, options
10
10
  end
11
11
 
12
+ def datetime_input(method, options = {})
13
+ options[:input_html] ||= {}
14
+ options[:input_html][:class] = [options[:input_html][:class], :datetime].compact.join ' '
15
+ options[:input_html][:value] = I18n.l(object[method]) if object[method].is_a? DateTime
16
+ options[:wrapper_html] ||= {}
17
+ options[:input_html][:class] = [options[:wrapper_html][:class], :datetime].compact.join ' '
18
+ string_input method, options
19
+ end
20
+
12
21
  def default_input_type_with_date(method, options={})
13
- if date_column? method
22
+ if column_of_type? method, :date
14
23
  :date
24
+ elsif column_of_type? method, :datetime
25
+ :datetime
15
26
  else
16
27
  default_input_type_without_date method, options
17
28
  end
@@ -21,8 +32,21 @@ Formtastic::SemanticFormBuilder.class_eval do
21
32
 
22
33
  protected
23
34
 
24
- def date_column?(method)
25
- object.respond_to?(:column_for_attribute) &&
26
- object.column_for_attribute(method).try(:type) == :date
35
+ def column_of_type?(method, type)
36
+ (mongoid_type(method) || active_record_type(method)).to_s.downcase == type.to_s
27
37
  end
38
+
39
+ def active_record_type(method)
40
+ if defined?(ActiveRecord::Base) && object.is_a?(ActiveRecord::Base) && object.column_for_attribute(method)
41
+ return object.column_for_attribute(method).try(:type)
42
+ end
43
+ end
44
+
45
+ def mongoid_type(method)
46
+ if defined?(Mongoid::Document) && object.is_a?(Mongoid::Document) && object.fields[method.to_s]
47
+ return object.fields[method.to_s].options[:type]
48
+ end
49
+ end
50
+
28
51
  end
52
+
@@ -1,3 +1,3 @@
1
1
  module FormtasticDateAsString
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5.1"
3
3
  end
metadata CHANGED
@@ -5,8 +5,9 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 4
9
- version: 0.0.4
8
+ - 5
9
+ - 1
10
+ version: 0.0.5.1
10
11
  platform: ruby
11
12
  authors:
12
13
  - Dmitry Lihachev
@@ -14,7 +15,7 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2011-04-08 00:00:00 +07:00
18
+ date: 2011-07-14 00:00:00 +07:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency