activeadmin-globalize3 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Andrea Pavoni http://andreapavoni.com
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.
@@ -0,0 +1,39 @@
1
+ # ActiveAdmin::Globalize3
2
+ Makes it easy to translate your resource fields.
3
+
4
+ ## Installation
5
+
6
+ ```ruby
7
+ gem "activeadmin-globalize3"
8
+ ```
9
+ ## Your model
10
+
11
+ ```ruby
12
+ active_admin_translates :title, :description do
13
+ validates_presence_of :title
14
+ end
15
+ ```
16
+ ## Editor configuration
17
+
18
+ ```ruby
19
+ index do
20
+ # ...
21
+ translation_status
22
+ # ...
23
+ default_actions
24
+ end
25
+
26
+ form do |f|
27
+ # ...
28
+ f.translated_inputs "Translated fields" do |t|
29
+ t.input :title
30
+ t.input :content
31
+ end
32
+ # ...
33
+ end
34
+ ```
35
+
36
+ ## Friendly ID
37
+
38
+ If you want to use Friendly ID together with Globalize3, please take a look
39
+ at the `activeadmin-seo` gem.
@@ -0,0 +1,24 @@
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 = 'SimpleFormGlobalize'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+ Bundler::GemHelper.install_tasks
24
+
@@ -0,0 +1,29 @@
1
+ $ ->
2
+
3
+ translations = ->
4
+ $(".activeadmin-translations > ul").each ->
5
+ $dom = $(this)
6
+ if !$dom.data("ready")
7
+ $dom.data("ready", true)
8
+ $tabs = $("li > a", this)
9
+ $contents = $(this).siblings("fieldset")
10
+
11
+ $tabs.click ->
12
+ $tab = $(this)
13
+ $tabs.not($tab).removeClass("active")
14
+ $tab.addClass("active")
15
+ $contents.hide()
16
+ $contents.filter($tab.attr("href")).show()
17
+ false
18
+
19
+ $tabs.eq(0).click()
20
+
21
+ # this is to handle elements created with has_many
22
+ $(document).on "click", "a", ->
23
+ setTimeout(
24
+ -> translations()
25
+ 50
26
+ )
27
+
28
+ translations()
29
+
@@ -0,0 +1,42 @@
1
+ @import "active_admin/mixins"
2
+
3
+ .active_admin
4
+ .activeadmin-translations
5
+ margin-bottom: 20px
6
+
7
+ &> ul
8
+ position: relative
9
+ z-index: 2
10
+ top: 4px
11
+ padding: 0 10px
12
+
13
+ &> li
14
+ display: inline-block
15
+
16
+ &> a
17
+ display: inline-block
18
+ color: #666
19
+ margin-right: 3px
20
+ text-decoration: none
21
+ font-size: 17px
22
+ padding: 8px 15px
23
+ padding-bottom: 8px + 4px
24
+ margin-bottom: 0
25
+
26
+ &.active
27
+ background: #f4f4f4
28
+ +inset-shadow(0, 4px, 4px, #ddd)
29
+ +border-top-radius(4px)
30
+ margin-bottom: 0
31
+ +gradient($secondary-gradient-stop, #f4f4f4)
32
+ text-shadow: 0 1px 0 white
33
+
34
+ &> fieldset.inputs
35
+ margin-bottom: 0
36
+
37
+ ol
38
+ padding-left: 0
39
+ width: 100%
40
+
41
+ li.hidden
42
+ padding: 0 !important
@@ -0,0 +1,7 @@
1
+ en:
2
+ active_admin:
3
+ globalize3:
4
+ translations: "Translations"
5
+ language:
6
+ it: "Italian"
7
+ en: "English"
@@ -0,0 +1,7 @@
1
+ it:
2
+ active_admin:
3
+ globalize3:
4
+ translations: "Traduzioni"
5
+ language:
6
+ it: "Italiano"
7
+ en: "Inglese"
@@ -0,0 +1,13 @@
1
+ require 'globalize3'
2
+ require 'activeadmin'
3
+
4
+ require 'active_admin/views/index_as_table'
5
+ require 'active_admin/globalize3/engine'
6
+ require 'active_admin/globalize3/form_builder_extension'
7
+ require 'active_admin/globalize3/active_record_extension'
8
+ require 'active_admin/globalize3/index_table_for_extension'
9
+
10
+ ActiveRecord::Base.send :extend, ActiveAdmin::Globalize3::ActiveRecordExtension
11
+
12
+ ActiveAdmin::FormBuilder.send :include, ActiveAdmin::Globalize3::FormBuilderExtension
13
+ ActiveAdmin::Views::IndexAsTable::IndexTableFor.send :include, ActiveAdmin::Globalize3::IndexTableFor
@@ -0,0 +1,30 @@
1
+ module ActiveAdmin::Globalize3
2
+ module ActiveRecordExtension
3
+
4
+ module Methods
5
+ def translation_names
6
+ self.translations.map(&:locale).map do |locale|
7
+ I18n.t("active_admin.globalize3.language.#{locale}")
8
+ end.uniq.sort
9
+ end
10
+ end
11
+
12
+ def active_admin_translates(*args, &block)
13
+ translates(*args.dup)
14
+ args.extract_options!
15
+
16
+ if block
17
+ translation_class.instance_eval &block
18
+ end
19
+ translation_class.attr_accessible :locale
20
+ translation_class.attr_accessible *args
21
+
22
+ attr_accessible :translations_attributes
23
+ accepts_nested_attributes_for :translations, allow_destroy: true
24
+
25
+ include Methods
26
+ end
27
+
28
+ end
29
+ end
30
+
@@ -0,0 +1,18 @@
1
+ module ActiveAdmin
2
+ module Globalize3
3
+ class Engine < ::Rails::Engine
4
+ initializer "Railsyard precompile hook" do |app|
5
+ app.config.assets.precompile += [
6
+ "active_admin/active_admin_globalize3.css",
7
+ "active_admin/active_admin_globalize3.js"
8
+ ]
9
+ end
10
+
11
+ initializer "add assets" do
12
+ ActiveAdmin.application.register_stylesheet "active_admin/active_admin_globalize3.css", :media => :screen
13
+ ActiveAdmin.application.register_javascript "active_admin/active_admin_globalize3.js"
14
+ end
15
+
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,36 @@
1
+ module ActiveAdmin
2
+ module Globalize3
3
+ module FormBuilderExtension
4
+ extend ActiveSupport::Concern
5
+
6
+ def translated_inputs(name = "Translations", &block)
7
+ form_buffers.last << template.content_tag(:div, class: "activeadmin-translations") do
8
+ template.content_tag(:ul, class: "available-locales") do
9
+ I18n.available_locales.sort.map do |locale|
10
+ template.content_tag(:li) do
11
+ template.content_tag(:a, I18n.t(:"active_admin.globalize3.language.#{locale}"), href:".locale-#{locale}")
12
+ end
13
+ end.join.html_safe
14
+ end <<
15
+ I18n.available_locales.sort.map do |locale|
16
+ translation = object.translations.find { |t| t.locale.to_s == locale.to_s }
17
+ translation ||= object.translations.build(locale: locale)
18
+ fields = proc do |form|
19
+ form.input(:locale, as: :hidden)
20
+ form.input(:id, as: :hidden)
21
+ block.call(form)
22
+ end
23
+ inputs_for_nested_attributes(
24
+ for: [:translations, translation ],
25
+ class: "inputs locale locale-#{translation.locale}",
26
+ &fields
27
+ )
28
+ end.join.html_safe
29
+ end
30
+ end
31
+
32
+ module ClassMethods
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,16 @@
1
+ require 'active_admin/views/components/status_tag'
2
+
3
+ module ActiveAdmin
4
+ module Globalize3
5
+ module IndexTableFor
6
+ def translation_status
7
+ column I18n.t("active_admin.globalize3.translations") do |obj|
8
+ obj.translation_names.map do |t|
9
+ '<span class="status_tag">%s</span>' % t
10
+ end.join(" ").html_safe
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
16
+
@@ -0,0 +1,5 @@
1
+ module ActiveAdmin
2
+ module Globalize3
3
+ VERSION = "0.0.2"
4
+ end
5
+ end
@@ -0,0 +1 @@
1
+ require 'active_admin/globalize'
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: activeadmin-globalize3
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Stefano Verna
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-22 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activeadmin
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '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: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: globalize3
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'
46
+ description: Handles globalize3 translations
47
+ email:
48
+ - stefano.verna@gmail.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - app/assets/stylesheets/active_admin/active_admin_globalize3.css.sass
54
+ - app/assets/javascripts/active_admin/active_admin_globalize3.js.coffee
55
+ - config/locales/en.yml
56
+ - config/locales/it.yml
57
+ - lib/active_admin/globalize.rb
58
+ - lib/active_admin/globalize3/version.rb
59
+ - lib/active_admin/globalize3/engine.rb
60
+ - lib/active_admin/globalize3/form_builder_extension.rb
61
+ - lib/active_admin/globalize3/active_record_extension.rb
62
+ - lib/active_admin/globalize3/index_table_for_extension.rb
63
+ - lib/activeadmin-globalize3.rb
64
+ - MIT-LICENSE
65
+ - Rakefile
66
+ - README.md
67
+ homepage: http://github.com/cantierecreativo/activeadmin-globalize3
68
+ licenses: []
69
+ post_install_message:
70
+ rdoc_options: []
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ! '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubyforge_project:
87
+ rubygems_version: 1.8.23
88
+ signing_key:
89
+ specification_version: 3
90
+ summary: Handles globalize3 translations
91
+ test_files: []