rails_admin_hstore_translate 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9edd83efe8b9ba143b4f9149aa6c23f76da4c158
4
+ data.tar.gz: 0c5ab6cffab97bda6b6b1dc2616f2ddd7b606a2e
5
+ SHA512:
6
+ metadata.gz: 156054968942196e5dd74fa350371cf05b4ce4fbc7a988190e05ac6241a730ca1bcaadbd4f9adccd52e14e032ade4b5802d3b85c380b9fac8a18ff1d4249c4ff
7
+ data.tar.gz: f45478d4694002255f2bf829f61830c14d155616e9244b58367a8cf7b04a0ad8a99c626a1ffbd500435223beda7b85da0e7dadc72b4908cdc8a945b6f98347b5
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.sqlite3
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rails_admin_globalize_field.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Andrew Volozhanin
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # RailsAdminHstoreTranslate
2
+
3
+ RailsAdminHstoreTranslate adds tabbed interface to [rails_admin](https://github.com/sferik/rails_admin) for multilingual models (using [hstore_translate](https://github.com/Leadformance/hstore_translate) gem)
4
+
5
+ Heavily based on [RailsAdminGlobalizeField](https://github.com/scarfacedeb/rails_admin_globalize_field) and [rails_admin_mongoid_localize_field](https://github.com/sudosu/rails_admin_mongoid_localize_field)
6
+
7
+
8
+ It adds custom field type that you can use for globalize translations association.
9
+
10
+ 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).
11
+
12
+
13
+ ## Installation
14
+
15
+
16
+ Then add this gem and run `bundle`
17
+ ``` ruby
18
+ gem 'rails_admin_hstore_translate'
19
+ ```
20
+
21
+
22
+ ## Usage
23
+
24
+ > Don't forget to set I18n.available_locale config, because it uses that to determine what tabs to show
25
+
26
+ Add configuration to your model. `:locale` field is always required.
27
+ ``` ruby
28
+ config.model 'Post' do
29
+ field :name do
30
+ tabbed false
31
+ end
32
+ field :description do
33
+ tabbed false
34
+ end
35
+ end
36
+ ```
37
+
38
+ ## Screenshot
39
+
40
+ ![Screenshot](https://camo.githubusercontent.com/524bee72c730418105c4498ed4cdf40f861cfb1e/68747470733a2f2f7261772e6769746875622e636f6d2f7375646f73752f73637265656e73686f74732f6d61737465722f7261696c735f61646d696e5f6d6f6e676f69645f6c6f63616c697a655f6669656c64732e706e67)
41
+
42
+ ## Contributing
43
+
44
+ 1. Fork it
45
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
46
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
47
+ 4. Push to the branch (`git push origin my-new-feature`)
48
+ 5. Create new Pull Request
49
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -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 => javascript_path('ckeditor/init'),
4
+ :base_location => '/ckeditor',
5
+ :options => {
6
+ :customConfig => javascript_path('ckeditor/config')
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,46 @@
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
+ editor_size = {
10
+ width: 'auto',
11
+ heigth: '300px',
12
+ }
13
+
14
+ if field.html_attributes[:cols]
15
+ if field.html_attributes[:cols].to_s.match('%')
16
+ editor_size[:width] = field.html_attributes[:cols]
17
+ else
18
+ editor_size[:width] = "#{field.html_attributes[:cols].to_i * 8}px"
19
+ end
20
+ end
21
+
22
+ if field.html_attributes[:rows]
23
+ if field.html_attributes[:rows].to_s.match('%')
24
+ editor_size[:heigth] = field.html_attributes[:rows]
25
+ else
26
+ editor_size[:heigth] = "#{field.html_attributes[:rows].to_i * 20}px"
27
+ end
28
+ end
29
+
30
+ - uniqid = "code_mirror_#{SecureRandom.hex(10)}"
31
+
32
+ :css
33
+ ##{uniqid} .CodeMirror {
34
+ width: #{editor_size[:width]};
35
+ height: #{editor_size[:heigth]};
36
+ }
37
+
38
+ :javascript
39
+ $(document).on('click', '##{uniqid} .nav.nav-tabs li a', function(e){
40
+ $('##{uniqid} .tab-content '+ $(this).attr('href') + ' .CodeMirror').each(function(i, el){
41
+ el.CodeMirror.refresh();
42
+ });
43
+ });
44
+
45
+ %div{id: uniqid}
46
+ = 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,7 @@
1
+ = form.fields_for field.translations_field do |localized_field|
2
+ - I18n.available_locales.each do |locale|
3
+ - val = form.object.send("#{field.name}_translations").try(:[], locale.to_s)
4
+ %div
5
+ = localized_field.label locale
6
+ = localized_field.send field_type, locale, html_attributes.reverse_merge({ :value => field.value.try(:[], locale.to_s) })
7
+
@@ -0,0 +1,23 @@
1
+
2
+ %ul.nav.nav-tabs
3
+ - uuid = "#{field.name}_#{field.object_id}_unique_id"
4
+ - I18n.available_locales.each do |locale|
5
+ %li{ class: ( 'active' if locale == I18n.locale ) }
6
+ %a{ href: "##{locale}_#{uuid}", data: { toggle: "tab" }, class: uuid }= locale
7
+ .tab-content
8
+ = form.fields_for field.translations_field do |localized_field|
9
+ - I18n.available_locales.each do |locale|
10
+ - val = form.object.send("#{field.name}_translations").try(:[], locale.to_s)
11
+ .fields.tab-pane{ style: 'padding:5px; margin: 0;', id: "#{locale}_#{uuid}", class: [( 'active' if locale == I18n.locale ), uuid] }
12
+ = localized_field.send field_type, locale, html_attributes.reverse_merge({ :value => val })
13
+
14
+ :javascript
15
+ var #{field.name}#{field.object_id} = (new Date().getTime()) + Math.floor(Math.random()*100000);
16
+ $("ul.nav.nav-tabs a.#{uuid}").each(function(e){
17
+ this.href = $(this).attr('href').replace('_unique_id', #{field.name}#{field.object_id});
18
+ $(this).removeClass('#{uuid}');
19
+ });
20
+ $(".tab-content .#{uuid}").each(function(e){
21
+ this.id = this.id.replace('_unique_id', #{field.name}#{field.object_id});
22
+ $(this).removeClass('#{uuid}');
23
+ });
@@ -0,0 +1,4 @@
1
+ module RailsAdminHstoreTranslate
2
+ class Engine < ::Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module RailsAdminHstoreTranslate
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,92 @@
1
+ require 'rails_admin_hstore_translate/engine'
2
+ require 'rails_admin'
3
+ require 'hstore_translate'
4
+
5
+ require 'active_support/concern'
6
+ require 'rails_admin/config/fields'
7
+ require 'rails_admin/config/fields/base'
8
+ require 'rails_admin/config/fields/types/string'
9
+ require 'rails_admin/config/fields/types/text'
10
+ require 'rails_admin/config/fields/types/ck_editor'
11
+ require 'rails_admin/config/fields/types/code_mirror'
12
+ require 'rails_admin/config/fields/types/wysihtml5'
13
+
14
+ module RegisterInstances
15
+ extend ActiveSupport::Concern
16
+
17
+ included do
18
+
19
+ register_instance_option :translations_field do
20
+ (name.to_s + '_translations').to_sym
21
+ end
22
+
23
+ register_instance_option :localized? do
24
+ @abstract_model.model_name.constantize.public_instance_methods.include?(translations_field)
25
+ end
26
+
27
+ register_instance_option :tabbed do
28
+ true
29
+ end
30
+
31
+ register_instance_option :allowed_methods do
32
+ localized? ? [method_name, translations_field] : [method_name]
33
+ end
34
+
35
+ end
36
+
37
+ end
38
+
39
+ module RailsAdmin
40
+ module Config
41
+ module Fields
42
+ module Types
43
+
44
+ RailsAdmin::Config::Fields::Types::Text.class_eval do
45
+ include RegisterInstances
46
+
47
+ register_instance_option :partial do
48
+ localized? ? :form_textml : :form_text
49
+ end
50
+
51
+ end
52
+
53
+ RailsAdmin::Config::Fields::Types::CKEditor.class_eval do
54
+ include RegisterInstances
55
+
56
+ register_instance_option :partial do
57
+ localized? ? :form_ck_editorml : :form_ck_editor
58
+ end
59
+
60
+ end
61
+
62
+ RailsAdmin::Config::Fields::Types::CodeMirror.class_eval do
63
+ include RegisterInstances
64
+
65
+ register_instance_option :partial do
66
+ localized? ? :form_code_mirrorml : :form_code_mirror
67
+ end
68
+
69
+ end
70
+
71
+ RailsAdmin::Config::Fields::Types::Wysihtml5.class_eval do
72
+ include RegisterInstances
73
+
74
+ register_instance_option :partial do
75
+ localized? ? :form_wysihtml5ml : :form_wysihtml5
76
+ end
77
+
78
+ end
79
+
80
+ RailsAdmin::Config::Fields::Types::String.class_eval do
81
+ include RegisterInstances
82
+
83
+ register_instance_option :partial do
84
+ localized? ? :form_fieldml : :form_field
85
+ end
86
+
87
+ end
88
+
89
+ end
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rails_admin_hstore_translate/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rails_admin_hstore_translate"
8
+ spec.version = RailsAdminHstoreTranslate::VERSION
9
+ spec.authors = ["GlebTv"]
10
+ spec.email = ["glebtv@gmail.com"]
11
+ spec.description = %q{Adds tabbed interface and custom field type for hstore_translate translations to rails_admin}
12
+ spec.summary = %q{Tabbed interface and custom field type for hstore_translate translations for rails_admin}
13
+ spec.homepage = "https://github.com/glebtv/rails_admin_hstore_translate"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "rails", '~> 4.2'
22
+ spec.add_dependency 'rails_admin', '>= 0.6.2'
23
+ spec.add_dependency 'hstore_translate'
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.10"
26
+ spec.add_development_dependency "rake"
27
+ end
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails_admin_hstore_translate
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - GlebTv
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-07-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rails_admin
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.6.2
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 0.6.2
41
+ - !ruby/object:Gem::Dependency
42
+ name: hstore_translate
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.10'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.10'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Adds tabbed interface and custom field type for hstore_translate translations
84
+ to rails_admin
85
+ email:
86
+ - glebtv@gmail.com
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - app/views/rails_admin/main/_form.html.haml
97
+ - app/views/rails_admin/main/_form_ck_editorml.html.haml
98
+ - app/views/rails_admin/main/_form_code_mirrorml.html.haml
99
+ - app/views/rails_admin/main/_form_fieldml.html.haml
100
+ - app/views/rails_admin/main/_form_textml.html.haml
101
+ - app/views/rails_admin/main/_form_wysihtml5ml.html.haml
102
+ - app/views/rails_admin/main/form_types/_form_simple.html.haml
103
+ - app/views/rails_admin/main/form_types/_form_tabbed.html.haml
104
+ - lib/rails_admin_hstore_translate.rb
105
+ - lib/rails_admin_hstore_translate/engine.rb
106
+ - lib/rails_admin_hstore_translate/version.rb
107
+ - rails_admin_hstore_translate.gemspec
108
+ homepage: https://github.com/glebtv/rails_admin_hstore_translate
109
+ licenses:
110
+ - MIT
111
+ metadata: {}
112
+ post_install_message:
113
+ rdoc_options: []
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ requirements: []
127
+ rubyforge_project:
128
+ rubygems_version: 2.4.5
129
+ signing_key:
130
+ specification_version: 4
131
+ summary: Tabbed interface and custom field type for hstore_translate translations
132
+ for rails_admin
133
+ test_files: []