rails_admin_json_translate 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2dc18550e577dfbe6bdea537b92cc4ebbda61ef6
4
+ data.tar.gz: 5d6f6d6be5a3043cd2988a21a32334129c972805
5
+ SHA512:
6
+ metadata.gz: d8d7d44530a4e64a319fa0e97176a4a51db95982d9440f809d5b6d60d5bb559253f17a358e4f701dce65c5eba9bfae64cf0b12390a51c35f5984c2bc32f25383
7
+ data.tar.gz: 73568bbc4f23576fef967270367d60ebae38c2d4f384b6ddf4c0e8116b7e87bf4a923494b0d4987b41fc655444b3d4d0ede3da659afc24e94dd4e539151cfead
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2017 Richard Venneman
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,42 @@
1
+ # RailsAdminJsonTranslate
2
+ This gem integrates [json_translate](https://github.com/cfabianski/json_translate) into [rails_admin](https://github.com/sferik/rails_admin). It aims to provide a reasonably good interface for managing translations. It does so by grouping translations into a tabbed interface, having full language names and accompanying [country flags](https://github.com/richardvenneman/emoji_flag) allowing for good scannability.
3
+
4
+ ![screenshot](https://cloud.githubusercontent.com/assets/75705/23833356/7c448ddc-0744-11e7-83fc-22eb1851d060.png)
5
+
6
+ [![Travis](https://img.shields.io/travis/richardvenneman/rails_admin_json_translate.svg?style=flat-square)](https://travis-ci.org/richardvenneman/rails_admin_json_translate)
7
+ [![Gem](https://img.shields.io/gem/v/rails_admin_json_translate.svg)](https://rubygems.org/gems/rails_admin_json_translate)
8
+
9
+ ## Usage
10
+ First make sure you've setup [json_translate](https://github.com/cfabianski/json_translate) for your models. You'll then need update your rails_admin configuration:
11
+
12
+ ```ruby
13
+ RailsAdmin.config do |config|
14
+ ...
15
+
16
+ config.model 'Post' do
17
+ configure :title_translations, :json_translate
18
+
19
+ # Overriding locales
20
+ configure :body_translations, :json_translate do
21
+ locales %w(nl zh)
22
+ end
23
+ end
24
+ end
25
+ ```
26
+
27
+ By default, rails_admin_json_translate uses the `I18n.available_locales` locales to create the tabbed interface. However you can specify the locales to use on a per-model basis as shown above.
28
+
29
+ ## Installation
30
+ Add this line to your application's Gemfile:
31
+
32
+ ```ruby
33
+ gem 'rails_admin_json_translate'
34
+ ```
35
+
36
+ And then execute:
37
+ ```bash
38
+ $ bundle
39
+ ```
40
+
41
+ ## License
42
+ 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,24 @@
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 = 'RailsAdminJsonTranslate'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+ load 'rails/tasks/statistics.rake'
20
+
21
+
22
+
23
+ require 'bundler/gem_tasks'
24
+
@@ -0,0 +1,32 @@
1
+ - klass = "#{field.abstract_model.model_name.parameterize}-#{field.name}"
2
+
3
+ .controls
4
+ = form.hidden_field field.name, { id: "#{klass}" }
5
+ .json-translate-errors
6
+ = form.errors_for(field)
7
+ %ul.nav.nav-tabs{ style: 'margin-top: 0' }
8
+ - field.locales.each do |locale|
9
+ - locale_klass = "json-translate-pane-#{field.name}-#{locale}-#{form.object.id}"
10
+ %li{ class: ( 'active' if locale == field.current_locale ) }
11
+ %a{ href: '#', data: { toggle: 'tab', target: ".#{locale_klass}:first"} }= "#{EmojiFlag.new(locale)} #{t(locale, scope: :languages)}"
12
+ .tab-content{ class: "#{field.name}-inputs" }
13
+ - field.locales.each do |locale|
14
+ - locale_klass = "json-translate-pane-#{field.name}-#{locale}-#{form.object.id}"
15
+ .fields.tab-pane{ class: "#{locale_klass} #{'active' if locale == field.current_locale}" }
16
+ = form.text_area "#{field.name}_#{locale}", field.html_attributes.reverse_merge(data: { locale: "#{locale}", richtext: false, options: {}.to_json }).reverse_merge({ value: field.value_for_locale(locale), class: "form-control json-translate-input", required: field.required })
17
+
18
+ :javascript
19
+ (function() {
20
+ var input = $("##{klass}");
21
+ var form = $(input.get(0).form);
22
+
23
+ form.on('submit', function(e) {
24
+ var value = input.value || {};
25
+
26
+ $('.#{field.name}-inputs .json-translate-input').each(function(index, element) {
27
+ value[$(element).data('locale')] = element.value;
28
+ });
29
+
30
+ input.val(JSON.stringify(value));
31
+ });
32
+ })();
@@ -0,0 +1,41 @@
1
+ require 'rails_admin_json_translate/engine'
2
+ require 'rails_admin'
3
+ require 'rails_admin/config/fields'
4
+ require 'rails_admin/config/fields/base'
5
+ require 'i18n-language-translations'
6
+ require 'emoji_flag'
7
+
8
+ module RailsAdmin
9
+ module Config
10
+ module Fields
11
+ module Types
12
+ class JsonTranslate < RailsAdmin::Config::Fields::Base
13
+ RailsAdmin::Config::Fields::Types.register(:json_translate, self)
14
+
15
+ register_instance_option :partial do
16
+ :form_json_translate
17
+ end
18
+
19
+ register_instance_option :pretty_value do
20
+ value_for_locale(current_locale)
21
+ end
22
+
23
+ register_instance_option :locales do
24
+ I18n.available_locales
25
+ end
26
+
27
+ def value_for_locale(locale)
28
+ val = @bindings[:object].send(name)
29
+ val ? JSON.parse(val).try(:[], locale.to_s) : ''
30
+ rescue JSON::ParserError
31
+ ''
32
+ end
33
+
34
+ def current_locale
35
+ value_for_locale(I18n.locale).blank? ? locales.first : I18n.locale
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,4 @@
1
+ module RailsAdminJsonTranslate
2
+ class Engine < ::Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module RailsAdminJsonTranslate
2
+ VERSION = '0.1.0'.freeze
3
+ end
metadata ADDED
@@ -0,0 +1,189 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails_admin_json_translate
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Richard Venneman
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-03-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pg
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.20'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.20'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 5.0.0
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: 5.0.0.1
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: 5.0.0
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 5.0.0.1
47
+ - !ruby/object:Gem::Dependency
48
+ name: rails_admin
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '1.1'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '1.1'
61
+ - !ruby/object:Gem::Dependency
62
+ name: json_translate
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '3.0'
68
+ type: :runtime
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '3.0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: i18n-language-translations
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: 0.0.2
82
+ type: :runtime
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: 0.0.2
89
+ - !ruby/object:Gem::Dependency
90
+ name: emoji_flag
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: 0.0.1
96
+ type: :runtime
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: 0.0.1
103
+ - !ruby/object:Gem::Dependency
104
+ name: minitest-rails-capybara
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '3.0'
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: 3.0.1
113
+ type: :development
114
+ prerelease: false
115
+ version_requirements: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - "~>"
118
+ - !ruby/object:Gem::Version
119
+ version: '3.0'
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: 3.0.1
123
+ - !ruby/object:Gem::Dependency
124
+ name: poltergeist
125
+ requirement: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - "~>"
128
+ - !ruby/object:Gem::Version
129
+ version: '1.13'
130
+ type: :development
131
+ prerelease: false
132
+ version_requirements: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - "~>"
135
+ - !ruby/object:Gem::Version
136
+ version: '1.13'
137
+ - !ruby/object:Gem::Dependency
138
+ name: launchy
139
+ requirement: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - "~>"
142
+ - !ruby/object:Gem::Version
143
+ version: '2.4'
144
+ type: :development
145
+ prerelease: false
146
+ version_requirements: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - "~>"
149
+ - !ruby/object:Gem::Version
150
+ version: '2.4'
151
+ description: json_translate tabbed interface and custom field type for rails_admin.
152
+ email:
153
+ - richardvenneman@me.com
154
+ executables: []
155
+ extensions: []
156
+ extra_rdoc_files: []
157
+ files:
158
+ - MIT-LICENSE
159
+ - README.md
160
+ - Rakefile
161
+ - app/views/rails_admin/main/_form_json_translate.html.haml
162
+ - lib/rails_admin_json_translate.rb
163
+ - lib/rails_admin_json_translate/engine.rb
164
+ - lib/rails_admin_json_translate/version.rb
165
+ homepage: https://github.com/richardvenneman/rails_admin_json_translate
166
+ licenses:
167
+ - MIT
168
+ metadata: {}
169
+ post_install_message:
170
+ rdoc_options: []
171
+ require_paths:
172
+ - lib
173
+ required_ruby_version: !ruby/object:Gem::Requirement
174
+ requirements:
175
+ - - ">="
176
+ - !ruby/object:Gem::Version
177
+ version: '0'
178
+ required_rubygems_version: !ruby/object:Gem::Requirement
179
+ requirements:
180
+ - - ">="
181
+ - !ruby/object:Gem::Version
182
+ version: '0'
183
+ requirements: []
184
+ rubyforge_project:
185
+ rubygems_version: 2.5.1
186
+ signing_key:
187
+ specification_version: 4
188
+ summary: Integrate json_translate into rails_admin
189
+ test_files: []