Move information texts form partial to a component

This way it'll be easierto write tests for it when we change it.
This commit is contained in:
Javi Martín
2024-05-23 20:21:56 +02:00
parent 2a5edbb5dd
commit 26b48e527a
5 changed files with 16 additions and 8 deletions

View File

@@ -0,0 +1,16 @@
<%= render Shared::GlobalizeLocalesComponent.new %>
<%= form_tag admin_site_customization_information_texts_path do %>
<% I18n.available_locales.each do |l| %>
<%= translation_enabled_tag l, site_customization_enable_translation?(l) %>
<% end %>
<% contents.each do |group| %>
<% group.each do |content| %>
<b><%= content.key %></b>
<% content.globalize_locales.each do |locale| %>
<%= render Admin::SiteCustomization::InformationTexts::FormFieldComponent.new(content, locale: locale) %>
<% end %>
<% end %>
<% end %>
<%= submit_tag t("admin.menu.site_customization.buttons.save"), class: "button" %>
<% end %>

View File

@@ -0,0 +1,14 @@
class Admin::SiteCustomization::InformationTexts::FormComponent < ApplicationComponent
attr_reader :contents
use_helpers :site_customization_enable_translation?
def initialize(contents)
@contents = contents
end
private
def translation_enabled_tag(locale, enabled)
hidden_field_tag("enabled_translations[#{locale}]", (enabled ? 1 : 0))
end
end