rails_admin_globalize_field 0.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 36f25ef423bdedceaeefca32547f96d98ab86a37
4
- data.tar.gz: 98a810b823e43070961a4dc85e246e5de6199634
3
+ metadata.gz: 0d82bc91b1dd15c273b5ad94992e73fe84727ac7
4
+ data.tar.gz: d6a33c0602ec69e2e834968680ae506b228019f2
5
5
  SHA512:
6
- metadata.gz: 054d7f5706d372d4e60e00476a1863626d8b2300370368ea72b06c5115548469c4d4e5fb69a9b7fc4c2d1d2cabec8eb6171297ab6b9f1db248bb2d3bc1f1f862
7
- data.tar.gz: d78d0a1a2e4bcf564ee2db90d46354fdaa1dd53409d1c6028ee2e84183b70aaa937b33a8a27c673eb09f3185560991d64f9e237c8928f2de1c3e0ef0eba7fe68
6
+ metadata.gz: 96c391c828ef19e44b1c865e3fc0899d406e14f388631f5a4f60a8c11b344b1b0284b92d3881983f13835e93d68b2670e0ba64149d62f45dc340f6dc0289d18c
7
+ data.tar.gz: 0f7c9aa056831121efff474a6988226089be4e89ebc811f3f720f4511f7c961ea7c90da9b8888aa38c4ba35569e3b0771cf28fa950433f9896126a4da0c7a6dd
data/README.md CHANGED
@@ -1,34 +1,25 @@
1
1
  # RailsAdminGlobalizeField
