mongoid_form 0.0.2.1 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ # Changelog
2
+
3
+ ## 0.0.3
4
+ * Localized fields for text_field and text_area
5
+ * Fix issue with flag block rendering if field is not required
@@ -8,12 +8,19 @@ module MongoidForm
8
8
  object = @object.send(field_name).try(:empty?) ? nil : @object.send(field_name)
9
9
  name = "#{object_name}[#{field_name}]"
10
10
 
11
- @template.fields_for(name, object, &block).html_safe
11
+ @template.fields_for(name, object, &block)
12
12
  end
13
13
 
14
- def localized_text_field(attribute, options = {})
14
+ def localized_field(type, attribute, options = {})
15
15
  attribute, options = value_field(attribute, options)
16
- text_field(attribute, options).html_safe
16
+ case type
17
+ when :text
18
+ text_field(attribute, options)
19
+ when :text_area
20
+ text_area(attribute, options)
21
+ else
22
+ ""
23
+ end
17
24
  end
18
25
 
19
26
  def error_notification
@@ -74,16 +81,16 @@ module MongoidForm
74
81
  wrap_group(input, name, label)
75
82
  end
76
83
 
77
- def wrap_localized_fields(builder)
84
+ def wrap_localized_fields(builder, type, options)
78
85
  name = builder.object_name.scan(/\[(.*)_translations\]/).join.to_sym
79
86
  result = ''
80
87
  I18n.available_locales.each do |locale|
81
88
  field = builder.object_name.scan(/(.*)\[(.*)_translations\]/).join('.')
82
89
  flag = wrapper.flag_for_localized.first ? wrap('', [:div, class: "flag flags-#{locale.to_s}"]) : ''
83
90
  label = builder.label locale.to_sym, *wrapper.label_options do
84
- asterisk(name) + I18n::t("mongoid.attributes.#{field}") + flag
91
+ asterisk(name).html_safe + I18n::t("mongoid.attributes.#{field}") + flag
85
92
  end
86
- input = builder.localized_text_field locale.to_sym
93
+ input = builder.localized_field type, locale.to_sym, options
87
94
 
88
95
  result << wrap_group(input, name, label)
89
96
  end
@@ -2,17 +2,25 @@ module MongoidForm
2
2
  module Helpers
3
3
  module FormHelper
4
4
 
5
- def localized(name)
6
- localized_fields(name) { |lf| @template.concat wrap_localized_fields(lf) }
5
+ def localized(name, *args)
6
+ type, options = get_options(args)
7
+ localized_fields(name) { |lf| @template.concat wrap_localized_fields(lf, type, options) }
7
8
  end
8
9
 
9
10
  def input(name, *args)
10
- type = args[0]
11
- options = args.extract_options!
12
- type ||= :text
11
+ type, options = get_options(args)
13
12
  factory type, name, options
14
13
  end
15
14
 
15
+ private
16
+
17
+ def get_options(args)
18
+ type = args[0]
19
+ options = args.extract_options!
20
+ type ||= :text
21
+ return type, options
22
+ end
23
+
16
24
  end
17
25
  end
18
26
  end
@@ -1,3 +1,3 @@
1
1
  module MongoidForm
2
- VERSION = "0.0.2.1"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid_form
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2.1
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-20 00:00:00.000000000 Z
12
+ date: 2013-03-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mongoid
@@ -115,6 +115,7 @@ extensions: []
115
115
  extra_rdoc_files: []
116
116
  files:
117
117
  - .gitignore
118
+ - CHANGELOG.md
118
119
  - Gemfile
119
120
  - LICENSE.txt
120
121
  - README.md