Extract method to open links in a new window

This way we can slightly simplify the code.
This commit is contained in:
Javi Martín
2023-10-15 16:39:01 +02:00
parent e19c16d4e2
commit c2710de5fc
11 changed files with 20 additions and 21 deletions

View File

@@ -2,7 +2,7 @@
<%= back_link_to debates_path, t("debates.index.section_header.title") %>
<%= header do %>
<%= link_to t("debates.new.more_info"), help_path(anchor: "debates"), title: t("shared.target_blank"), target: "_blank" %>
<%= link_to t("debates.new.more_info"), help_path(anchor: "debates") %>
<% end %>
<aside>

View File

@@ -1,6 +1,7 @@
class Debates::NewComponent < ApplicationComponent
include Header
attr_reader :debate
delegate :new_window_link_to, to: :helpers
def initialize(debate)
@debate = debate

View File

@@ -2,7 +2,7 @@
<%= back_link_to proposals_path, t("proposals.index.section_header.title") %>
<%= header do %>
<%= link_to t("proposals.new.more_info"), help_path(anchor: "proposals"), title: t("shared.target_blank"), target: "_blank" %>
<%= new_window_link_to t("proposals.new.more_info"), help_path(anchor: "proposals") %>
<% end %>
<aside>

View File

@@ -1,6 +1,7 @@
class Proposals::NewComponent < ApplicationComponent
include Header
attr_reader :proposal
delegate :new_window_link_to, to: :helpers
def initialize(proposal)
@proposal = proposal

View File

@@ -14,10 +14,8 @@
<%= f.text_field :related_sdg_list,
class: "input",
hint: sanitize(t("sdg.related_list_selector.hint",
link: link_to(t("sdg.related_list_selector.help.text"),
sdg_help_path,
title: t("shared.target_blank"),
target: "_blank")),
link: new_window_link_to(t("sdg.related_list_selector.help.text"),
sdg_help_path)),
attributes: %w[href title target]),
data: { "suggestions-list": sdg_related_suggestions,
"remove-tag-text": t("sdg.related_list_selector.remove_tag") } %>

View File

@@ -1,5 +1,6 @@
class SDG::RelatedListSelectorComponent < ApplicationComponent
attr_reader :f
delegate :new_window_link_to, to: :helpers
def initialize(form)
@f = form

View File

@@ -1,5 +1,6 @@
class Shared::AgreeWithTermsOfServiceFieldComponent < ApplicationComponent
attr_reader :form
delegate :new_window_link_to, to: :helpers
def initialize(form)
@form = form
@@ -9,8 +10,7 @@ class Shared::AgreeWithTermsOfServiceFieldComponent < ApplicationComponent
def label
t("form.accept_terms",
policy: link_to(t("form.policy"), "/privacy", target: "_blank", title: t("shared.target_blank")),
conditions: link_to(t("form.conditions"), "/conditions", target: "_blank",
title: t("shared.target_blank")))
policy: new_window_link_to(t("form.policy"), "/privacy"),
conditions: new_window_link_to(t("form.conditions"), "/conditions"))
end
end

View File

@@ -30,6 +30,10 @@ module ApplicationHelper
end
end
def new_window_link_to(text, path, **options)
link_to text, path, { target: "_blank", title: t("shared.target_blank") }.merge(options)
end
def image_path_for(filename)
image = SiteCustomization::Image.image_for(filename)

View File

@@ -26,10 +26,8 @@
<%= f.check_box :terms_of_service,
label: t("devise_views.users.registrations.new.terms",
terms: link_to(t("devise_views.users.registrations.new.terms_link"),
"/conditions",
title: t("shared.target_blank"),
target: "_blank")) %>
terms: new_window_link_to(t("devise_views.users.registrations.new.terms_link"),
"/conditions")) %>
<div class="small-12 medium-6 small-centered">
<%= f.submit t("devise_views.organizations.registrations.new.submit"), class: "button expanded" %>

View File

@@ -36,10 +36,8 @@
<%= f.check_box :terms_of_service,
label: t("devise_views.users.registrations.new.terms",
terms: link_to(t("devise_views.users.registrations.new.terms_link"),
"/conditions",
title: t("shared.target_blank"),
target: "_blank")) %>
terms: new_window_link_to(t("devise_views.users.registrations.new.terms_link"),
"/conditions")) %>
<div class="small-12 medium-6 small-centered">
<%= f.submit t("devise_views.users.registrations.new.submit"), class: "button expanded" %>

View File

@@ -70,10 +70,8 @@
<div class="small-12">
<%= f.check_box :terms_of_service,
label: t("verification.residence.new.accept_terms_text",
terms_url: link_to(t("verification.residence.new.terms"),
page_path("census_terms"),
title: t("shared.target_blank"),
target: "_blank")) %>
terms_url: new_window_link_to(t("verification.residence.new.terms"),
page_path("census_terms"))) %>
</div>
<div class="small-12 medium-3 clear">