2
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)
3
+ RailsAdminGlobalizeField adds tabbed interface to [rails_admin](https://github.com/sferik/rails_admin) for multilingual models (using [globalize](https://github.com/globalize/globalize) gem)
4
4
 
5
- It creates custom field type for globalize3 translations that you can use on any translations asssociation to translated models.
5
+ It adds custom field type that you can use for globalize translations association.
6
+
7
+ This gem uses Translation models generated by globalize, so you don't need to add any additional model to your app (as some older globalize3 gists suggested).
6
8
 
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
 
9
10
  ## Installation
10
11
 
11
- > rails-4.0 compatible only for now!
12
+ Add and configure globalize gem first.
12
13
 
13
- Add and configure globalize3 gem first. **You need to use rails4 branch.**
14
14
  ``` ruby
15
- gem 'paper_trail', github: 'airblade/paper_trail'
16
- gem 'globalize3', github: 'svenfuchs/globalize3', branch: 'rails4'
15
+ gem 'globalize', '~> 4.0'
17
16
  ```
18
17
 
19
-
20
- Add this line to your application's Gemfile:
18
+ Then add this gem and run `bundle`
21
19
  ``` ruby
22
- gem 'rails_admin_globalize_field'
20
+ gem 'rails_admin_globalize_field'
23
21
  ```
24
22
 
25
- And then execute:
26
-
27
- $ bundle
28
-
29
- Or install it yourself as:
30
-
31
- $ gem install rails_admin_globalize_field
32
23
 
33
24
  ## Usage
34
25
 
@@ -37,35 +28,54 @@ Add **translation** models to `config.included_models` in `initializers/rails_ad
37
28
  config.included_models = ['Model','Model::Translation']
38
29
  ```
39
30
 
40
- Add `accepts_nested_attributes_for` for translations to your **translated** model
31
+ Add `accepts_nested_attributes_for` for translations to your **translated** model.
32
+
41
33
  ``` ruby
42
34
  class Model < ActiveRecord::Base
43
35
  translates :title, :desc
44
- accepts_nested_attributes_for :translations, :allow_destroy => true
36
+ accepts_nested_attributes_for :translations, allow_destroy: true
45
37
  end
46
38
  ```
47
39
 
48
- Add configuration to associated **translation** model:
40
+ Add configuration to your **translated** model and associated **translation** model. `:locale` field is always required.
49
41
  ``` ruby
42
+ config.model 'Post' do
43
+ configure :translations, :globalize_tabs
44
+ end
45
+
50
46
  config.model 'Model::Translation' do
51
47
  visible false
52
- configure :locale, :hidden
48
+ configure :locale, :hidden do
49
+ help ''
50
+ end
53
51
  include_fields :locale, :title, :desc
54
52
  end
55
53
  ```
56
- `:locale` field is always required.
57
54
 
58
55
 
59
- Add additional stylesheet in app/assets/stylesheets/rails_admin/theming.scss:
60
- ``` ruby
56
+ Add this stylesheet into app/assets/stylesheets/rails_admin/theming.scss:
57
+ ``` css
61
58
  /*
62
59
  *= require rails_admin/ra.globalize_tabs
63
60
  */
64
61
  ```
65
62
 
63
+
64
+ If you need to add validation to the translation class, you can add it on `translation_class` inside **translated** model:
65
+ ```ruby
66
+ translation_class.validates :title, presence: true
67
+ ```
68
+
69
+
70
+ ## Known issues
71
+
72
+ If you need to use `null: false` options on any column in translations table, you'll have to use [this globalize fork](https://github.com/scarfacedeb/globalize/tree/before_callbacks) for now.
73
+ See: https://github.com/globalize/globalize/issues/325
74
+
75
+
66
76
  ## Screenshot
67
77
 
68
- ![Screenshot](screenshots/screenshots/shot1.png)
78
+ ![Screenshot](https://raw.github.com/scarfaceDeb/rails_admin_globalize_field/screenshots/screenshots/shot1.png)
69
79
 
70
80
  ## Contributing
71
81
 
@@ -1,14 +1,17 @@
1
+
2
+ // scope all selectors (it's awful, but it's safer)
1
3
  .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 {
4
+
5
+ // Generic adjustments
6
+
7
+ .globalize-errors {
8
8
  float: right;
9
9
  margin-left: 15px;
10
+ line-height: 36px; // tabs height
11
+ }
12
+ .globalize-help {
13
+ margin-top: 10px;
14
+ margin-left: 180px; // == .form-horizontal .controls indent
10
15
  }
11
- }
12
- body.rails_admin .form-horizontal.denser .globalize_tabs_type > .help-block {
13
- margin-top: 10px;
16
+
14
17
  }
@@ -1,11 +1,16 @@
1
+ - field.translations(true) # fetch translations and memoize them
2
+
1
3
  .controls
2
- = form.errors_for(field)
4
+ .globalize-errors
5
+ = form.errors_for(field)
3
6
  %ul.nav.nav-tabs{ :style => 'margin-top:5px' }
4
7
  - field.available_locales.each do |locale|
5
8
  %li{ class: ( 'active' if locale == field.current_locale ) }
6
9
  %a{ href: "##{locale}", data: { toggle: "tab" } }= locale
7
10
  .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)
11
+ - field.available_locales.each do |locale|
12
+ = form.fields_for field.name, field.translations[locale], wrapper: false do |nested_form|
13
+ .fields.tab-pane{ id: locale, class: ( 'active' if locale == field.current_locale ) }
14
+ = nested_form.generate({:action => :nested, :model_config => field.associated_model_config, :nested_in => field.name })
15
+ .globalize-help
16
+ = form.help_for(field)
@@ -1,8 +1,4 @@
1
1
  require "rails_admin_globalize_field/engine"
2
-
3
- module RailsAdminGlobalizeField
4
- end
5
-
6
2
  require 'rails_admin/config/fields/association'
7
3
 
8
4
  module RailsAdmin
@@ -12,6 +8,12 @@ module RailsAdmin
12
8
  class GlobalizeTabs < RailsAdmin::Config::Fields::Association
13
9
  RailsAdmin::Config::Fields::Types::register(:globalize_tabs, self)
14
10
 
11
+ # A workaround for https://github.com/sferik/rails_admin/pull/1726
12
+ def initialize(parent, name, properties)
13
+ properties = parent.abstract_model.associations.detect { |p| name == p[:name] }
14
+ super
15
+ end
16
+
15
17
  register_instance_option :partial do
16
18
  :form_globalize_tabs
17
19
  end
@@ -20,6 +22,10 @@ module RailsAdmin
20
22
  "#{super}_attributes".to_sym
21
23
  end
22
24
 
25
+ def generic_help
26
+ "" # false is ignored by I18n.translate
27
+ end
28
+
23
29
  # Reader for validation errors of the bound object
24
30
  def errors
25
31
  bindings[:object].errors[name]
@@ -32,14 +38,20 @@ module RailsAdmin
32
38
  I18n.locale
33
39
  end
34
40
 
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 })
41
+ # Returns array of Translation objects.
42
+ # It gets existing or creates new empty translation for every locale.
43
+ # Call the first time with reset_cache == true to update memoized translations.
44
+ def translations reset_cache=false
45
+ return @translations if @translations && !reset_cache
46
+
47
+ translations = @bindings[:object].translations_by_locale
48
+ new_locales = available_locales - translations.keys.map(&:to_sym)
49
+
50
+ new_locales.map do |locale|
51
+ translations[locale] = @bindings[:object].translations.new({ locale: locale })
42
52
  end
53
+
54
+ @translations = translations
43
55
  end
44
56
  end
45
57
  end
@@ -48,13 +60,11 @@ module RailsAdmin
48
60
  end
49
61
 
50
62
 
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
63
+ # RailsAdmin::Config::Fields.register_factory do |parent, properties, fields|
64
+ # if properties[:name] == :translations
65
+ # fields << RailsAdmin::Config::Fields::Types::GlobalizeTabs.new(parent, properties[:name], properties)
66
+ # true
67
+ # else
68
+ # false
69
+ # end
70
+ # end
@@ -1,3 +1,3 @@
1
1
  module RailsAdminGlobalizeField
2
- VERSION = "0.2"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
8
8
  spec.version = RailsAdminGlobalizeField::VERSION
9
9
  spec.authors = ["Andrew Volozhanin"]
10
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}
11
+ spec.description = %q{Adds tabbed interface and custom field type for globalize translations to Rails_admin}
12
+ spec.summary = %q{Tabbed interface and custom field type for globalize translations for Rails_admin}
13
13
  spec.homepage = ""
14
14
  spec.license = "MIT"
15
15
 
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
23
23
  spec.add_runtime_dependency 'rails_admin', '>= 0.5'
24
24
 
25
25
  # TODO: uncomment later, when globalize3 rails4 branch would be commited to rubygems
26
- #spec.add_runtime_dependency 'globalize3', '>= 0.3'
26
+ spec.add_runtime_dependency 'globalize', '>= 4.0'
27
27
 
28
28
  spec.add_development_dependency "bundler", "~> 1.3"
29
29
  spec.add_development_dependency "rake"
metadata CHANGED
@@ -1,72 +1,86 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_admin_globalize_field
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.2'
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Volozhanin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-27 00:00:00.000000000 Z
11
+ date: 2014-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '4.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '4.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rails_admin
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0.5'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: globalize
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '4.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '4.0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: bundler
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
- - - ~>
59
+ - - "~>"
46
60
  - !ruby/object:Gem::Version
47
61
  version: '1.3'
48
62
  type: :development
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
- - - ~>
66
+ - - "~>"
53
67
  - !ruby/object:Gem::Version
54
68
  version: '1.3'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: rake
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
- - - '>='
73
+ - - ">="
60
74
  - !ruby/object:Gem::Version
61
75
  version: '0'
62
76
  type: :development
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
- - - '>='
80
+ - - ">="
67
81
  - !ruby/object:Gem::Version
68
82
  version: '0'
69
- description: Adds tabbed interface and custom field type for globalize3 translations
83
+ description: Adds tabbed interface and custom field type for globalize translations
70
84
  to Rails_admin
71
85
  email:
72
86
  - linuxheadrus@gmail.com
@@ -74,7 +88,7 @@ executables: []
74
88
  extensions: []
75
89
  extra_rdoc_files: []
76
90
  files:
77
- - .gitignore
91
+ - ".gitignore"
78
92
  - Gemfile
79
93
  - LICENSE.txt
80
94
  - README.md
@@ -96,18 +110,18 @@ require_paths:
96
110
  - lib
97
111
  required_ruby_version: !ruby/object:Gem::Requirement
98
112
  requirements:
99
- - - '>='
113
+ - - ">="
100
114
  - !ruby/object:Gem::Version
101
115
  version: '0'
102
116
  required_rubygems_version: !ruby/object:Gem::Requirement
103
117
  requirements:
104
- - - '>='
118
+ - - ">="
105
119
  - !ruby/object:Gem::Version
106
120
  version: '0'
107
121
  requirements: []
108
122
  rubyforge_project:
109
- rubygems_version: 2.0.3
123
+ rubygems_version: 2.2.0
110
124
  signing_key:
111
125
  specification_version: 4
112
- summary: Tabbed interface and custom field type for globalize3 translations for Rails_admin
126
+ summary: Tabbed interface and custom field type for globalize translations for Rails_admin
113
127
  test_files: []