activeadmin-globalize3-unofficial 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,55 @@
1
+ # ActiveAdmin::Globalize3
2
+
3
+ Makes it easy to translate your resource fields.
4
+
5
+ ## Installation
6
+
7
+ ```ruby
8
+ gem "activeadmin-globalize3"
9
+ ```
10
+ ## Your model
11
+
12
+ ```ruby
13
+ active_admin_translates :title, :description do
14
+ validates_presence_of :title
15
+ end
16
+ ```
17
+ ## Editor configuration
18
+
19
+ ```ruby
20
+ index do
21
+ # ...
22
+ translation_status
23
+ # ...
24
+ default_actions
25
+ end
26
+
27
+ form do |f|
28
+ # ...
29
+ f.translated_inputs "Translated fields" do |t|
30
+ t.input :title
31
+ t.input :content
32
+ end
33
+ # ...
34
+ end
35
+ ```
36
+
37
+ ## Friendly ID
38
+
39
+ If you want to use Friendly ID together with Globalize3, this is the way to go:
40
+
41
+ ```ruby
42
+ active_admin_translates :title, :description, :slug do
43
+ extend FriendlyId
44
+ friendly_id :title, use: :slugged
45
+ end
46
+ ```
47
+
48
+ Want to make the slug editable by the user?
49
+
50
+ ```ruby
51
+ active_admin_translates :title, :description, :slug do
52
+ extend FriendlyId
53
+ friendly_id :title, use: [:slugged, :editable]
54
+ end
55
+ ```
@@ -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
+ $("a").live "click", ->
23
+ setTimeout(
24
+ -> translations()
25
+ 50
26
+ )
27
+
28
+ translations()
29
+
@@ -0,0 +1,38 @@
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
+ li.hidden
38
+ 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,8 @@
1
+ module FriendlyId
2
+ module Editable
3
+ def should_generate_new_friendly_id?
4
+ slug_value = send(friendly_id_config.slug_column)
5
+ slug_value.blank?
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,35 @@
1
+ module FriendlyId
2
+ module Globalize3
3
+
4
+ def self.included(model_class)
5
+ model_class.friendly_id_config.instance_eval do
6
+ self.class.send :include, Configuration
7
+ end
8
+ model_class.instance_eval do
9
+ relation_class.send :include, FinderMethods
10
+ end
11
+ end
12
+
13
+ module FinderMethods
14
+ def find_one(id)
15
+ return super if id.unfriendly_id?
16
+ found = includes(:translations).
17
+ where(translation_class.arel_table[:locale].in([I18n.locale, I18n.default_locale])).
18
+ where(translation_class.arel_table[translation_class.friendly_id_config.query_field].eq(id)).first
19
+ if found
20
+ found.tap { |f| f.translations.reload }
21
+ else
22
+ find_one_without_friendly_id(id)
23
+ end
24
+ end
25
+ protected :find_one
26
+ end
27
+
28
+ module Configuration
29
+ def query_field
30
+ model_class.translation_class.friendly_id_config.query_field
31
+ end
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,15 @@
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
+ require 'active_admin/friendly_id/editable'
11
+
12
+ ActiveRecord::Base.send :extend, ActiveAdmin::Globalize3::ActiveRecordExtension
13
+
14
+ ActiveAdmin::FormBuilder.send :include, ActiveAdmin::Globalize3::FormBuilderExtension
15
+ ActiveAdmin::Views::IndexAsTable::IndexTableFor.send :include, ActiveAdmin::Globalize3::IndexTableFor
@@ -0,0 +1,37 @@
1
+ require 'active_admin/friendly_id/globalize3'
2
+
3
+ module ActiveAdmin::Globalize3
4
+ module ActiveRecordExtension
5
+
6
+ module Methods
7
+ def translation_names
8
+ self.translations.map(&:locale).map do |locale|
9
+ I18n.t("active_admin.globalize3.language.#{locale}")
10
+ end.uniq.sort
11
+ end
12
+ end
13
+
14
+ def active_admin_translates(*args, &block)
15
+ translates(*args.dup)
16
+ args.extract_options!
17
+
18
+ if block
19
+ translation_class.instance_eval &block
20
+ end
21
+ translation_class.attr_accessible :locale
22
+ translation_class.attr_accessible *args
23
+
24
+ if translation_class.respond_to? :friendly_id_config
25
+ extend FriendlyId
26
+ friendly_id :anything, use: :globalize3
27
+ end
28
+
29
+ attr_accessible :translations_attributes
30
+ accepts_nested_attributes_for :translations, allow_destroy: true
31
+
32
+ include Methods
33
+ end
34
+
35
+ end
36
+ end
37
+
@@ -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,35 @@
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_or_initialize_by_locale(locale)
17
+ fields = proc do |form|
18
+ form.input(:locale, as: :hidden)
19
+ form.input(:id, as: :hidden)
20
+ block.call(form)
21
+ end
22
+ inputs_for_nested_attributes(
23
+ for: [:translations, translation ],
24
+ class: "inputs locale locale-#{translation.locale}",
25
+ &fields
26
+ )
27
+ end.join.html_safe
28
+ end
29
+ end
30
+
31
+ module ClassMethods
32
+ end
33
+ end
34
+ end
35
+ 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,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: activeadmin-globalize3-unofficial
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: 2012-11-20 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/javascripts/active_admin/active_admin_globalize3.js.coffee
54
+ - app/assets/stylesheets/active_admin/active_admin_globalize3.css.sass
55
+ - config/locales/en.yml
56
+ - config/locales/it.yml
57
+ - lib/active_admin/friendly_id/editable.rb
58
+ - lib/active_admin/friendly_id/globalize3.rb
59
+ - lib/active_admin/globalize.rb
60
+ - lib/active_admin/globalize3/active_record_extension.rb
61
+ - lib/active_admin/globalize3/engine.rb
62
+ - lib/active_admin/globalize3/form_builder_extension.rb
63
+ - lib/active_admin/globalize3/index_table_for_extension.rb
64
+ - lib/active_admin/globalize3/version.rb
65
+ - lib/activeadmin-globalize3.rb
66
+ - MIT-LICENSE
67
+ - Rakefile
68
+ - README.md
69
+ homepage: http://github.com/cantierecreativo/activeadmin-globalize3
70
+ licenses: []
71
+ post_install_message:
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ! '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ! '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ requirements: []
88
+ rubyforge_project:
89
+ rubygems_version: 1.8.23
90
+ signing_key:
91
+ specification_version: 3
92
+ summary: Handles globalize3 translations
93
+ test_files: []
94
+ has_rdoc: