enum_select_rails 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +52 -0
- data/Rakefile +29 -0
- data/lib/enum_select_rails.rb +4 -0
- data/lib/enum_select_rails/action_view_ext.rb +16 -0
- data/lib/enum_select_rails/version.rb +3 -0
- data/lib/tasks/enum_select_rails_tasks.rake +4 -0
- metadata +93 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1ad7528894f2dfea689a5bad101034f53a90fafbff59cf8da81905c9b2a46602
|
4
|
+
data.tar.gz: 7cbc8c2a2be0ff5e650accc86d3bb870e2bd4eefc8632f62ca49dcffab322b75
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 12f58473f710cd2cefd426632a7c56e99b407bbae373d994dfb6eeb5495238ba9bca9ffb1ae3941102354275ff04889fe4e294cf864c89465cf80a67471114bb
|
7
|
+
data.tar.gz: b7601829a439c1edc3b81c0b52b80e44a8c30ef1fdf88f984d07db807d27112df15cb5fba95d73cbdafbb73d05833f5e719b2d7c174badd039627fd04eb69e52
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2018 tanakaworld
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# EnumSelectRails
|
2
|
+
A form helper for the enum field of Rails model.
|
3
|
+
|
4
|
+
## Usage
|
5
|
+
|
6
|
+
```erbruby
|
7
|
+
<%= f.enum_select :your_field_name %>
|
8
|
+
```
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'enum_select_rails'
|
15
|
+
```
|
16
|
+
|
17
|
+
## i18n
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
# Gemfile
|
21
|
+
gem 'enum_help'
|
22
|
+
```
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
# application.rb
|
26
|
+
# i18n
|
27
|
+
config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}').to_s]
|
28
|
+
```
|
29
|
+
|
30
|
+
```yaml
|
31
|
+
# config/locales/models/user/ja.yml
|
32
|
+
ja:
|
33
|
+
activerecord:
|
34
|
+
models:
|
35
|
+
user: ユーザー
|
36
|
+
attributes:
|
37
|
+
user:
|
38
|
+
gender: 性別
|
39
|
+
enums:
|
40
|
+
user:
|
41
|
+
gender:
|
42
|
+
female: 女性
|
43
|
+
male: 男性
|
44
|
+
other: その他
|
45
|
+
```
|
46
|
+
|
47
|
+
|
48
|
+
## Contributing
|
49
|
+
Contribution directions go here.
|
50
|
+
|
51
|
+
## License
|
52
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'EnumSelectRails'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
require 'bundler/gem_tasks'
|
19
|
+
|
20
|
+
require 'rake/testtask'
|
21
|
+
|
22
|
+
Rake::TestTask.new(:test) do |t|
|
23
|
+
t.libs << 'test'
|
24
|
+
t.pattern = 'test/**/*_test.rb'
|
25
|
+
t.verbose = false
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
task default: :test
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class ActionView::Helpers::FormBuilder
|
2
|
+
def enum_select(record, options = {}, html_options = {})
|
3
|
+
pluralized = record.to_s.pluralize
|
4
|
+
klass = self.object.class
|
5
|
+
base = klass.send(pluralized)
|
6
|
+
|
7
|
+
# check i18n
|
8
|
+
i18n_method = "#{pluralized}_i18n".to_sym
|
9
|
+
if klass.methods.include? i18n_method
|
10
|
+
i18n = klass.send(i18n_method)
|
11
|
+
select record.to_sym, base.keys.map {|k| [i18n[k], k]}, options, html_options
|
12
|
+
else
|
13
|
+
select record.to_sym, base.keys.map {|k| [k, k]}, options, html_options
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: enum_select_rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- tanakaworld
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-03-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 5.1.4
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 5.1.4
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: enum_help
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: sqlite3
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: A form helper for the enum field of Rails model.
|
56
|
+
email:
|
57
|
+
- yutaro.tanaka.world@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- MIT-LICENSE
|
63
|
+
- README.md
|
64
|
+
- Rakefile
|
65
|
+
- lib/enum_select_rails.rb
|
66
|
+
- lib/enum_select_rails/action_view_ext.rb
|
67
|
+
- lib/enum_select_rails/version.rb
|
68
|
+
- lib/tasks/enum_select_rails_tasks.rake
|
69
|
+
homepage: https://tanakaworld.github.io/enum_select_rails
|
70
|
+
licenses:
|
71
|
+
- MIT
|
72
|
+
metadata: {}
|
73
|
+
post_install_message:
|
74
|
+
rdoc_options: []
|
75
|
+
require_paths:
|
76
|
+
- lib
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
requirements: []
|
88
|
+
rubyforge_project:
|
89
|
+
rubygems_version: 2.7.6
|
90
|
+
signing_key:
|
91
|
+
specification_version: 4
|
92
|
+
summary: A form helper for the enum field of Rails model.
|
93
|
+
test_files: []
|