simple_form_localized_input 1.0.1 → 1.0.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 117fe6571faa3fb163b47e0f8f8ee0bf2656f4d4
4
- data.tar.gz: a3e45bdddec119898330d3de5d8c2e4ab383e099
3
+ metadata.gz: 38e238539e753672ccd4affe7d069ce2ed9308b6
4
+ data.tar.gz: 2a75204938310a24d390d7e88a4b4ff0983289af
5
5
  SHA512:
6
- metadata.gz: 7d7a42175c32e21d5fc2eb58d921e064d1340345fb846bcf871c76f31af8bd7a0b1bda3f1634c8b49ee0e83f3532fdf292c7f5b505cdd90209b0038e804aab0a
7
- data.tar.gz: 7b3d15fb486b76ff5a900d1ed1db39277e95ed40e1a1961dcb944aef06dabf016025dfe796c42aea84d1c49a43905eb0e0abd161e2447cef6ccf3da40543db77
6
+ metadata.gz: d1c65a3e08e79119d53ad6141bcddea89088fea54da081bcc3d4536d5162806097cba2008afcd39bfeff8bce287f7e5bbd8af3a898d35cccfc77be5759811157
7
+ data.tar.gz: c183470ac22f475779f35dc96c6efdec30504833c2b75ce21820acbdc71eba6cb3b5ffa4a3b3a9f2d63874c69f9f82670721819e85187eb3311180cafbe62845
@@ -2,26 +2,26 @@ require 'simple_form'
2
2
 
3
3
  module SimpleFormLocalizedInput
4
4
  module FormBuilder
5
+ include SimpleForm::Helpers::Validators
5
6
 
6
7
  def self.included(base)
7
8
  base.class_eval do
8
- def localized_input attribute_name, options={}
9
- simple_fields_for "#{attribute_name}_translations", OpenStruct.new(object.send("#{attribute_name}_translations")) do |f|
9
+ def localized_input(attribute_name, options = {})
10
+ field_name = [attribute_name, 'translations'].join('_')
11
+ field_value = OpenStruct.new(object.send(field_name))
12
+
13
+ simple_fields_for(field_name, field_value) do |fields|
10
14
  ::I18n.available_locales.collect do |loc|
11
- f.input loc.to_sym, options.merge(
12
- {
13
- collection: (options[:collection_translations] ? options[:collection_translations][loc.to_s] : options[:collection]),
14
- label: [object.class.human_attribute_name(attribute_name), "(#{loc})"].reject(&:blank?).join(' ')
15
- }
16
- )
15
+ collection = options[:collection_translations] ? options[:collection_translations][loc.to_s] : options[:collection]
16
+ label = [object.class.human_attribute_name(attribute_name), "(#{loc})"].reject(&:blank?).join(' ')
17
+ required = object.class.validators_on(attribute_name).any? { |v| v.kind == :presence && valid_validator?(v) }
18
+
19
+ fields.input(loc.to_sym, options.merge(collection: collection, label: label, required: required))
17
20
  end.join.html_safe
18
21
  end
19
22
  end
20
23
  end
21
24
  end
22
-
23
- # ---------------------------------------------------------------------
24
-
25
25
  end
26
26
  end
27
27
 
@@ -1,3 +1,3 @@
1
1
  module SimpleFormLocalizedInput
2
- VERSION = "1.0.1"
2
+ VERSION = '1.0.2'.freeze
3
3
  end
@@ -4,23 +4,23 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'simple_form_localized_input/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "simple_form_localized_input"
7
+ spec.name = 'simple_form_localized_input'
8
8
  spec.version = SimpleFormLocalizedInput::VERSION
9
9
  spec.authors = ["Tomáš Celizna"]
10
- spec.email = ["tomas.celizna@gmail.com"]
11
- spec.summary = %q{Custom input for Simple Form that renders Mongoid fields for multiple locales.}
12
- spec.description = %q{Custom input for Simple Form that renders Mongoid fields for multiple locales.}
13
- spec.homepage = "https://github.com/tomasc/simple_form_localized_input"
14
- spec.license = "MIT"
10
+ spec.email = ['tomas.celizna@gmail.com']
11
+ spec.summary = 'Custom input for Simple Form that renders Mongoid fields for multiple locales.'
12
+ spec.description = 'Custom input for Simple Form that renders Mongoid fields for multiple locales.'
13
+ spec.homepage = 'https://github.com/tomasc/simple_form_localized_input'
14
+ spec.license = 'MIT'
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
17
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
19
+ spec.require_paths = ['lib']
20
20
 
21
- spec.add_dependency "simple_form", ">= 3.0.2"
22
- spec.add_dependency "mongoid", ">= 4.0", "< 6.0"
21
+ spec.add_dependency 'simple_form', '>= 3.0.2'
22
+ spec.add_dependency 'mongoid', '>= 4.0', '< 6.0'
23
23
 
24
- spec.add_development_dependency "bundler", "~> 1.6"
25
- spec.add_development_dependency "rake"
24
+ spec.add_development_dependency 'bundler', '~> 1.6'
25
+ spec.add_development_dependency 'rake'
26
26
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_form_localized_input
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomáš Celizna
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-03 00:00:00.000000000 Z
11
+ date: 2016-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: simple_form