Skip to content

Commit 8ac8dee

Browse files
author
Rob Florence
authored
Merge pull request #1 from fabn/develop
Update from fabn fork
2 parents b5d61a7 + 49c219d commit 8ac8dee

30 files changed

+304
-56
lines changed

.travis.yml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
1+
sudo: false
12
language: ruby
3+
# Limit ruby versions to currently supported versions to avoid a big build matrix
24
rvm:
3-
- 1.9.3
4-
- 2.0.0
5+
- 2.2
6+
- 2.3.0
7+
# Update bundler on travis, since current one is broken, see https://github.com/rubygems/rubygems/issues/1419
8+
before_install:
9+
- gem install bundler
510
# Load database schema before rake
6-
before_script: bundle exec rake db:schema:load
11+
before_script: bundle exec rake db:schema:load
12+
# Test on all supported rails versions
13+
gemfile:
14+
- gemfiles/activeadmin_master.gemfile
15+
- gemfiles/rails4_1.gemfile
16+
- gemfiles/rails4_2.gemfile

Appraisals

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
appraise 'rails4_1' do
2+
gem 'rails', '~> 4.1.12'
3+
gem 'globalize', '~> 4.0.3'
4+
end
5+
6+
appraise 'rails4_2' do
7+
gem 'rails', '~> 4.2.3'
8+
gem 'globalize', '~> 5.0.0'
9+
end
10+
11+
# Run tests on latest github version of ActiveAdmin
12+
appraise 'activeadmin_master' do
13+
gem 'rails', '~> 4.2.0'
14+
gem 'activeadmin', github: 'activeadmin/activeadmin'
15+
end

Gemfile

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ gemspec
1414
# gem 'debugger'
1515

1616
# Gems used by the dummy application
17-
gem 'rails', '~> 4.0.0'
18-
gem 'sass-rails', '~> 4.0.2'
17+
gem 'sass-rails'
1918
gem 'coffee-rails'
2019

2120
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
@@ -25,21 +24,21 @@ gem 'uglifier'
2524
# jquery-rails is
2625
gem 'jquery-rails'
2726

28-
# Fetch activeadmin from github until is released
29-
gem 'devise'
27+
# ActiveAdmin requires devise < 4.0
28+
gem 'devise', '~> 3.2'
3029

3130
group :test do
3231
gem 'sqlite3', '~> 1.3.5'
3332
gem 'rspec-rails', '~> 2.14.0'
3433
gem 'factory_girl_rails', '~> 4.2.1'
3534
gem 'database_cleaner', '~> 1.0.1'
36-
gem 'guard-rspec', require: false
3735
gem 'spring', require: false
3836
gem 'spring-commands-rspec', require: false
3937
gem 'capybara', '~> 2.1.0'
4038
gem 'capybara-screenshot'
4139
gem 'poltergeist'
4240
gem 'fuubar'
41+
gem 'appraisal'
4342
# Useful to debug tests
4443
gem 'awesome_print'
4544
gem 'pry'

Guardfile

Lines changed: 0 additions & 16 deletions
This file was deleted.

README.md

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,30 +25,79 @@ active_admin_translates :title, :description do
2525
validates_presence_of :title
2626
end
2727
```
28-
## Editor configuration
28+
## In your Active Admin resource definition
29+
30+
**Important note:** I'm working on a fix for #4 because after AA deprecated and then removed [#form_buffers](https://github.com/activeadmin/activeadmin/pull/3486) the
31+
syntax shown below for form declaration doesn't work as is. See comments in code and [discussion](#4) to fix it until I found a solution.
2932

3033
```ruby
3134

3235
# For usage with strong parameters you'll need to permit them
33-
permit_params translations_attributes: [:id, :locale, :title, :content, :_destroy]
36+
permit_params translations_attributes: [:id, :locale, :title, :description, :_destroy]
3437

3538
index do
3639
# textual translation status
3740
translation_status
3841
# or with flag icons
3942
translation_status_flags
4043
# ...
41-
default_actions
44+
actions
4245
end
4346

47+
# This was the original syntax proposed in this gem, however currently it doesn't work
4448
form do |f|
4549
# ...
4650
f.translated_inputs "Translated fields", switch_locale: false do |t|
4751
t.input :title
48-
t.input :content
52+
t.input :description
4953
end
5054
# ...
5155
end
56+
57+
# Instead you have to nest the block inside an #inputs block and the title
58+
# should be passed to the inputs method
59+
form do |f|
60+
# ...
61+
f.inputs "Translated fields" do
62+
f.translated_inputs 'ignored title', switch_locale: false do |t|
63+
t.input :title
64+
t.input :description
65+
end
66+
end
67+
# ...
68+
end
69+
70+
# You can also set locales to show in tabs
71+
# For example we want to show English translation fields without tab, and want to show other languages within tabs
72+
form do |f|
73+
# ...
74+
f.inputs do
75+
Globalize.with_locale(:en) do
76+
f.input :title
77+
end
78+
end
79+
f.inputs "Translated fields" do
80+
f.translated_inputs 'ignored title', switch_locale: false, available_locales: (I18n.available_locales - [:en]) do |t|
81+
t.input :title
82+
t.input :description
83+
end
84+
end
85+
# ...
86+
end
87+
88+
# You can also set default language tab
89+
# For example we want to make Bengali translation tab as default
90+
form do |f|
91+
# ...
92+
f.inputs "Translated fields" do
93+
f.translated_inputs 'ignored title', switch_locale: false, default_locale: :bn do |t|
94+
t.input :title
95+
t.input :description
96+
end
97+
end
98+
# ...
99+
end
100+
52101
```
53102
If `switch_locale` is set, each tab will be rendered switching locale.
54103

activeadmin-globalize.gemspec

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ Gem::Specification.new do |s|
1616
s.files = Dir['{app,config,db,lib}/**/*'] + %w(MIT-LICENSE README.md)
1717

1818
s.add_dependency 'activeadmin', '~> 1.0.0.pre'
19-
s.add_dependency 'globalize', '~> 4.0'
19+
# Try to support rails from 3.2 up to 4.2.x
20+
s.add_dependency 'globalize', '>= 3.1.0', '< 6.0'
2021

2122
# development dependencies
2223
s.add_development_dependency 'bundler', '>= 1.6.1'
119 Bytes
Loading
-42 Bytes
Binary file not shown.

app/assets/javascripts/active_admin/active_admin_globalize.js.coffee

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ $ ->
148148
$td = $(this).closest('td')
149149
$('.field-translation', $td).hide()
150150
$(".locale-#{$locale}", $td).show()
151+
$(this).parent().children('a.ui-translation-trigger').removeClass('active')
152+
$(this).addClass('active')
151153
e.preventDefault()
152154

153155
translations()
154-

0 commit comments

Comments
 (0)