activeadmin-mongoid-localize 0.0.2 → 0.1.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.
- data/README.md +7 -1
- data/activeadmin-mongoid-localize.gemspec +3 -0
- data/lib/activeadmin-mongoid-localize.rb +4 -50
- data/lib/activeadmin-mongoid-localize/field.rb +83 -0
- data/lib/activeadmin-mongoid-localize/formtastic.rb +27 -0
- data/lib/activeadmin-mongoid-localize/version.rb +1 -1
- metadata +38 -5
data/README.md
CHANGED
@@ -22,8 +22,14 @@ Really simple:
|
|
22
22
|
|
23
23
|
f.inputs do
|
24
24
|
f.localized_input :title
|
25
|
+
|
26
|
+
# and ckeditor too!
|
27
|
+
f.localized_input :content, as: :ckeditor
|
25
28
|
end
|
26
29
|
|
30
|
+
CKEditor is tested & working with my fork: https://github.com/glebtv/ckeditor
|
31
|
+
ActiveAdmin-mongoid is tested & working with my fork: https://github.com/rs-pro/activeadmin-mongoid
|
32
|
+
|
27
33
|
## Contributing
|
28
34
|
|
29
35
|
1. Fork it
|
@@ -36,4 +42,4 @@ Really simple:
|
|
36
42
|
|
37
43
|
This gem uses free flags icons from famfamfam -- http://www.famfamfam.com/lab/icons/flags/
|
38
44
|
|
39
|
-
MIT License
|
45
|
+
MIT License
|
@@ -16,4 +16,7 @@ Gem::Specification.new do |gem|
|
|
16
16
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
17
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
18
|
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_runtime_dependency(%q<mongoid>, [">= 3.0.0"])
|
21
|
+
gem.add_runtime_dependency(%q<formtastic>)
|
19
22
|
end
|
@@ -1,59 +1,13 @@
|
|
1
1
|
require "activeadmin-mongoid-localize/version"
|
2
2
|
|
3
|
+
require 'activeadmin-mongoid-localize/formtastic'
|
4
|
+
|
3
5
|
module ActiveAdmin
|
4
6
|
module Mongoid
|
5
|
-
class Hashit
|
6
|
-
def initialize(hash)
|
7
|
-
::I18n.available_locales.each do |k|
|
8
|
-
## create the getter that returns the instance variable
|
9
|
-
self.class.send(:define_method, k, proc{self.instance_variable_get("@#{k}")})
|
10
|
-
|
11
|
-
## create the setter that sets the instance variable
|
12
|
-
self.class.send(:define_method, "#{k}=", proc{|v| self.instance_variable_set("@#{k}", v)})
|
13
|
-
|
14
|
-
## create and initialize an instance variable for this key/value pair
|
15
|
-
self.instance_variable_set("@#{k}", '')
|
16
|
-
end
|
17
|
-
|
18
|
-
hash.each do |k,v|
|
19
|
-
## create and initialize an instance variable for this key/value pair
|
20
|
-
self.instance_variable_set("@#{k}", v)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
|
26
7
|
module Localize
|
27
|
-
|
28
|
-
class Engine < Rails::Engine
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
module Formtastic
|
35
|
-
class FormBuilder
|
36
|
-
def localized_input(name, args = {})
|
8
|
+
autoload :Field, 'activeadmin-mongoid-localize/field'
|
37
9
|
|
38
|
-
|
39
|
-
tv = ActiveAdmin::Mongoid::Hashit.new(t)
|
40
|
-
|
41
|
-
self.semantic_fields_for "#{name}_translations", tv do |lf|
|
42
|
-
::I18n.available_locales.each do |locale|
|
43
|
-
args[:value] = (t.nil? || t[locale.to_s].nil?) ? '' : t[locale.to_s]
|
44
|
-
# locale.to_s
|
45
|
-
|
46
|
-
label = CGI.escapeHTML(self.object.class.human_attribute_name(name)) + " #{template.image_tag "aml/flags/#{locale.to_s}.png", alt: locale.to_s, title: locale.to_s}"
|
47
|
-
if args[:as] == :ckeditor
|
48
|
-
form_buffers.last << "<h3 style='margin: 10px 0px 0px 10px;'>#{label}</h3>".html_safe
|
49
|
-
args[:label] = false
|
50
|
-
else
|
51
|
-
args[:label] = label.html_safe
|
52
|
-
end
|
53
|
-
|
54
|
-
form_buffers.last << lf.input(locale, args)
|
55
|
-
form_buffers.last
|
56
|
-
end
|
10
|
+
class Engine < Rails::Engine
|
57
11
|
end
|
58
12
|
end
|
59
13
|
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
module ActiveAdmin
|
2
|
+
module Mongoid
|
3
|
+
module Localize
|
4
|
+
|
5
|
+
class Field
|
6
|
+
extend ActiveModel::Naming
|
7
|
+
|
8
|
+
@@validators = {}
|
9
|
+
@@model = nil
|
10
|
+
|
11
|
+
def initialize(obj, name)
|
12
|
+
@obj = obj
|
13
|
+
@@model = obj.class
|
14
|
+
@field = name
|
15
|
+
@@validators[@field] = @obj.class.validators_on(name.to_sym)
|
16
|
+
@required = @@validators[@field].map(&:class).map(&:name).include? 'Mongoid::Validations::PresenceValidator'
|
17
|
+
@errors = ActiveModel::Errors.new(self)
|
18
|
+
hash = @obj.send("#{name}_translations")
|
19
|
+
|
20
|
+
::I18n.available_locales.each do |k|
|
21
|
+
## create the getter that returns the instance variable
|
22
|
+
self.class.send(:define_method, k, proc{self.instance_variable_get("@#{k}")})
|
23
|
+
|
24
|
+
## create the setter that sets the instance variable
|
25
|
+
self.class.send(:define_method, "#{k}=", proc{|v| self.instance_variable_set("@#{k}", v)})
|
26
|
+
|
27
|
+
## create and initialize an instance variable for this key/value pair
|
28
|
+
self.instance_variable_set("@#{k}", '')
|
29
|
+
end
|
30
|
+
|
31
|
+
hash.each do |k,v|
|
32
|
+
## create and initialize an instance variable for this key/value pair
|
33
|
+
self.instance_variable_set("@#{k}", v)
|
34
|
+
end
|
35
|
+
|
36
|
+
def @obj.before_validation
|
37
|
+
validate!
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def required?
|
42
|
+
@required
|
43
|
+
end
|
44
|
+
|
45
|
+
def errors
|
46
|
+
validate! if @obj.errors.any?
|
47
|
+
@errors
|
48
|
+
end
|
49
|
+
|
50
|
+
def validate!
|
51
|
+
::I18n.available_locales.each do |k|
|
52
|
+
if @required && send(k).blank?
|
53
|
+
@errors.add(k, I18n.t('errors.messages.blank'))
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def column_for_attribute(name)
|
59
|
+
# we only have one column for all locales
|
60
|
+
@obj.fields[@field]
|
61
|
+
end
|
62
|
+
|
63
|
+
def method_missing(*args)
|
64
|
+
@obj.send(*args)
|
65
|
+
end
|
66
|
+
|
67
|
+
def respond_to?(method_name, include_private = false)
|
68
|
+
@obj.respond_to?(method_name, include_private)
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.validators_on(attributized_method_name)
|
72
|
+
@@validators[attributized_method_name].nil? ? [] : @@validators[attributized_method_name]
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.human_attribute_name(*args)
|
76
|
+
@@model.send(:human_attribute_name, *args)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Formtastic
|
2
|
+
class FormBuilder
|
3
|
+
def localized_input(name, args = {})
|
4
|
+
|
5
|
+
t = self.object.send("#{name}_translations")
|
6
|
+
field = ActiveAdmin::Mongoid::Localize::Field.new(self.object, name)
|
7
|
+
|
8
|
+
self.semantic_fields_for "#{name}_translations", field do |lf|
|
9
|
+
::I18n.available_locales.each do |locale|
|
10
|
+
args[:value] = (t.nil? || t[locale.to_s].nil?) ? '' : t[locale.to_s]
|
11
|
+
|
12
|
+
label = CGI.escapeHTML(self.object.class.human_attribute_name(name)) + " #{template.image_tag "aml/flags/#{locale.to_s}.png", alt: locale.to_s, title: locale.to_s}"
|
13
|
+
if args[:as] == :ckeditor
|
14
|
+
form_buffers.last << "<h3 style='margin: 10px 0px 0px 10px;'>#{label}</h3>#{'<abbr>*</abbr>' if field.required?}".html_safe
|
15
|
+
args[:label] = false
|
16
|
+
else
|
17
|
+
args[:label] = label.html_safe
|
18
|
+
end
|
19
|
+
args[:required] = field.required?
|
20
|
+
|
21
|
+
form_buffers.last << lf.input(locale, args)
|
22
|
+
form_buffers.last
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activeadmin-mongoid-localize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,8 +9,40 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-02-
|
13
|
-
dependencies:
|
12
|
+
date: 2013-02-08 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: mongoid
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.0.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 3.0.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: formtastic
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
14
46
|
description: Easily edit mongoid localized fields in ActiveAdmin (all locales on one
|
15
47
|
page)
|
16
48
|
email:
|
@@ -274,6 +306,8 @@ files:
|
|
274
306
|
- app/assets/images/aml/flags/zm.png
|
275
307
|
- app/assets/images/aml/flags/zw.png
|
276
308
|
- lib/activeadmin-mongoid-localize.rb
|
309
|
+
- lib/activeadmin-mongoid-localize/field.rb
|
310
|
+
- lib/activeadmin-mongoid-localize/formtastic.rb
|
277
311
|
- lib/activeadmin-mongoid-localize/version.rb
|
278
312
|
homepage: https://github.com/rs-pro/activeadmin-mongoid-localize
|
279
313
|
licenses: []
|
@@ -295,9 +329,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
295
329
|
version: '0'
|
296
330
|
requirements: []
|
297
331
|
rubyforge_project:
|
298
|
-
rubygems_version: 1.8.
|
332
|
+
rubygems_version: 1.8.24
|
299
333
|
signing_key:
|
300
334
|
specification_version: 3
|
301
335
|
summary: Mongoid localized fields for active admin
|
302
336
|
test_files: []
|
303
|
-
has_rdoc:
|