rails_admin_translate 0.4.0
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 +7 -0
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +44 -0
- data/Rakefile +1 -0
- data/app/views/rails_admin/main/_form.html.haml +1 -0
- data/app/views/rails_admin/main/_form_code_mirrorml.html.haml +46 -0
- data/app/views/rails_admin/main/_form_fieldml.html.haml +1 -0
- data/app/views/rails_admin/main/_form_textml.html.haml +1 -0
- data/app/views/rails_admin/main/_form_wysihtml5ml.html.haml +8 -0
- data/app/views/rails_admin/main/form_types/_form_simple.html.haml +7 -0
- data/app/views/rails_admin/main/form_types/_form_tabbed.html.haml +23 -0
- data/lib/rails_admin_translate.rb +20 -0
- data/lib/rails_admin_translate/engine.rb +4 -0
- data/lib/rails_admin_translate/register_instances.rb +21 -0
- data/lib/rails_admin_translate/types.rb +47 -0
- data/lib/rails_admin_translate/version.rb +3 -0
- data/rails_admin_translate.gemspec +26 -0
- metadata +120 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: '069427067bba205270d6f8663cf5ad165dd89ec92b1ce7713390891189d30d73'
|
4
|
+
data.tar.gz: e149079d8977fb772438c19de45984c15d10c7e5762717084620343f57ecef66
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ccff392c6674a56a3b180668fa011ad7e74eec798afb3895398ac8a61fbf6fc9a2f9576c2ee5c7d1a6851fdd463e370bb0a69be53849f97e0a54f2e3a0c1c1fa
|
7
|
+
data.tar.gz: 252e7752835ea43366e3c86effb5d2d38ae4a1779315526f9db44953839984cf4670fe12953e4ef2da2a7e9bd19e71ae0bc0815e464cb9f2c53925aa50f37698
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Andrew Volozhanin
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# Rails Admin Translate
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
Add your translation gem to gemfile
|
6
|
+
```ruby
|
7
|
+
gem 'json_translate'
|
8
|
+
# OR
|
9
|
+
gem 'globalize'
|
10
|
+
```
|
11
|
+
|
12
|
+
Then add this gem and run `bundle`
|
13
|
+
```ruby
|
14
|
+
gem 'rails_admin_translate'
|
15
|
+
```
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
> Don't forget to set I18n.available_locale config, because it uses that to determine what tabs to show
|
20
|
+
|
21
|
+
Add configuration to your model. `:locale` field is always required.
|
22
|
+
``` ruby
|
23
|
+
config.model 'Post' do
|
24
|
+
field :name do
|
25
|
+
tabbed false
|
26
|
+
end
|
27
|
+
field :description do
|
28
|
+
tabbed false
|
29
|
+
end
|
30
|
+
end
|
31
|
+
```
|
32
|
+
|
33
|
+
## Screenshot
|
34
|
+
|
35
|
+

|
36
|
+
|
37
|
+
## Contributing
|
38
|
+
|
39
|
+
1. Fork it
|
40
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
41
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
42
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
43
|
+
5. Create new Pull Request
|
44
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1 @@
|
|
1
|
+
= render "rails_admin/main/form_types/#{field.tabbed ? 'form_tabbed' : 'form_simple'}", form: form, field: field, field_type: field_type, html_attributes: html_attributes
|
@@ -0,0 +1,46 @@
|
|
1
|
+
:ruby
|
2
|
+
js_data = {
|
3
|
+
:csspath => field.css_location,
|
4
|
+
:jspath => field.js_location,
|
5
|
+
:options => field.config,
|
6
|
+
:locations => field.assets
|
7
|
+
}
|
8
|
+
|
9
|
+
editor_size = {
|
10
|
+
width: 'auto',
|
11
|
+
heigth: '300px',
|
12
|
+
}
|
13
|
+
|
14
|
+
if field.html_attributes[:cols]
|
15
|
+
if field.html_attributes[:cols].to_s.match('%')
|
16
|
+
editor_size[:width] = field.html_attributes[:cols]
|
17
|
+
else
|
18
|
+
editor_size[:width] = "#{field.html_attributes[:cols].to_i * 8}px"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
if field.html_attributes[:rows]
|
23
|
+
if field.html_attributes[:rows].to_s.match('%')
|
24
|
+
editor_size[:heigth] = field.html_attributes[:rows]
|
25
|
+
else
|
26
|
+
editor_size[:heigth] = "#{field.html_attributes[:rows].to_i * 20}px"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
- uniqid = "code_mirror_#{SecureRandom.hex(10)}"
|
31
|
+
|
32
|
+
:css
|
33
|
+
##{uniqid} .CodeMirror {
|
34
|
+
width: #{editor_size[:width]};
|
35
|
+
height: #{editor_size[:heigth]};
|
36
|
+
}
|
37
|
+
|
38
|
+
:javascript
|
39
|
+
$(document).on('click', '##{uniqid} .nav.nav-tabs li a', function(e){
|
40
|
+
$('##{uniqid} .tab-content '+ $(this).attr('href') + ' .CodeMirror').each(function(i, el){
|
41
|
+
el.CodeMirror.refresh();
|
42
|
+
});
|
43
|
+
});
|
44
|
+
|
45
|
+
%div{id: uniqid}
|
46
|
+
= render 'form', form: form, field: field, field_type: :text_area, html_attributes: field.html_attributes.reverse_merge(:data => { :richtext => 'codemirror', :options => js_data.to_json })
|
@@ -0,0 +1 @@
|
|
1
|
+
= render 'form', form: form, field: field, field_type: :text_field, html_attributes: field.html_attributes
|
@@ -0,0 +1 @@
|
|
1
|
+
= render 'form', form: form, field: field, field_type: :text_area, html_attributes: field.html_attributes.reverse_merge(:data => { :richtext => false, :options => {}.to_json })
|
@@ -0,0 +1,8 @@
|
|
1
|
+
:ruby
|
2
|
+
js_data = {
|
3
|
+
:csspath => field.css_location,
|
4
|
+
:jspath => field.js_location,
|
5
|
+
:config_options => field.config_options.to_json
|
6
|
+
}
|
7
|
+
|
8
|
+
= render 'form', form: form, field: field, field_type: :text_area, html_attributes: field.html_attributes.reverse_merge(:data => { :richtext => 'bootstrap-wysihtml5', :options => js_data.to_json })
|
@@ -0,0 +1,7 @@
|
|
1
|
+
= form.fields_for field.translations_field do |localized_field|
|
2
|
+
- I18n.available_locales.each do |locale|
|
3
|
+
- val = form.object.send("#{field.name}_translations").try(:[], locale.to_s)
|
4
|
+
%div
|
5
|
+
= localized_field.label locale
|
6
|
+
= localized_field.send field_type, locale, html_attributes.reverse_merge({ :value => val })
|
7
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
|
2
|
+
%ul.nav.nav-tabs
|
3
|
+
- uuid = "#{field.name}_#{field.object_id}_unique_id"
|
4
|
+
- I18n.available_locales.each do |locale|
|
5
|
+
%li{ class: ( 'active' if locale == I18n.locale ) }
|
6
|
+
%a{ href: "##{locale}_#{uuid}", data: { toggle: "tab" }, class: uuid }= locale
|
7
|
+
.tab-content
|
8
|
+
= form.fields_for field.translations_field do |localized_field|
|
9
|
+
- I18n.available_locales.each do |locale|
|
10
|
+
- val = form.object.send("#{field.name}_translations").try(:[], locale.to_s)
|
11
|
+
.fields.tab-pane{ style: 'padding:5px; margin: 0;', id: "#{locale}_#{uuid}", class: [( 'active' if locale == I18n.locale ), uuid] }
|
12
|
+
= localized_field.send field_type, locale, html_attributes.reverse_merge({ :value => val })
|
13
|
+
|
14
|
+
:javascript
|
15
|
+
var #{field.name}#{field.object_id} = (new Date().getTime()) + Math.floor(Math.random()*100000);
|
16
|
+
$("ul.nav.nav-tabs a.#{uuid}").each(function(e){
|
17
|
+
this.href = $(this).attr('href').replace('_unique_id', #{field.name}#{field.object_id});
|
18
|
+
$(this).removeClass('#{uuid}');
|
19
|
+
});
|
20
|
+
$(".tab-content .#{uuid}").each(function(e){
|
21
|
+
this.id = this.id.replace('_unique_id', #{field.name}#{field.object_id});
|
22
|
+
$(this).removeClass('#{uuid}');
|
23
|
+
});
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'rails_admin_translate/engine'
|
2
|
+
require 'rails_admin'
|
3
|
+
|
4
|
+
require 'active_support/concern'
|
5
|
+
require 'rails_admin/config/fields'
|
6
|
+
require 'rails_admin/config/fields/base'
|
7
|
+
require 'rails_admin/config/fields/types/string'
|
8
|
+
require 'rails_admin/config/fields/types/text'
|
9
|
+
require 'rails_admin/config/fields/types/ck_editor'
|
10
|
+
require 'rails_admin/config/fields/types/code_mirror'
|
11
|
+
require 'rails_admin/config/fields/types/wysihtml5'
|
12
|
+
|
13
|
+
require 'rails_admin_translate/register_instances'
|
14
|
+
require 'rails_admin_translate/types'
|
15
|
+
|
16
|
+
module RailsAdminTranslate
|
17
|
+
mattr_accessor :tabbed
|
18
|
+
@@tabbed = false
|
19
|
+
end
|
20
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module RegisterInstances
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
included do
|
5
|
+
register_instance_option :translations_field do
|
6
|
+
(name.to_s + '_translations').to_sym
|
7
|
+
end
|
8
|
+
|
9
|
+
register_instance_option :localized? do
|
10
|
+
@abstract_model.model_name.constantize.public_instance_methods.include?(translations_field)
|
11
|
+
end
|
12
|
+
|
13
|
+
register_instance_option :tabbed do
|
14
|
+
RailsAdminTranslate.tabbed
|
15
|
+
end
|
16
|
+
|
17
|
+
register_instance_option :allowed_methods do
|
18
|
+
localized? ? [method_name, translations_field] : [method_name]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module RailsAdmin
|
2
|
+
module Config
|
3
|
+
module Fields
|
4
|
+
module Types
|
5
|
+
RailsAdmin::Config::Fields::Types::Text.class_eval do
|
6
|
+
include RegisterInstances
|
7
|
+
|
8
|
+
register_instance_option :partial do
|
9
|
+
localized? ? :form_textml : :form_text
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
RailsAdmin::Config::Fields::Types::CKEditor.class_eval do
|
14
|
+
include RegisterInstances
|
15
|
+
|
16
|
+
register_instance_option :partial do
|
17
|
+
localized? ? :form_ck_editorml : :form_ck_editor
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
RailsAdmin::Config::Fields::Types::CodeMirror.class_eval do
|
22
|
+
include RegisterInstances
|
23
|
+
|
24
|
+
register_instance_option :partial do
|
25
|
+
localized? ? :form_code_mirrorml : :form_code_mirror
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
RailsAdmin::Config::Fields::Types::Wysihtml5.class_eval do
|
30
|
+
include RegisterInstances
|
31
|
+
|
32
|
+
register_instance_option :partial do
|
33
|
+
localized? ? :form_wysihtml5ml : :form_wysihtml5
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
RailsAdmin::Config::Fields::Types::String.class_eval do
|
38
|
+
include RegisterInstances
|
39
|
+
|
40
|
+
register_instance_option :partial do
|
41
|
+
localized? ? :form_fieldml : :form_field
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rails_admin_translate/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rails_admin_translate"
|
8
|
+
spec.version = RailsAdminTranslate::VERSION
|
9
|
+
spec.authors = ["GlebTv"]
|
10
|
+
spec.email = ["glebtv@gmail.com"]
|
11
|
+
spec.description = %q{Adds tabbed interface and custom field type for globalize/json_translate translations to rails_admin}
|
12
|
+
spec.summary = %q{Tabbed interface and custom field type for globalize / json_translate translations for rails_admin}
|
13
|
+
spec.homepage = "https://gitlab.com/rocket-science/rails_admin_translate"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency 'rails'
|
22
|
+
spec.add_dependency 'rails_admin'
|
23
|
+
|
24
|
+
spec.add_development_dependency 'bundler'
|
25
|
+
spec.add_development_dependency 'rake'
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails_admin_translate
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.4.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- GlebTv
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-06-05 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: '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_admin
|
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: bundler
|
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
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Adds tabbed interface and custom field type for globalize/json_translate
|
70
|
+
translations to rails_admin
|
71
|
+
email:
|
72
|
+
- glebtv@gmail.com
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- app/views/rails_admin/main/_form.html.haml
|
83
|
+
- app/views/rails_admin/main/_form_code_mirrorml.html.haml
|
84
|
+
- app/views/rails_admin/main/_form_fieldml.html.haml
|
85
|
+
- app/views/rails_admin/main/_form_textml.html.haml
|
86
|
+
- app/views/rails_admin/main/_form_wysihtml5ml.html.haml
|
87
|
+
- app/views/rails_admin/main/form_types/_form_simple.html.haml
|
88
|
+
- app/views/rails_admin/main/form_types/_form_tabbed.html.haml
|
89
|
+
- lib/rails_admin_translate.rb
|
90
|
+
- lib/rails_admin_translate/engine.rb
|
91
|
+
- lib/rails_admin_translate/register_instances.rb
|
92
|
+
- lib/rails_admin_translate/types.rb
|
93
|
+
- lib/rails_admin_translate/version.rb
|
94
|
+
- rails_admin_translate.gemspec
|
95
|
+
homepage: https://gitlab.com/rocket-science/rails_admin_translate
|
96
|
+
licenses:
|
97
|
+
- MIT
|
98
|
+
metadata: {}
|
99
|
+
post_install_message:
|
100
|
+
rdoc_options: []
|
101
|
+
require_paths:
|
102
|
+
- lib
|
103
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
requirements: []
|
114
|
+
rubyforge_project:
|
115
|
+
rubygems_version: 2.7.7
|
116
|
+
signing_key:
|
117
|
+
specification_version: 4
|
118
|
+
summary: Tabbed interface and custom field type for globalize / json_translate translations
|
119
|
+
for rails_admin
|
120
|
+
test_files: []
|