activeadmin-mongoid-localize 0.3.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/README.md +20 -1
- data/lib/activeadmin-mongoid-localize.rb +13 -0
- data/lib/activeadmin-mongoid-localize/attributes_table.rb +3 -2
- data/lib/activeadmin-mongoid-localize/columns.rb +21 -0
- data/lib/activeadmin-mongoid-localize/field.rb +12 -6
- data/lib/activeadmin-mongoid-localize/formtastic.rb +7 -3
- data/lib/activeadmin-mongoid-localize/version.rb +1 -1
- metadata +14 -18
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 09d51b1e5671d396e053b03f00c39a454f04401d
|
4
|
+
data.tar.gz: ec618247e9d430cd5375713db3f1c25b040a98cd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2d46601fc54ec26879d20131766bca1ff9223dd4a8b2a935ff51f0102c42f564ecff5e38fac4067a00d3ba068edc301148c2c6ae46d4126e10064d7e6fe8d26d
|
7
|
+
data.tar.gz: 7147c36a741647200b94bb2e13c501adfedeaa017a740507a1ec4b7cb05e09dd34155f6076c51fcdf93a1ab05dd92ebadad63a1bdc1fb49247852d0269c78534
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
activeadmin-mongoid-localize
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.0.0-p247
|
data/README.md
CHANGED
@@ -4,7 +4,7 @@ Easily edit mongoid localized fields in ActiveAdmin (all locales on one page)
|
|
4
4
|
|
5
5
|
## Screenshot
|
6
6
|
|
7
|
-
![AML](
|
7
|
+
![AML](https://rscx.ru/aml.jpg)
|
8
8
|
|
9
9
|
## Installation
|
10
10
|
|
@@ -36,6 +36,11 @@ Really simple:
|
|
36
36
|
f.localized_input :content, as: :ckeditor
|
37
37
|
end
|
38
38
|
|
39
|
+
# displaying in index action
|
40
|
+
index do
|
41
|
+
localize_column :title
|
42
|
+
end
|
43
|
+
|
39
44
|
# displaying in show action
|
40
45
|
show do |f|
|
41
46
|
panel I18n.t('fields') do
|
@@ -46,6 +51,20 @@ Really simple:
|
|
46
51
|
end
|
47
52
|
end
|
48
53
|
|
54
|
+
|
55
|
+
## Configuration
|
56
|
+
|
57
|
+
By default this gem provides editable fields for all the available locales. If however, you would want to restrict to some particular locales, then create a new *'active_admin_mongoid_localize.rb'* file in the *'/config/initializers'* folder of your rails application:
|
58
|
+
|
59
|
+
|
60
|
+
ActiveAdmin::Mongoid::Localize.configure do |config|
|
61
|
+
|
62
|
+
config.locales = [:en, :ja] # Specify the locales you want to use
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
|
49
68
|
CKEditor is tested & working with my fork: https://github.com/glebtv/ckeditor
|
50
69
|
|
51
70
|
ActiveAdmin-mongoid is tested & working with my fork: https://github.com/rs-pro/activeadmin-mongoid
|
@@ -4,12 +4,25 @@ require 'activeadmin-mongoid-localize/formtastic'
|
|
4
4
|
|
5
5
|
require 'activeadmin-mongoid-localize/active_admin'
|
6
6
|
require 'activeadmin-mongoid-localize/attributes_table'
|
7
|
+
require 'activeadmin-mongoid-localize/columns'
|
7
8
|
|
8
9
|
module ActiveAdmin
|
9
10
|
module Mongoid
|
10
11
|
module Localize
|
11
12
|
autoload :Field, 'activeadmin-mongoid-localize/field'
|
12
13
|
|
14
|
+
class << self
|
15
|
+
attr_writer :locales
|
16
|
+
|
17
|
+
def locales
|
18
|
+
@locales || I18n.available_locales
|
19
|
+
end
|
20
|
+
|
21
|
+
def configure
|
22
|
+
yield self
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
13
26
|
class Engine < Rails::Engine
|
14
27
|
end
|
15
28
|
end
|
@@ -4,10 +4,11 @@ module ActiveAdmin
|
|
4
4
|
builder_method :localize_attributes_table_for
|
5
5
|
|
6
6
|
def row(attr, &block)
|
7
|
-
|
7
|
+
_locales = ActiveAdmin::Mongoid::Localize.locales
|
8
|
+
_locales.each_with_index do |locale, index|
|
8
9
|
@table << tr do
|
9
10
|
if index == 0
|
10
|
-
th :rowspan =>
|
11
|
+
th :rowspan => _locales.length do
|
11
12
|
header_content_for(attr)
|
12
13
|
end
|
13
14
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module ActiveAdmin
|
2
|
+
module Views
|
3
|
+
class IndexAsTable < ActiveAdmin::Component
|
4
|
+
class IndexTableFor < ::ActiveAdmin::Views::TableFor
|
5
|
+
|
6
|
+
# Display a column for each locale
|
7
|
+
def localize_column(attr)
|
8
|
+
ActiveAdmin::Mongoid::Localize.locales.each do |locale|
|
9
|
+
I18n.with_locale(locale) do
|
10
|
+
column_name = resource_class.human_attribute_name(attr) + " (#{locale})"
|
11
|
+
column(column_name, sortable: "#{attr}.#{locale}") do |resource|
|
12
|
+
resource.send(attr)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -8,6 +8,10 @@ module ActiveAdmin
|
|
8
8
|
@@validators = {}
|
9
9
|
@@model = nil
|
10
10
|
|
11
|
+
def clean_locale(locale)
|
12
|
+
locale.to_s.gsub('-','_')
|
13
|
+
end
|
14
|
+
|
11
15
|
def initialize(obj, name)
|
12
16
|
@obj = obj
|
13
17
|
@@model = obj.class
|
@@ -17,20 +21,22 @@ module ActiveAdmin
|
|
17
21
|
@errors = ActiveModel::Errors.new(self)
|
18
22
|
hash = @obj.send("#{name}_translations")
|
19
23
|
|
20
|
-
::
|
24
|
+
::ActiveAdmin::Mongoid::Localize.locales.each do |k|
|
25
|
+
inst_var_name = clean_locale(k)
|
21
26
|
## create the getter that returns the instance variable
|
22
|
-
self.class.send(:define_method, k, proc{self.instance_variable_get("@#{
|
27
|
+
self.class.send(:define_method, k, proc{self.instance_variable_get("@#{inst_var_name}")})
|
23
28
|
|
24
29
|
## create the setter that sets the instance variable
|
25
|
-
self.class.send(:define_method, "#{k}=", proc{|v| self.instance_variable_set("@#{
|
30
|
+
self.class.send(:define_method, "#{k}=", proc{|v| self.instance_variable_set("@#{inst_var_name}", v)})
|
26
31
|
|
27
32
|
## create and initialize an instance variable for this key/value pair
|
28
|
-
self.instance_variable_set("@#{
|
33
|
+
self.instance_variable_set("@#{inst_var_name}", '')
|
29
34
|
end
|
30
35
|
|
31
36
|
hash.each do |k,v|
|
32
37
|
## create and initialize an instance variable for this key/value pair
|
33
|
-
|
38
|
+
inst_var_name = k.to_s.gsub('-','_')
|
39
|
+
self.instance_variable_set("@#{inst_var_name}", v)
|
34
40
|
end
|
35
41
|
|
36
42
|
def @obj.before_validation
|
@@ -48,7 +54,7 @@ module ActiveAdmin
|
|
48
54
|
end
|
49
55
|
|
50
56
|
def validate!
|
51
|
-
::
|
57
|
+
::ActiveAdmin::Mongoid::Localize.locales.each do |k|
|
52
58
|
if @required && send(k).blank?
|
53
59
|
@errors.add(k, I18n.t('errors.messages.blank'))
|
54
60
|
end
|
@@ -6,10 +6,14 @@ module Formtastic
|
|
6
6
|
|
7
7
|
ret = ''
|
8
8
|
self.semantic_fields_for "#{name}_translations", field do |lf|
|
9
|
-
::
|
10
|
-
args[:value] = (t.nil? || t[locale.to_s].nil?) ? '' : t[locale.to_s]
|
9
|
+
::ActiveAdmin::Mongoid::Localize.locales.each do |locale|
|
10
|
+
args[:input_html][:value] = (t.nil? || t[locale.to_s].nil?) ? '' : t[locale.to_s]
|
11
|
+
flag_code = locale.to_s.include?("-") ? locale.to_s.split("-")[1].downcase : locale.to_s
|
11
12
|
|
12
|
-
|
13
|
+
# stupid fix to be removed
|
14
|
+
flag_code = "catalonia" if flag_code == "ca"
|
15
|
+
|
16
|
+
label = CGI.escapeHTML(self.object.class.human_attribute_name(name)) + " #{template.image_tag "aml/flags/#{flag_code}.png", alt: locale.to_s, title: locale.to_s}"
|
13
17
|
if args[:as] == :ckeditor
|
14
18
|
prepend = "<h3 style='margin: 10px 0px 0px 10px;'>#{label}</h3>#{'<abbr>*</abbr>' if field.required?}".html_safe
|
15
19
|
args[:label] = false
|
metadata
CHANGED
@@ -1,46 +1,41 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activeadmin-mongoid-localize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 1.0.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Gleb Tv
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-08-26 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: mongoid
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: 3.0.0
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - '>='
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: 3.0.0
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: formtastic
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - '>='
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :runtime
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - '>='
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
description: Easily edit mongoid localized fields in ActiveAdmin (all locales on one
|
@@ -52,6 +47,8 @@ extensions: []
|
|
52
47
|
extra_rdoc_files: []
|
53
48
|
files:
|
54
49
|
- .gitignore
|
50
|
+
- .ruby-gemset
|
51
|
+
- .ruby-version
|
55
52
|
- Gemfile
|
56
53
|
- LICENSE.txt
|
57
54
|
- README.md
|
@@ -308,32 +305,31 @@ files:
|
|
308
305
|
- lib/activeadmin-mongoid-localize.rb
|
309
306
|
- lib/activeadmin-mongoid-localize/active_admin.rb
|
310
307
|
- lib/activeadmin-mongoid-localize/attributes_table.rb
|
308
|
+
- lib/activeadmin-mongoid-localize/columns.rb
|
311
309
|
- lib/activeadmin-mongoid-localize/field.rb
|
312
310
|
- lib/activeadmin-mongoid-localize/formtastic.rb
|
313
311
|
- lib/activeadmin-mongoid-localize/version.rb
|
314
312
|
homepage: https://github.com/rs-pro/activeadmin-mongoid-localize
|
315
313
|
licenses: []
|
314
|
+
metadata: {}
|
316
315
|
post_install_message:
|
317
316
|
rdoc_options: []
|
318
317
|
require_paths:
|
319
318
|
- lib
|
320
319
|
required_ruby_version: !ruby/object:Gem::Requirement
|
321
|
-
none: false
|
322
320
|
requirements:
|
323
|
-
- -
|
321
|
+
- - '>='
|
324
322
|
- !ruby/object:Gem::Version
|
325
323
|
version: '0'
|
326
324
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
327
|
-
none: false
|
328
325
|
requirements:
|
329
|
-
- -
|
326
|
+
- - '>='
|
330
327
|
- !ruby/object:Gem::Version
|
331
328
|
version: '0'
|
332
329
|
requirements: []
|
333
330
|
rubyforge_project:
|
334
|
-
rubygems_version:
|
331
|
+
rubygems_version: 2.0.6
|
335
332
|
signing_key:
|
336
|
-
specification_version:
|
333
|
+
specification_version: 4
|
337
334
|
summary: Mongoid localized fields for active admin
|
338
335
|
test_files: []
|
339
|
-
has_rdoc:
|