formtastic_date_as_string 0.0.4 → 0.0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -0
- data/Gemfile +2 -0
- data/lib/formtastic_date_as_string/formtastic.rb +28 -4
- data/lib/formtastic_date_as_string/version.rb +1 -1
- metadata +4 -3
data/.gitignore
CHANGED
data/Gemfile
CHANGED
@@ -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
|
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
|
25
|
-
|
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
|
+
|
metadata
CHANGED
@@ -5,8 +5,9 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
|
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-
|
18
|
+
date: 2011-07-14 00:00:00 +07:00
|
18
19
|
default_executable:
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|