rails_admin_mongoid_localize_field 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +57 -0
- data/Rakefile +27 -0
- data/app/views/rails_admin/main/_form.html.haml +1 -0
- data/app/views/rails_admin/main/_form_ck_editorml.html.haml +10 -0
- data/app/views/rails_admin/main/_form_code_mirrorml.html.haml +9 -0
- data/app/views/rails_admin/main/_form_fieldml.html.haml +1 -0
- data/app/views/rails_admin/main/_form_textml.html.haml +1 -0
- data/app/views/rails_admin/main/_form_wysihtml5ml.html.haml +8 -0
- data/app/views/rails_admin/main/form_types/_form_simple.html.haml +4 -0
- data/app/views/rails_admin/main/form_types/_form_tabbed.html.haml +10 -0
- data/lib/rails_admin_mongoid_localize_field/engine.rb +4 -0
- data/lib/rails_admin_mongoid_localize_field/version.rb +3 -0
- data/lib/rails_admin_mongoid_localize_field.rb +89 -0
- metadata +116 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: efeecd1a0b13cef22913dbe9124367374df2a4fc
|
4
|
+
data.tar.gz: 7acfa81524c32de11086ec90e42092836889acef
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6081cde5d8702d02819cd1d54dc5b26347233c0699f69f2e90acdea4153d93d591c163c676fc00b11a650750fef48fb65bfa066cea0ee5c9c4d06ef86e49b0cd
|
7
|
+
data.tar.gz: 700ddfd1fdd1faa50f949d7b53246286ad347410481638a6fdbfd1c7d860cccdd133e8dc90ed473b9eed56e5a6833221a5635a0d6988b3546a508ef97f5b783d
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2012 YOURNAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# RailsAdminMongoidLocalizeField
|
2
|
+
|
3
|
+
Adds to [RailsAdmin](https://github.com/sferik/rails_admin) support for [mongoid localized fields](http://mongoid.org/en/mongoid/docs/documents.html#localized_fields).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
In your `Gemfile`add the following dependencies:
|
8
|
+
|
9
|
+
gem "rails_admin_mongoid_localize_field", "~> 0.1.2"
|
10
|
+
|
11
|
+
Run:
|
12
|
+
|
13
|
+
$ bundle install
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
Just by telling the field to `localize`:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
class Category
|
21
|
+
include Mongoid::Document
|
22
|
+
|
23
|
+
field :name, type: String, localize: true
|
24
|
+
field :description, type: String, localize: true
|
25
|
+
end
|
26
|
+
```
|
27
|
+
|
28
|
+
If you didn't like ui tabs, you can remove them and use simple form template by using `tabbed` option:
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
# config/initializer/rails_admin.rb
|
32
|
+
|
33
|
+
config.model 'Category' do
|
34
|
+
edit do
|
35
|
+
field :name do
|
36
|
+
tabbed false
|
37
|
+
end
|
38
|
+
field :description do
|
39
|
+
tabbed false
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
```
|
44
|
+
|
45
|
+
## Screenshot
|
46
|
+
|
47
|
+
![Screenshot](https://raw.github.com/sudosu/screenshots/master/rails_admin_mongoid_localize_fields.png)
|
48
|
+
|
49
|
+
|
50
|
+
## Dependencies
|
51
|
+
|
52
|
+
* haml
|
53
|
+
* mongoid >= 3.0
|
54
|
+
* rails >= 3.0
|
55
|
+
* rails_admin >= 0.5
|
56
|
+
|
57
|
+
This project rocks and uses MIT-LICENSE.
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'rdoc/task'
|
9
|
+
rescue LoadError
|
10
|
+
require 'rdoc/rdoc'
|
11
|
+
require 'rake/rdoctask'
|
12
|
+
RDoc::Task = Rake::RDocTask
|
13
|
+
end
|
14
|
+
|
15
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
16
|
+
rdoc.rdoc_dir = 'rdoc'
|
17
|
+
rdoc.title = 'RailsAdminMongoidLocalizeField'
|
18
|
+
rdoc.options << '--line-numbers'
|
19
|
+
rdoc.rdoc_files.include('README.rdoc')
|
20
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
Bundler::GemHelper.install_tasks
|
27
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
= render "rails_admin/main/form_types/#{field.tabbed ? 'form_tabbed' : 'form_simple'}", form: form, field: field, field_type: field_type, html_attributes: html_attributes
|
@@ -0,0 +1,10 @@
|
|
1
|
+
:ruby
|
2
|
+
js_data = {
|
3
|
+
:jspath => field.location ? field.location : field.base_location + "ckeditor.js",
|
4
|
+
:base_location => field.base_location,
|
5
|
+
:options => {
|
6
|
+
:customConfig => field.config_js ? field.config_js : field.base_location + "config.js"
|
7
|
+
}
|
8
|
+
}
|
9
|
+
|
10
|
+
= render 'form', form: form, field: field, field_type: :text_area, html_attributes: field.html_attributes.reverse_merge(:data => { :richtext => 'ckeditor', :options => js_data.to_json })
|
@@ -0,0 +1,9 @@
|
|
1
|
+
:ruby
|
2
|
+
js_data = {
|
3
|
+
:csspath => field.css_location,
|
4
|
+
:jspath => field.js_location,
|
5
|
+
:options => field.config,
|
6
|
+
:locations => field.assets
|
7
|
+
}
|
8
|
+
|
9
|
+
= render 'form', form: form, field: field, field_type: :text_area, html_attributes: field.html_attributes.reverse_merge(:data => { :richtext => 'codemirror', :options => js_data.to_json })
|
@@ -0,0 +1 @@
|
|
1
|
+
= render 'form', form: form, field: field, field_type: :text_field, html_attributes: field.html_attributes
|
@@ -0,0 +1 @@
|
|
1
|
+
= render 'form', form: form, field: field, field_type: :text_area, html_attributes: field.html_attributes.reverse_merge(:data => { :richtext => false, :options => {}.to_json })
|
@@ -0,0 +1,8 @@
|
|
1
|
+
:ruby
|
2
|
+
js_data = {
|
3
|
+
:csspath => field.css_location,
|
4
|
+
:jspath => field.js_location,
|
5
|
+
:config_options => field.config_options.to_json
|
6
|
+
}
|
7
|
+
|
8
|
+
= render 'form', form: form, field: field, field_type: :text_area, html_attributes: field.html_attributes.reverse_merge(:data => { :richtext => 'bootstrap-wysihtml5', :options => js_data.to_json })
|
@@ -0,0 +1,10 @@
|
|
1
|
+
%ul.nav.nav-tabs
|
2
|
+
- uuid = "#{field.name}_for_new_#{field.abstract_model.table_name}_#{SecureRandom.hex(10)}"
|
3
|
+
- I18n.available_locales.each do |locale|
|
4
|
+
%li{ class: ( 'active' if locale == I18n.locale ) }
|
5
|
+
%a{ href: "##{locale}_#{uuid}", data: { toggle: "tab" } }= locale
|
6
|
+
.tab-content{ style: 'float:left' }
|
7
|
+
= form.fields_for field.translations_field do |localized_field|
|
8
|
+
- I18n.available_locales.each do |locale|
|
9
|
+
.fields.tab-pane{ style: 'padding:5px', id: "#{locale}_#{uuid}", class: ( 'active' if locale == I18n.locale ) }
|
10
|
+
= localized_field.send field_type, locale, html_attributes.reverse_merge({ :value => field.value.try(:[], locale.to_s) })
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require "rails_admin_mongoid_localize_field/engine"
|
2
|
+
require 'active_support/concern'
|
3
|
+
require 'rails_admin/config/fields'
|
4
|
+
require 'rails_admin/config/fields/base'
|
5
|
+
require 'rails_admin/config/fields/types/string'
|
6
|
+
require 'rails_admin/config/fields/types/text'
|
7
|
+
require 'rails_admin/config/fields/types/ck_editor'
|
8
|
+
require 'rails_admin/config/fields/types/code_mirror'
|
9
|
+
require 'rails_admin/config/fields/types/wysihtml5'
|
10
|
+
|
11
|
+
module RegisterInstances
|
12
|
+
extend ActiveSupport::Concern
|
13
|
+
|
14
|
+
included do
|
15
|
+
|
16
|
+
register_instance_option :translations_field do
|
17
|
+
(name.to_s + '_translations').to_sym
|
18
|
+
end
|
19
|
+
|
20
|
+
register_instance_option :localized? do
|
21
|
+
@abstract_model.model_name.constantize.public_instance_methods.include?(translations_field)
|
22
|
+
end
|
23
|
+
|
24
|
+
register_instance_option :tabbed do
|
25
|
+
true
|
26
|
+
end
|
27
|
+
|
28
|
+
register_instance_option :allowed_methods do
|
29
|
+
localized? ? [method_name, translations_field] : [method_name]
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
module RailsAdmin
|
37
|
+
module Config
|
38
|
+
module Fields
|
39
|
+
module Types
|
40
|
+
|
41
|
+
RailsAdmin::Config::Fields::Types::Text.class_eval do
|
42
|
+
include RegisterInstances
|
43
|
+
|
44
|
+
register_instance_option :partial do
|
45
|
+
localized? ? :form_textml : :form_text
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
RailsAdmin::Config::Fields::Types::CKEditor.class_eval do
|
51
|
+
include RegisterInstances
|
52
|
+
|
53
|
+
register_instance_option :partial do
|
54
|
+
localized? ? :form_ck_editorml : :form_ck_editor
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
RailsAdmin::Config::Fields::Types::CodeMirror.class_eval do
|
60
|
+
include RegisterInstances
|
61
|
+
|
62
|
+
register_instance_option :partial do
|
63
|
+
localized? ? :form_code_mirrorml : :form_code_mirror
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
RailsAdmin::Config::Fields::Types::Wysihtml5.class_eval do
|
69
|
+
include RegisterInstances
|
70
|
+
|
71
|
+
register_instance_option :partial do
|
72
|
+
localized? ? :form_wysihtml5ml : :form_wysihtml5
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
RailsAdmin::Config::Fields::Types::String.class_eval do
|
78
|
+
include RegisterInstances
|
79
|
+
|
80
|
+
register_instance_option :partial do
|
81
|
+
localized? ? :form_fieldml : :form_field
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails_admin_mongoid_localize_field
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Oleg Popadiuk
|
8
|
+
- Rostyslav Diachok
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-01-31 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rails
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - '>='
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '3.0'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - '>='
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '3.0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: mongoid
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '3.0'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '3.0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rails_admin
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0.5'
|
49
|
+
type: :runtime
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0.5'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: haml
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :runtime
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
description: Adds to RailsAdmin support for mongoid localized fields.
|
71
|
+
email:
|
72
|
+
- superdodman@gmail.com
|
73
|
+
- infernalmaster1@gmail.com
|
74
|
+
executables: []
|
75
|
+
extensions: []
|
76
|
+
extra_rdoc_files: []
|
77
|
+
files:
|
78
|
+
- app/views/rails_admin/main/_form_wysihtml5ml.html.haml
|
79
|
+
- app/views/rails_admin/main/form_types/_form_tabbed.html.haml
|
80
|
+
- app/views/rails_admin/main/form_types/_form_simple.html.haml
|
81
|
+
- app/views/rails_admin/main/_form_fieldml.html.haml
|
82
|
+
- app/views/rails_admin/main/_form.html.haml
|
83
|
+
- app/views/rails_admin/main/_form_ck_editorml.html.haml
|
84
|
+
- app/views/rails_admin/main/_form_code_mirrorml.html.haml
|
85
|
+
- app/views/rails_admin/main/_form_textml.html.haml
|
86
|
+
- lib/rails_admin_mongoid_localize_field/engine.rb
|
87
|
+
- lib/rails_admin_mongoid_localize_field/version.rb
|
88
|
+
- lib/rails_admin_mongoid_localize_field.rb
|
89
|
+
- MIT-LICENSE
|
90
|
+
- Rakefile
|
91
|
+
- README.md
|
92
|
+
homepage: https://github.com/sudosu/rails_admin_mongoid_localize_field
|
93
|
+
licenses:
|
94
|
+
- MIT
|
95
|
+
metadata: {}
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options: []
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - '>='
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
requirements: []
|
111
|
+
rubyforge_project:
|
112
|
+
rubygems_version: 2.1.11
|
113
|
+
signing_key:
|
114
|
+
specification_version: 4
|
115
|
+
summary: RailsAdmin support for mongoid localized fields.
|
116
|
+
test_files: []
|