activeadmin-globalize 0.6.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 54a0d5a4b4d8229c79ebc2a651fd3dafc532e839
4
+ data.tar.gz: fb06e589b6c9adb39b8d3b1889005ae213637ff3
5
+ SHA512:
6
+ metadata.gz: 45377c6432d3338feebe6ce60380d7f32d4cded5aa80506737e61644b1609669c50c086aa75e39e983213b00ef8e4df4205f067d7d3d727799a1ed6679664644
7
+ data.tar.gz: c305e8e0b0bc8be3d586a12bdab883da91b4d619d4ed6bdbc42ea4f7c956c10bf7fc8e9399612654b989ee2c2ceefeb22fdd55e7f87dd09dec25a11913094ead
@@ -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,57 @@
1
+ # ActiveAdmin::Globalize
2
+ Makes it easy to translate your resource fields.
3
+
4
+ ## Installation
5
+
6
+ ```ruby
7
+ gem 'activeadmin-globalize', '~> 0.6.3'
8
+ ```
9
+
10
+ This version targets Rails 3.2.x only and ActiveAdmin ~> 0.6.3.
11
+
12
+ ## Your model
13
+
14
+ ```ruby
15
+ active_admin_translates :title, :description do
16
+ validates_presence_of :title
17
+ end
18
+ ```
19
+ ## Editor configuration
20
+
21
+ ```ruby
22
+ index do
23
+ # textual translation status
24
+ translation_status
25
+ # or with flag icons
26
+ translation_status_flags
27
+ # ...
28
+ default_actions
29
+ end
30
+
31
+ form do |f|
32
+ # ...
33
+ f.translated_inputs "Translated fields", switch_locale: false do |t|
34
+ t.input :title
35
+ t.input :content
36
+ end
37
+ # ...
38
+ end
39
+ ```
40
+ If `switch_locale` is set, each tab will be rendered switching locale.
41
+
42
+ ## Friendly ID
43
+
44
+ If you want to use Friendly ID together with Globalize, please take a look
45
+ at the `activeadmin-seo` gem.
46
+
47
+ ## Hints
48
+
49
+ To use the dashed locale keys as 'pt-BR' or 'pt-PT' you need to convert a string
50
+ to symbol (in application.rb)
51
+
52
+ config.i18n.available_locales = [:en, :it, :de, :es, :"pt-BR"]
53
+
54
+ ## Credits
55
+
56
+ This work is based on original idea by [@stefanoverna](https://github.com/stefanoverna/activeadmin-globalize),
57
+ I needed it for AA 0.6.x so I forked the original project.
@@ -0,0 +1,154 @@
1
+ $ ->
2
+
3
+ translations = ->
4
+
5
+ # Hides or shows the + button and the remove button.
6
+ updateLocaleButtonsStatus = ($dom) ->
7
+ $localeList = $dom.find('.add-locale ul li:not(.hidden)')
8
+ if $localeList.length == 0
9
+ $dom.find('.add-locale').hide()
10
+ else
11
+ $dom.find('.add-locale').show()
12
+
13
+
14
+ # Hides or shows the locale tab and its corresponding element in the add menu.
15
+ toggleTab = ($tab, active) ->
16
+ $addButton = $tab.parents('ul').find('.add-locale li:has(a[href="' + $tab.attr('href') + '"])')
17
+ if active
18
+ $tab.addClass('hidden').show().removeClass('hidden')
19
+ $addButton.hide().addClass('hidden')
20
+ else
21
+ $tab.addClass('hidden').hide().addClass('hidden')
22
+ $addButton.show().removeClass('hidden')
23
+
24
+ $(".activeadmin-translations > ul").each ->
25
+ $dom = $(this)
26
+ # true when tabs are used in show action, false in form
27
+ showAction = $dom.hasClass('locale-selector')
28
+
29
+ if !$dom.data("ready")
30
+ $dom.data("ready", true)
31
+ $tabs = $("li > a", this)
32
+ # content to toggle is different according to current action
33
+ $contents = if showAction then $(this).siblings("div.field-translation") else $(this).siblings("fieldset")
34
+
35
+ $tabs.click (e) ->
36
+ $tab = $(this)
37
+ $tabs.not($tab).removeClass("active")
38
+ $tab.addClass("active")
39
+ $contents.hide()
40
+ $contents.filter($tab.attr("href")).show()
41
+ e.preventDefault()
42
+
43
+ $tabs.eq(0).click()
44
+
45
+ # Add button and other behavior is not needed in show action
46
+ return if showAction
47
+
48
+ # Collect tha available locales.
49
+ availableLocales = []
50
+ $tabs.not('.default').each ->
51
+ availableLocales.push($('<li></li>').append($(this).clone().removeClass('active')))
52
+
53
+ # Create a new tab as the root of the drop down menu.
54
+ $addLocaleButton = $('<li class="add-locale"><a href="#">+</a></li>')
55
+ $addLocaleButton.append($('<ul></ul>').append(availableLocales))
56
+
57
+ # Handle locale addition
58
+ $addLocaleButton.find('ul a').click (e) ->
59
+ href = $(this).attr('href')
60
+ $tab = $tabs.filter('[href="' + href + '"]')
61
+ toggleTab($tab, true)
62
+ $tab.click()
63
+ updateLocaleButtonsStatus($dom)
64
+ e.preventDefault()
65
+
66
+ # Remove a locale from the tab.
67
+ $removeButton = $('<span class="remove">x</span>').click (e) ->
68
+ e.stopImmediatePropagation()
69
+ e.preventDefault()
70
+ $tab = $(this).parent()
71
+ toggleTab($tab, false)
72
+ if $tab.hasClass('active')
73
+ $tabs.not('.hidden').eq(0).click()
74
+
75
+ updateLocaleButtonsStatus($dom)
76
+
77
+ # Add the remove button to every tab.
78
+ $tabs.not('.default').append($removeButton)
79
+
80
+ # Add the new button at the end of the locale list.
81
+ $dom.append($addLocaleButton)
82
+
83
+ $tabs.each ->
84
+ $tab = $(@)
85
+ $content = $contents.filter($tab.attr("href"))
86
+ containsErrors = $content.find(".input.error").length > 0
87
+ $tab.toggleClass("error", containsErrors)
88
+ # Find those tabs that are in use.
89
+ hide = true
90
+ # We will not hide the tabs that have any error.
91
+ if $tab.hasClass('error') || $tab.hasClass('default')
92
+ hide = false
93
+ else
94
+ # Check whether the input fields are empty or not.
95
+ $content.find('[name]').not('[type="hidden"]').each ->
96
+ if $(this).val()
97
+ # We will not hide the tab because it has some data.
98
+ hide = false
99
+ return false
100
+
101
+ if hide
102
+ toggleTab($tab, false)
103
+ else
104
+ toggleTab($tab, true)
105
+
106
+ # Remove the fields of hidden locales before form submission.
107
+ $form = $dom.parents('form')
108
+ if !$form.data('ready')
109
+ $form.data('ready')
110
+ $form.submit ->
111
+ # Get all translations (the nested ones too).
112
+ $('.activeadmin-translations > ul').each ->
113
+ # Get the corresponding fieldsets.
114
+ $fieldsets = $(this).siblings('fieldset')
115
+ $("li:not(.add-locale) > a", this).each ->
116
+ # Remove them if the locale is hidden.
117
+ if $(this).hasClass('hidden')
118
+ # check if it's an existing translation otherwise remove it
119
+ $currentFieldset = $("fieldset#{$(this).attr('href')}")
120
+ $translationId = $('input[id$=_id]', $currentFieldset)
121
+ if $translationId.val()
122
+ # mark it for database removal appending a _destroy element
123
+ $destroy = $('<input/>').attr(
124
+ type: 'hidden',
125
+ name: $translationId.attr('name').replace('[id]', '[_destroy]'),
126
+ id: $translationId.attr('id').replace('_id', '_destroy'),
127
+ value: '1'
128
+ )
129
+ $destroy.appendTo($currentFieldset)
130
+ else
131
+ # remove the fieldset from dom so it won't be submitted
132
+ $fieldsets.filter($(this).attr('href')).remove()
133
+
134
+ #Initially update the buttons' status
135
+ updateLocaleButtonsStatus($dom)
136
+ $tabs.filter('.default').click()
137
+
138
+ # this is to handle elements created with has_many
139
+ $("a").bind "click", ->
140
+ setTimeout(
141
+ -> translations()
142
+ 50
143
+ )
144
+
145
+ # Used to toggle translations values for inline fields
146
+ $('a.ui-translation-trigger').click (e) ->
147
+ $locale = $(this).data('locale')
148
+ $td = $(this).closest('td')
149
+ $('.field-translation', $td).hide()
150
+ $(".locale-#{$locale}", $td).show()
151
+ e.preventDefault()
152
+
153
+ translations()
154
+
@@ -0,0 +1,114 @@
1
+ @import "active_admin/mixins"
2
+
3
+ @import "active_admin_globalize_flags"
4
+
5
+ .active_admin
6
+ .activeadmin-translations
7
+ margin-bottom: 20px
8
+
9
+ &> ul
10
+ position: relative
11
+ top: 4px
12
+ padding: 0 10px
13
+
14
+ &> li
15
+ display: inline-block
16
+
17
+ &> a
18
+ display: inline-block
19
+ color: #666
20
+ margin-right: 3px
21
+ text-decoration: none
22
+ font-size: 17px
23
+ padding: 8px 15px
24
+ padding-bottom: 8px + 4px
25
+ margin-bottom: 0
26
+ position: relative
27
+
28
+ &.error
29
+ color: #932419
30
+
31
+ &.active
32
+ background: #f4f4f4
33
+ +inset-shadow(0, 4px, 4px, #ddd)
34
+ +border-top-radius(4px)
35
+ margin-bottom: 0
36
+ +gradient($secondary-gradient-stop, #f4f4f4)
37
+ text-shadow: 0 1px 0 white
38
+ color: #666 !important
39
+
40
+ &> span
41
+ font-size: 0.75em
42
+ font-weight: bold
43
+ position: absolute
44
+ top: 2px
45
+ right: 4px
46
+ display: none
47
+
48
+ &:hover
49
+ +text-shadow(red, 1px, 1px, 2px)
50
+
51
+ &:hover
52
+ span
53
+ display: block
54
+
55
+ span.hidden
56
+ display: none
57
+
58
+ &> li.add-locale
59
+ font-weight: bold
60
+ position: relative
61
+ z-index: 100
62
+
63
+ &> ul
64
+ display: none
65
+ font-size: 17px
66
+ font-weight: normal
67
+ padding: 0
68
+ +border-bottom-radius(4px)
69
+ position: absolute
70
+ +shadow(3px, 3px, 5px, #aaa)
71
+ background: #f4f4f4
72
+ z-index: 100
73
+
74
+ &> li
75
+ font-size: 17px
76
+ padding: 8px 15px
77
+ padding-bottom: 8px + 4px
78
+ margin-bottom: 0
79
+
80
+ &:hover
81
+ background: #ddd
82
+ background: -webkit-linear-gradient(left, $secondary-gradient-stop, #f4f4f4)
83
+ background: -moz-linear-gradient(left, $secondary-gradient-stop, #f4f4f4)
84
+ background: linear-gradient(left, $secondary-gradient-stop, #f4f4f4)
85
+
86
+ &> a
87
+ text-decoration: none
88
+ color: #666
89
+
90
+ &> li:first-child
91
+ border-top-right-radius: 4px
92
+
93
+ &:hover
94
+ background: #f4f4f4
95
+ +inset-shadow(0, 4px, 4px, #ddd)
96
+ +border-top-radius(4px)
97
+ margin-bottom: 0
98
+ +gradient($secondary-gradient-stop, #f4f4f4)
99
+ text-shadow: 0 1px 0 white
100
+ color: #666 !important
101
+
102
+ &> ul
103
+ display: block
104
+
105
+
106
+ &> fieldset.inputs
107
+ margin-bottom: 0
108
+
109
+ ol
110
+ padding-left: 0
111
+ width: 100%
112
+
113
+ li.hidden
114
+ padding: 0 !important
@@ -0,0 +1,56 @@
1
+ // This file (and the sprite image) is kindly generated by http://flag-sprites.com/
2
+ // and converted to SASS using this converter http://css2sass.heroku.com/
3
+
4
+ // Override flag positions in your stylesheet if you want to change default flags
5
+ .flag
6
+ width: 16px
7
+ height: 11px
8
+ vertical-align: middle
9
+ background: url(active_admin_image_path('flags.png')) no-repeat
10
+ &.flag-ar // originally flag-ae
11
+ background-position: -16px 0
12
+ &.flag-br
13
+ background-position: -32px 0
14
+ &.flag-pt-BR
15
+ background-position: -32px 0
16
+ &.flag-de
17
+ background-position: -48px 0
18
+ &.flag-es
19
+ background-position: 0 -11px
20
+ &.flag-fr
21
+ background-position: -16px -11px
22
+ &.flag-gb
23
+ background-position: -32px -11px
24
+ &.flag-hu
25
+ background-position: -48px -11px
26
+ &.flag-it
27
+ background-position: 0 -22px
28
+ &.flag-pt
29
+ background-position: -16px -22px
30
+ &.flag-pt-PT
31
+ background-position: -16px -22px
32
+ &.flag-tr
33
+ background-position: -32px -22px
34
+ &.flag-en // originally flag-us
35
+ background-position: -48px -22px
36
+
37
+ // Used to distantiate inline locale selector
38
+ span.inline-locale-selector
39
+ margin-right: 10px
40
+
41
+ .field-translation.hidden
42
+ display: none
43
+
44
+ ul.locale-selector
45
+ margin-bottom: 0 !important
46
+
47
+ div.field-translation
48
+ padding: 10px 10px
49
+ +inset-shadow(0, -40px, 40px, #ddd)
50
+ +border-top-radius(4px)
51
+ +border-bottom-radius(6px)
52
+ min-height: 80px
53
+
54
+ // prevent tr height flickering
55
+ span.field-translation.empty
56
+ vertical-align: bottom
@@ -0,0 +1,15 @@
1
+ de:
2
+ active_admin:
3
+ globalize:
4
+ translations: "Übersetzungen"
5
+ language:
6
+ de: "Deutsch"
7
+ en: "Englisch"
8
+ es: "Spanisch"
9
+ fr: "Fränzösisch"
10
+ hu: "Ungarisch"
11
+ it: "Italienisch"
12
+ pt-BR: "Portugiesisch"
13
+ pt-PT: "Portugiesisch (Portugal)"
14
+ tr: "Türkisch"
15
+
@@ -0,0 +1,15 @@
1
+ en:
2
+ active_admin:
3
+ globalize:
4
+ translations: "Translations"
5
+ language:
6
+ de: "German"
7
+ en: "English"
8
+ es: "Spanish"
9
+ fr: "French"
10
+ hu: "Hungarian"
11
+ it: "Italian"
12
+ pt-BR: "Portuguese"
13
+ pt-PT: "Portuguese (Portugal)"
14
+ tr: "Turkish"
15
+
@@ -0,0 +1,15 @@
1
+ hu:
2
+ active_admin:
3
+ globalize:
4
+ translations: "Fordítások"
5
+ language:
6
+ de: "Német"
7
+ en: "Angol"
8
+ es: "Spanyol"
9
+ fr: "Francia"
10
+ hu: "Magyar"
11
+ it: "Olasz"
12
+ pt-BR: "Portuguese"
13
+ pt-PT: "Portuguese (Portugal)"
14
+ tr: "Török"
15
+
@@ -0,0 +1,15 @@
1
+ it:
2
+ active_admin:
3
+ globalize:
4
+ translations: "Traduzioni"
5
+ language:
6
+ de: "Tedesco"
7
+ en: "Inglese"
8
+ es: "Spagnolo"
9
+ fr: "Francese"
10
+ hu: "Ungherese"
11
+ it: "Italiano"
12
+ pt-BR: "Portoghese"
13
+ pt-PT: "Portoghese (Portogallo)"
14
+ tr: "Turco"
15
+
@@ -0,0 +1,15 @@
1
+ pt-BR:
2
+ active_admin:
3
+ globalize:
4
+ translations: "Traduções"
5
+ language:
6
+ de: "Alemão"
7
+ en: "Inglês"
8
+ es: "Espanhol"
9
+ fr: "Francês"
10
+ hu: "Húngaro"
11
+ it: "Italiano"
12
+ pt-BR: "Português"
13
+ pt-PT: "Português (Portugal)"
14
+ tr: "Turco"
15
+
@@ -0,0 +1,15 @@
1
+ pt-PT:
2
+ active_admin:
3
+ globalize:
4
+ translations: "Traduções"
5
+ language:
6
+ de: "Alemão"
7
+ en: "Inglês"
8
+ es: "Espanhol"
9
+ fr: "Francês"
10
+ hu: "Húngaro"
11
+ it: "Italiano"
12
+ pt-BR: "Português"
13
+ pt-PT: "Português (Portugal)"
14
+ tr: "Turco"
15
+
@@ -0,0 +1,2 @@
1
+ # Tell spring where the app is
2
+ Spring.application_root = './spec/dummy'
@@ -0,0 +1,16 @@
1
+ require 'globalize'
2
+ require 'activeadmin'
3
+
4
+ require 'active_admin/views/index_as_table'
5
+ require 'active_admin/globalize/engine'
6
+ require 'active_admin/globalize/form_builder_extension'
7
+ require 'active_admin/globalize/active_record_extension'
8
+ require 'active_admin/globalize/index_table_for_extension'
9
+ require 'active_admin/globalize/attributes_table_extension'
10
+ require 'active_admin/view_helpers/flag_helper'
11
+
12
+ ActiveRecord::Base.send :extend, ActiveAdmin::Globalize::ActiveRecordExtension
13
+
14
+ ActiveAdmin::FormBuilder.send :include, ActiveAdmin::Globalize::FormBuilderExtension
15
+ ActiveAdmin::Views::IndexAsTable::IndexTableFor.send :include, ActiveAdmin::Globalize::IndexTableFor
16
+
@@ -0,0 +1,27 @@
1
+ module ActiveAdmin::Globalize
2
+ module ActiveRecordExtension
3
+
4
+ module Methods
5
+ def translation_names
6
+ self.translations.map(&:locale).map do |locale|
7
+ I18n.t("active_admin.globalize.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
+
20
+ accepts_nested_attributes_for :translations, allow_destroy: true
21
+
22
+ include Methods
23
+ end
24
+
25
+ end
26
+ end
27
+
@@ -0,0 +1,139 @@
1
+ require 'active_admin/views/components/attributes_table.rb'
2
+
3
+ module ActiveAdmin
4
+ module Views
5
+
6
+ # Provide additional method #translated_row to attribute table
7
+ class AttributesTable < ActiveAdmin::Component
8
+
9
+ # Show a row with their translations and selectors for choosing locale to show.
10
+ #
11
+ # If a block is given it will be used to format the translation,
12
+ # otherwise field taken from translation object is used as translation.
13
+ #
14
+ # Additional options are forwarded to the original row call.
15
+ #
16
+ # @overload translated_row(field, opts)
17
+ # @param [String] field row label, also used as field name if none given in options
18
+ # @param [Hash] opts the options to create a message with.
19
+ # @option opts [String] :field field to retrieve from model if different from first argument of args
20
+ # @option opts [String] :locale (I18n.locale) initial locale to show in the ui
21
+ # @option opts [Boolean] :inline (true) if true locale selectors (and values) are shown inline,
22
+ # otherwise as block content and tabs
23
+ #
24
+ # @yield if given will be used to build single translations
25
+ # @yieldparam [*::Translation] Globalize translation model
26
+ # @yieldreturn [String] content to show as translation
27
+ #
28
+ # @example Show inlined translation values for title field
29
+ # show do |p|
30
+ # attributes_table do
31
+ # translated_row(:title)
32
+ # end
33
+ # end
34
+ #
35
+ # @example Show block translation for body field with selection of initial locale
36
+ # show do |p|
37
+ # attributes_table do
38
+ # translated_row(:body, inline: false, locale: :es)
39
+ # end
40
+ # end
41
+ #
42
+ def translated_row(*args, &block)
43
+ options = args.extract_options!
44
+ options.reverse_merge!(inline: true, locale: I18n.locale)
45
+ field = options[:field] || args.first
46
+ raise ArgumentError, "Field '#{field}' is not translatable" unless translatable?(field)
47
+ # Remove my options from passed options
48
+ row_options = options.symbolize_keys.except(:field, :locale, :inline)
49
+ # Append remaining options to original args
50
+ args.push(row_options) unless row_options.empty?
51
+ # Render the table row with translations
52
+ row(*args) do
53
+ if options[:inline]
54
+ ''.html_safe.tap do |value|
55
+ # Add selectors for inline locale
56
+ value << inline_locale_selectors
57
+ # Build translations spans
58
+ value << field_translations(field, :span, options[:locale], &block)
59
+ end
60
+ else
61
+ content_tag(:div, class: 'activeadmin-translations') do
62
+ ''.html_safe.tap do |value|
63
+ # Render selectors as in translation ui
64
+ value << block_locale_selectors
65
+ # Build translations divs for actual translations
66
+ value << field_translations(field, :div, options[:locale], &block)
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
72
+
73
+ private
74
+
75
+ # @return [Boolean] true iff the field is translatable
76
+ def translatable?(field)
77
+ @record.class.translates? &&
78
+ @record.class.translated_attribute_names.include?(field.to_sym)
79
+ end
80
+
81
+ # Build a tag for each field translation with appropriate css classes to make javascript working
82
+ # @param [String] field field name to render
83
+ # @param [Symbol] tag tag to enclose field translation
84
+ # @param [Symbol] initial_locale locale to set as not hidden
85
+ def field_translations(field, tag, initial_locale)
86
+ available_translations.map do |translation|
87
+ # Classes for translation span only first element is visible
88
+ css_classes = ['field-translation', "locale-#{translation.locale}"]
89
+ # Initially only element for selected locale is visible
90
+ css_classes.push 'hidden' unless translation.locale == initial_locale.to_sym
91
+ # Build content for cell or div using translation locale and given block
92
+ content = I18n.with_locale(translation.locale) do
93
+ block_given? ? yield(translation) : translation.send(field)
94
+ end
95
+ # return element
96
+ if tag == :span # inline element
97
+ # attach class to span if inline
98
+ css_classes.push(:empty) if content.blank?
99
+ content_tag(tag, content.presence || 'Empty', class: css_classes)
100
+ else
101
+ # block content
102
+ content_tag(tag, class: css_classes) do
103
+ # Return content or empty span
104
+ content.presence || content_tag(:span, 'Empty', class: 'empty')
105
+ end
106
+ end
107
+ end.join(' ').html_safe
108
+ end
109
+
110
+ def block_locale_selectors
111
+ content_tag(:ul, class: 'available-locales locale-selector') do
112
+ available_translations.map(&:locale).map do |locale|
113
+ default = 'default' if locale == I18n.default_locale
114
+ content_tag(:li, class: 'translation-tab') do
115
+ I18n.with_locale(locale) do
116
+ content_tag(:a, I18n.t(:"active_admin.globalize.language.#{locale}"), href: ".locale-#{locale}", class: default)
117
+ end
118
+ end
119
+ end.join.html_safe
120
+ end
121
+ end
122
+
123
+ # Return flag elements to show the given locale using javascript
124
+ def inline_locale_selectors
125
+ content_tag(:span, class: 'inline-locale-selector') do
126
+ available_translations.map do |translation|
127
+ # Build a link to show the given translation
128
+ link_to(flag_icon(translation.locale), '#', class: 'ui-translation-trigger', data: {locale: translation.locale})
129
+ end.join(' ').html_safe
130
+ end
131
+ end
132
+
133
+ def available_translations
134
+ @record_translations ||= @record.translations.order(:locale)
135
+ end
136
+
137
+ end
138
+ end
139
+ end
@@ -0,0 +1,19 @@
1
+ module ActiveAdmin
2
+ module Globalize
3
+ class Engine < ::Rails::Engine
4
+ initializer "Active Admin precompile hook", group: :all do |app|
5
+ app.config.assets.precompile += [
6
+ "active_admin/active_admin_globalize.css",
7
+ "active_admin/active_admin_globalize.js"
8
+ ]
9
+ end
10
+
11
+ initializer "add assets" do
12
+ ActiveAdmin.application.register_stylesheet "active_admin/active_admin_globalize.css", :media => :screen
13
+ ActiveAdmin.application.register_javascript "active_admin/active_admin_globalize.js"
14
+ end
15
+
16
+ end
17
+ end
18
+ end
19
+
@@ -0,0 +1,45 @@
1
+ module ActiveAdmin
2
+ module Globalize
3
+ module FormBuilderExtension
4
+ extend ActiveSupport::Concern
5
+
6
+ def translated_inputs(name = "Translations", options = {}, &block)
7
+ options.symbolize_keys!
8
+ switch_locale = options.fetch(:switch_locale, false)
9
+ auto_sort = options.fetch(:auto_sort, true)
10
+ form_buffers.last << template.content_tag(:div, class: "activeadmin-translations") do
11
+ template.content_tag(:ul, class: "available-locales") do
12
+ (auto_sort ? I18n.available_locales.sort : I18n.available_locales).map do |locale|
13
+ default = 'default' if locale == I18n.default_locale
14
+ template.content_tag(:li) do
15
+ I18n.with_locale(switch_locale ? locale : I18n.locale) do
16
+ template.content_tag(:a, I18n.t(:"active_admin.globalize.language.#{locale}"), href:".locale-#{locale}", :class => default)
17
+ end
18
+ end
19
+ end.join.html_safe
20
+ end <<
21
+ (auto_sort ? I18n.available_locales.sort : I18n.available_locales).map do |locale|
22
+ translation = object.translations.find { |t| t.locale.to_s == locale.to_s }
23
+ translation ||= object.translations.build(locale: locale)
24
+ fields = proc do |form|
25
+ form.input(:locale, as: :hidden)
26
+ form.input(:id, as: :hidden)
27
+ I18n.with_locale(switch_locale ? locale : I18n.locale) do
28
+ block.call(form)
29
+ end
30
+ end
31
+ inputs_for_nested_attributes(
32
+ for: [:translations, translation ],
33
+ class: "inputs locale locale-#{translation.locale}",
34
+ &fields
35
+ )
36
+ end.join.html_safe
37
+ end
38
+ end
39
+
40
+ module ClassMethods
41
+ end
42
+ end
43
+ end
44
+ end
45
+
@@ -0,0 +1,20 @@
1
+ require 'active_admin/views/components/status_tag'
2
+
3
+ module ActiveAdmin
4
+ module Globalize
5
+ module IndexTableFor
6
+ def translation_status
7
+ column I18n.t("active_admin.globalize.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
+ def translation_status_flags
14
+ column I18n.t("active_admin.globalize.translations") do |obj|
15
+ obj.translations.map(&:locale).sort.map { |l| flag_icon(l) }.join(' ').html_safe
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,6 @@
1
+ module ActiveAdmin
2
+ module Globalize
3
+ VERSION = '0.6.3'
4
+ end
5
+ end
6
+
@@ -0,0 +1,17 @@
1
+ require 'active_admin/view_helpers'
2
+
3
+ module ActiveAdmin
4
+ module ViewHelpers
5
+ module FlagHelper
6
+
7
+ # Return an image tag with background of given locale
8
+ def flag_icon(locale)
9
+ image_tag('active_admin/transparent.gif', class: "flag flag-#{locale}")
10
+ end
11
+
12
+ end
13
+
14
+ # Register as ActiveAdmin view helper
15
+ include FlagHelper
16
+ end
17
+ end
@@ -0,0 +1 @@
1
+ require 'active_admin/globalize'
metadata ADDED
@@ -0,0 +1,124 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: activeadmin-globalize
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.6.3
5
+ platform: ruby
6
+ authors:
7
+ - Stefano Verna
8
+ - Fabio Napoleoni
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-09-23 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activeadmin
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ~>
19
+ - !ruby/object:Gem::Version
20
+ version: 0.6.3
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ version: 0.6.3
28
+ - !ruby/object:Gem::Dependency
29
+ name: globalize
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ~>
33
+ - !ruby/object:Gem::Version
34
+ version: 3.0.4
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.4
42
+ - !ruby/object:Gem::Dependency
43
+ name: bundler
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - '>='
47
+ - !ruby/object:Gem::Version
48
+ version: 1.6.1
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - '>='
54
+ - !ruby/object:Gem::Version
55
+ version: 1.6.1
56
+ - !ruby/object:Gem::Dependency
57
+ name: rake
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ description: Handles globalize translations in ActiveAdmin 0.6.3 and Rails 3.2.x
71
+ email:
72
+ - stefano.verna@gmail.com
73
+ - f.napoleoni@gmail.com
74
+ executables: []
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - MIT-LICENSE
79
+ - README.md
80
+ - app/assets/images/active_admin/flags.png
81
+ - app/assets/images/active_admin/transparent.gif
82
+ - app/assets/javascripts/active_admin/active_admin_globalize.js.coffee
83
+ - app/assets/stylesheets/active_admin/active_admin_globalize.css.sass
84
+ - app/assets/stylesheets/active_admin/active_admin_globalize_flags.css.sass
85
+ - config/locales/de.yml
86
+ - config/locales/en.yml
87
+ - config/locales/hu.yml
88
+ - config/locales/it.yml
89
+ - config/locales/pt-BR.yml
90
+ - config/locales/pt-PT.yml
91
+ - config/spring.rb
92
+ - lib/active_admin/globalize.rb
93
+ - lib/active_admin/globalize/active_record_extension.rb
94
+ - lib/active_admin/globalize/attributes_table_extension.rb
95
+ - lib/active_admin/globalize/engine.rb
96
+ - lib/active_admin/globalize/form_builder_extension.rb
97
+ - lib/active_admin/globalize/index_table_for_extension.rb
98
+ - lib/active_admin/globalize/version.rb
99
+ - lib/active_admin/view_helpers/flag_helper.rb
100
+ - lib/activeadmin-globalize.rb
101
+ homepage: http://github.com/fabn/activeadmin-globalize
102
+ licenses: []
103
+ metadata: {}
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - '>='
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ requirements: []
119
+ rubyforge_project:
120
+ rubygems_version: 2.2.2
121
+ signing_key:
122
+ specification_version: 4
123
+ summary: Handles globalize translations
124
+ test_files: []