rails_admin_globalize_field 0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +76 -0
- data/Rakefile +1 -0
- data/app/assets/stylesheets/rails_admin/ra.globalize_tabs.scss +14 -0
- data/app/views/.gitkeep +0 -0
- data/app/views/rails_admin/main/_form_globalize_tabs.html.haml +11 -0
- data/lib/rails_admin_globalize_field.rb +60 -0
- data/lib/rails_admin_globalize_field/engine.rb +4 -0
- data/lib/rails_admin_globalize_field/version.rb +3 -0
- data/rails_admin_globalize_field.gemspec +30 -0
- metadata +113 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 36f25ef423bdedceaeefca32547f96d98ab86a37
|
4
|
+
data.tar.gz: 98a810b823e43070961a4dc85e246e5de6199634
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 054d7f5706d372d4e60e00476a1863626d8b2300370368ea72b06c5115548469c4d4e5fb69a9b7fc4c2d1d2cabec8eb6171297ab6b9f1db248bb2d3bc1f1f862
|
7
|
+
data.tar.gz: d78d0a1a2e4bcf564ee2db90d46354fdaa1dd53409d1c6028ee2e84183b70aaa937b33a8a27c673eb09f3185560991d64f9e237c8928f2de1c3e0ef0eba7fe68
|
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,76 @@
|
|
1
|
+
# RailsAdminGlobalizeField
|
2
|
+
|
3
|
+
RailsAdminGlobalizeField adds tabbed interface to [rails_admin](https://github.com/sferik/rails_admin) for multilingual models (using [globalize3](https://github.com/svenfuchs/globalize3) gem)
|
4
|
+
|
5
|
+
It creates custom field type for globalize3 translations that you can use on any translations asssociation to translated models.
|
6
|
+
|
7
|
+
This gem uses Translation models generated by globalize3, so you don't need to add any additional models to your project (as some older globalize3 gists suggested).
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
> rails-4.0 compatible only for now!
|
12
|
+
|
13
|
+
Add and configure globalize3 gem first. **You need to use rails4 branch.**
|
14
|
+
``` ruby
|
15
|
+
gem 'paper_trail', github: 'airblade/paper_trail'
|
16
|
+
gem 'globalize3', github: 'svenfuchs/globalize3', branch: 'rails4'
|
17
|
+
```
|
18
|
+
|
19
|
+
|
20
|
+
Add this line to your application's Gemfile:
|
21
|
+
``` ruby
|
22
|
+
gem 'rails_admin_globalize_field'
|
23
|
+
```
|
24
|
+
|
25
|
+
And then execute:
|
26
|
+
|
27
|
+
$ bundle
|
28
|
+
|
29
|
+
Or install it yourself as:
|
30
|
+
|
31
|
+
$ gem install rails_admin_globalize_field
|
32
|
+
|
33
|
+
## Usage
|
34
|
+
|
35
|
+
Add **translation** models to `config.included_models` in `initializers/rails_admin.rb`:
|
36
|
+
``` ruby
|
37
|
+
config.included_models = ['Model','Model::Translation']
|
38
|
+
```
|
39
|
+
|
40
|
+
Add `accepts_nested_attributes_for` for translations to your **translated** model
|
41
|
+
``` ruby
|
42
|
+
class Model < ActiveRecord::Base
|
43
|
+
translates :title, :desc
|
44
|
+
accepts_nested_attributes_for :translations, :allow_destroy => true
|
45
|
+
end
|
46
|
+
```
|
47
|
+
|
48
|
+
Add configuration to associated **translation** model:
|
49
|
+
``` ruby
|
50
|
+
config.model 'Model::Translation' do
|
51
|
+
visible false
|
52
|
+
configure :locale, :hidden
|
53
|
+
include_fields :locale, :title, :desc
|
54
|
+
end
|
55
|
+
```
|
56
|
+
`:locale` field is always required.
|
57
|
+
|
58
|
+
|
59
|
+
Add additional stylesheet in app/assets/stylesheets/rails_admin/theming.scss:
|
60
|
+
``` ruby
|
61
|
+
/*
|
62
|
+
*= require rails_admin/ra.globalize_tabs
|
63
|
+
*/
|
64
|
+
```
|
65
|
+
|
66
|
+
## Screenshot
|
67
|
+
|
68
|
+
![Screenshot](screenshots/screenshots/shot1.png)
|
69
|
+
|
70
|
+
## Contributing
|
71
|
+
|
72
|
+
1. Fork it
|
73
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
74
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
75
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
76
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,14 @@
|
|
1
|
+
.globalize_tabs_type {
|
2
|
+
& > .help-block {
|
3
|
+
margin-left: 180px;
|
4
|
+
padding-top: 5px;
|
5
|
+
border-top: 1px solid #ddd;
|
6
|
+
}
|
7
|
+
& > .controls > .help-inline {
|
8
|
+
float: right;
|
9
|
+
margin-left: 15px;
|
10
|
+
}
|
11
|
+
}
|
12
|
+
body.rails_admin .form-horizontal.denser .globalize_tabs_type > .help-block {
|
13
|
+
margin-top: 10px;
|
14
|
+
}
|
data/app/views/.gitkeep
ADDED
File without changes
|
@@ -0,0 +1,11 @@
|
|
1
|
+
.controls
|
2
|
+
= form.errors_for(field)
|
3
|
+
%ul.nav.nav-tabs{ :style => 'margin-top:5px' }
|
4
|
+
- field.available_locales.each do |locale|
|
5
|
+
%li{ class: ( 'active' if locale == field.current_locale ) }
|
6
|
+
%a{ href: "##{locale}", data: { toggle: "tab" } }= locale
|
7
|
+
.tab-content
|
8
|
+
= form.fields_for field.name, field.translations, wrapper: false do |nested_form|
|
9
|
+
.fields.tab-pane{ id: nested_form.object.locale, class: ( 'active' if nested_form.object.locale == field.current_locale ) }
|
10
|
+
= nested_form.generate({:action => :nested, :model_config => field.associated_model_config, :nested_in => field.name })
|
11
|
+
= form.help_for(field)
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require "rails_admin_globalize_field/engine"
|
2
|
+
|
3
|
+
module RailsAdminGlobalizeField
|
4
|
+
end
|
5
|
+
|
6
|
+
require 'rails_admin/config/fields/association'
|
7
|
+
|
8
|
+
module RailsAdmin
|
9
|
+
module Config
|
10
|
+
module Fields
|
11
|
+
module Types
|
12
|
+
class GlobalizeTabs < RailsAdmin::Config::Fields::Association
|
13
|
+
RailsAdmin::Config::Fields::Types::register(:globalize_tabs, self)
|
14
|
+
|
15
|
+
register_instance_option :partial do
|
16
|
+
:form_globalize_tabs
|
17
|
+
end
|
18
|
+
|
19
|
+
def method_name
|
20
|
+
"#{super}_attributes".to_sym
|
21
|
+
end
|
22
|
+
|
23
|
+
# Reader for validation errors of the bound object
|
24
|
+
def errors
|
25
|
+
bindings[:object].errors[name]
|
26
|
+
end
|
27
|
+
|
28
|
+
def available_locales
|
29
|
+
I18n.available_locales
|
30
|
+
end
|
31
|
+
def current_locale
|
32
|
+
I18n.locale
|
33
|
+
end
|
34
|
+
|
35
|
+
# Returns array of Translation objects
|
36
|
+
# It gets existing or creates new empty translation for every locale
|
37
|
+
# It's used in fields_for method in partial
|
38
|
+
def translations
|
39
|
+
translated_locales = @bindings[:object].translated_locales
|
40
|
+
available_locales.collect do |locale|
|
41
|
+
translated_locales.include?(locale) ? @bindings[:object].translation_for(locale) : @bindings[:object].translations.new({ locale: locale })
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
# TODO: apply it only on `configure :translations, :globalize_tabs` fields?
|
52
|
+
# see: https://github.com/sferik/rails_admin/pull/1726
|
53
|
+
RailsAdmin::Config::Fields.register_factory do |parent, properties, fields|
|
54
|
+
if properties[:name] == :translations
|
55
|
+
fields << RailsAdmin::Config::Fields::Types::GlobalizeTabs.new(parent, properties[:name], properties)
|
56
|
+
true
|
57
|
+
else
|
58
|
+
false
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,30 @@
|
|
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_globalize_field/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rails_admin_globalize_field"
|
8
|
+
spec.version = RailsAdminGlobalizeField::VERSION
|
9
|
+
spec.authors = ["Andrew Volozhanin"]
|
10
|
+
spec.email = ["linuxheadrus@gmail.com"]
|
11
|
+
spec.description = %q{Adds tabbed interface and custom field type for globalize3 translations to Rails_admin}
|
12
|
+
spec.summary = %q{Tabbed interface and custom field type for globalize3 translations for Rails_admin}
|
13
|
+
spec.homepage = ""
|
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
|
+
# TODO: test on earlier versions
|
22
|
+
spec.add_runtime_dependency "rails", ">= 4.0"
|
23
|
+
spec.add_runtime_dependency 'rails_admin', '>= 0.5'
|
24
|
+
|
25
|
+
# TODO: uncomment later, when globalize3 rails4 branch would be commited to rubygems
|
26
|
+
#spec.add_runtime_dependency 'globalize3', '>= 0.3'
|
27
|
+
|
28
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
29
|
+
spec.add_development_dependency "rake"
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails_admin_globalize_field
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.2'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andrew Volozhanin
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-08-27 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: '4.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.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.5'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.5'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.3'
|
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 globalize3 translations
|
70
|
+
to Rails_admin
|
71
|
+
email:
|
72
|
+
- linuxheadrus@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/assets/stylesheets/rails_admin/ra.globalize_tabs.scss
|
83
|
+
- app/views/.gitkeep
|
84
|
+
- app/views/rails_admin/main/_form_globalize_tabs.html.haml
|
85
|
+
- lib/rails_admin_globalize_field.rb
|
86
|
+
- lib/rails_admin_globalize_field/engine.rb
|
87
|
+
- lib/rails_admin_globalize_field/version.rb
|
88
|
+
- rails_admin_globalize_field.gemspec
|
89
|
+
homepage: ''
|
90
|
+
licenses:
|
91
|
+
- MIT
|
92
|
+
metadata: {}
|
93
|
+
post_install_message:
|
94
|
+
rdoc_options: []
|
95
|
+
require_paths:
|
96
|
+
- lib
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - '>='
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
requirements: []
|
108
|
+
rubyforge_project:
|
109
|
+
rubygems_version: 2.0.3
|
110
|
+
signing_key:
|
111
|
+
specification_version: 4
|
112
|
+
summary: Tabbed interface and custom field type for globalize3 translations for Rails_admin
|
113
|
+
test_files: []
|