administrate-field-i18n_enum 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +44 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/LICENSE.txt +21 -0
- data/README.md +75 -0
- data/Rakefile +6 -0
- data/administrate-field-i18n_enum.gemspec +21 -0
- data/app/views/fields/i18n_enum/_form.html.erb +9 -0
- data/app/views/fields/i18n_enum/_index.html.erb +1 -0
- data/app/views/fields/i18n_enum/_show.html.erb +2 -0
- data/lib/administrate/field/i18n_enum.rb +36 -0
- data/spec/administrate/field/i18n_enum_spec.rb +11 -0
- data/spec/spec_helper.rb +11 -0
- metadata +88 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 91afa83fc36ca7dc720c6e1efa606cd623dfef35
|
4
|
+
data.tar.gz: d366c4f3291bb4b8cd490a6b7cbc82267bce99d6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c9430c87e11389d50a690667b149261d4ad901dee99f41d58e3bda16483513feaea0309bebed3056657bb66f772b4e6b6e62b73ee67cdb203ff14ac11a29773e
|
7
|
+
data.tar.gz: f3d02d7eb506ba3ed7dc23f06c25a52bcf1a485de2a10a54f135a813d2642e9ef9abd229c38ee2212f24bf82b8785ddc9567fb653be89fc040ebcc9505845845
|
data/.gitignore
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
*.rbc
|
2
|
+
capybara-*.html
|
3
|
+
.rspec
|
4
|
+
/log
|
5
|
+
/tmp
|
6
|
+
/db/*.sqlite3
|
7
|
+
/db/*.sqlite3-journal
|
8
|
+
/public/system
|
9
|
+
/coverage/
|
10
|
+
/spec/tmp
|
11
|
+
*.orig
|
12
|
+
rerun.txt
|
13
|
+
pickle-email-*.html
|
14
|
+
|
15
|
+
# TODO Comment out this rule if you are OK with secrets being uploaded to the repo
|
16
|
+
config/initializers/secret_token.rb
|
17
|
+
|
18
|
+
# Only include if you have production secrets in this file, which is no longer a Rails default
|
19
|
+
# config/secrets.yml
|
20
|
+
|
21
|
+
# dotenv
|
22
|
+
# TODO Comment out this rule if environment variables can be committed
|
23
|
+
.env
|
24
|
+
|
25
|
+
## Environment normalization:
|
26
|
+
/.bundle
|
27
|
+
/vendor/bundle
|
28
|
+
|
29
|
+
# these should all be checked in to normalize the environment:
|
30
|
+
# Gemfile.lock, .ruby-version, .ruby-gemset
|
31
|
+
|
32
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
33
|
+
.rvmrc
|
34
|
+
|
35
|
+
# if using bower-rails ignore default bower_components path bower.json files
|
36
|
+
/vendor/assets/bower_components
|
37
|
+
*.bowerrc
|
38
|
+
bower.json
|
39
|
+
|
40
|
+
# Ignore pow environment settings
|
41
|
+
.powenv
|
42
|
+
|
43
|
+
# Ignore Byebug command history file.
|
44
|
+
.byebug_history
|
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at d.iwasaki.g@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2017 Daisuke Iwasaki
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 iwasaki_d
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
# Administrate::Field::I18nEnum
|
2
|
+
|
3
|
+
A plugin to i18n enum attribute select box in [Administrate](https://github.com/thoughtbot/administrate).
|
4
|
+
|
5
|
+
i18nに対応したAdministrate用のPluginです。
|
6
|
+
ActiveRecordモデルのenum属性の表示をi18nのlocaleで置き換えselectboxを表示します。
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'administrate-field-i18n_enum'
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install administrate-field-i18n_enum
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
class Human < ApplicationRecord
|
28
|
+
enum gender: { male: 0, female: 1 }
|
29
|
+
end
|
30
|
+
```
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
gender: Field::I18nEnum.with_options(class_name: 'Human'),
|
34
|
+
```
|
35
|
+
Put it into ATTRIBUTE_TYPES of HumanDashboard Class, please.
|
36
|
+
|
37
|
+
|
38
|
+
## Options
|
39
|
+
|
40
|
+
| Options |Type | Required | Description |
|
41
|
+
|------------|:--------------:|:------------:|:--------------------------------------|
|
42
|
+
| class_name |String | True | Class name of enum attribute. |
|
43
|
+
| collection |Array | False(Any) | If irregular plural or want to use custom options. You can set options of array.|
|
44
|
+
| null |Boolean | False(Any) | True, nil value option will be inserted into select box. |
|
45
|
+
| scope |symbol or Array | False(Any) | It is used for the scope option of i18n.translate |
|
46
|
+
|
47
|
+
## locales Example
|
48
|
+
Default:
|
49
|
+
```yml
|
50
|
+
ja:
|
51
|
+
human:
|
52
|
+
gender:
|
53
|
+
male: 男性
|
54
|
+
female: 女性
|
55
|
+
```
|
56
|
+
|
57
|
+
When set "scope: :enums".
|
58
|
+
```yml
|
59
|
+
ja:
|
60
|
+
enums:
|
61
|
+
human:
|
62
|
+
gender:
|
63
|
+
male: 男性
|
64
|
+
female: 女性
|
65
|
+
```
|
66
|
+
|
67
|
+
## Contributing
|
68
|
+
|
69
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/iwasaki_d/administrate-field-i18n_enum. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
70
|
+
|
71
|
+
|
72
|
+
## License
|
73
|
+
|
74
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
75
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "administrate-field-i18n_enum"
|
7
|
+
spec.version = '0.1.5'
|
8
|
+
spec.authors = ["iwasaki_d"]
|
9
|
+
spec.email = ["d.iwasaki.g@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = "A plugin to i18n enum attribute select box in Administrate."
|
12
|
+
spec.description = spec.summary
|
13
|
+
spec.homepage = "https://github.com/iwasaki-d/administrate-i18n-enum"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split("\n")
|
17
|
+
spec.require_paths = ['lib']
|
18
|
+
|
19
|
+
spec.add_runtime_dependency 'administrate'
|
20
|
+
spec.add_runtime_dependency 'rails', '>= 4.2'
|
21
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= field.data.nil? ? '' : field.translate(field.class_name, field.attribute, field.data) %>
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'administrate/field/select'
|
2
|
+
require 'rails'
|
3
|
+
|
4
|
+
module Administrate
|
5
|
+
module Field
|
6
|
+
class I18nEnum < Administrate::Field::Select
|
7
|
+
class Engine < ::Rails::Engine
|
8
|
+
end
|
9
|
+
|
10
|
+
def enum_options
|
11
|
+
enums = collection.map do |k, v|
|
12
|
+
[translate(class_name, @attribute, k), k]
|
13
|
+
end
|
14
|
+
enums.unshift(['', nil]) if @options.fetch(:null, false) == true
|
15
|
+
enums
|
16
|
+
end
|
17
|
+
|
18
|
+
def class_name
|
19
|
+
@options.fetch(:class_name, '').camelcase.downcase
|
20
|
+
end
|
21
|
+
|
22
|
+
def translate(class_name, attribute, value)
|
23
|
+
I18n.t("#{class_name}.#{attribute}.#{value}", scope: @options.fetch(:scope, nil), default: value)
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def collection
|
29
|
+
super
|
30
|
+
method_name = @attribute.to_s.pluralize
|
31
|
+
@collection = @options.fetch(:class_name, '').constantize.send(method_name) if @collection.empty?
|
32
|
+
@collection
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require "bundler/setup"
|
2
|
+
require "administrate/field/i18n_enum"
|
3
|
+
|
4
|
+
RSpec.configure do |config|
|
5
|
+
# Enable flags like --only-failures and --next-failure
|
6
|
+
config.example_status_persistence_file_path = ".rspec_status"
|
7
|
+
|
8
|
+
config.expect_with :rspec do |c|
|
9
|
+
c.syntax = :expect
|
10
|
+
end
|
11
|
+
end
|
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: administrate-field-i18n_enum
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.5
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- iwasaki_d
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-06-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: administrate
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rails
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '4.2'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '4.2'
|
41
|
+
description: A plugin to i18n enum attribute select box in Administrate.
|
42
|
+
email:
|
43
|
+
- d.iwasaki.g@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- ".rspec"
|
50
|
+
- ".travis.yml"
|
51
|
+
- CODE_OF_CONDUCT.md
|
52
|
+
- Gemfile
|
53
|
+
- LICENSE
|
54
|
+
- LICENSE.txt
|
55
|
+
- README.md
|
56
|
+
- Rakefile
|
57
|
+
- administrate-field-i18n_enum.gemspec
|
58
|
+
- app/views/fields/i18n_enum/_form.html.erb
|
59
|
+
- app/views/fields/i18n_enum/_index.html.erb
|
60
|
+
- app/views/fields/i18n_enum/_show.html.erb
|
61
|
+
- lib/administrate/field/i18n_enum.rb
|
62
|
+
- spec/administrate/field/i18n_enum_spec.rb
|
63
|
+
- spec/spec_helper.rb
|
64
|
+
homepage: https://github.com/iwasaki-d/administrate-i18n-enum
|
65
|
+
licenses:
|
66
|
+
- MIT
|
67
|
+
metadata: {}
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options: []
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
requirements: []
|
83
|
+
rubyforge_project:
|
84
|
+
rubygems_version: 2.6.8
|
85
|
+
signing_key:
|
86
|
+
specification_version: 4
|
87
|
+
summary: A plugin to i18n enum attribute select box in Administrate.
|
88
|
+
test_files: []
|