Extract merge_translatable_field_options helper method

This commit is contained in:
Marko Lovic
2018-08-16 14:41:35 +02:00
committed by Javi Martín
parent 61e3b3b406
commit 7b0aa1e104
2 changed files with 15 additions and 16 deletions

View File

@@ -11,6 +11,19 @@ module TranslatableFormHelper
yield(f)
end
end
def merge_translatable_field_options(options, locale)
options.merge(
class: (options.fetch(:class, "") + " js-globalize-attribute"),
style: display_translation?(locale),
data: options.fetch(:data, {}).merge(locale: locale),
label_options: {
class: (options.fetch(:class, "") + " js-globalize-attribute"),
style: display_translation?(locale),
data: (options.dig(:label_options, :data) || {}) .merge(locale: locale)
}
)
end
end
class TranslatableFormBuilder < FoundationRailsHelper::FormBuilder
@@ -28,17 +41,7 @@ class TranslatableFormBuilder < FoundationRailsHelper::FormBuilder
@template.capture do
@object.globalize_locales.each do |locale|
Globalize.with_locale(locale) do
final_options = options.merge(
class: (options.fetch(:class, "") + " js-globalize-attribute"),
style: @template.display_translation?(locale),
data: options.fetch(:data, {}).merge(locale: locale),
label_options: {
class: (options.fetch(:class, "") + " js-globalize-attribute"),
style: @template.display_translation?(locale),
data: (options.dig(:label_options, :data) || {}) .merge(locale: locale)
}
)
final_options = @template.merge_translatable_field_options(options, locale)
@template.concat send(field_type, "#{method}_#{locale}", final_options)
end
end

View File

@@ -11,9 +11,5 @@
<%= text_area_tag "contents[content_#{content.key}]values[value_#{locale}]",
i18n_content_translation ||
t(content.key, locale: locale),
{ rows: 5,
class: "js-globalize-attribute",
style: display_translation?(locale),
data: { locale: locale }
} %>
merge_translatable_field_options({rows: 5}, locale) %>
<% end %>