From 08318171f00e2265ddf2d8e8b1c0ad4df752d8cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Tue, 18 May 2021 15:42:40 +0200 Subject: [PATCH] Extract component to render help section --- .../pages/help/section_component.html.erb | 16 ++++++++ .../pages/help/section_component.rb | 8 ++++ app/views/pages/help/_budgets.html.erb | 22 +++-------- app/views/pages/help/_debates.html.erb | 39 +++++++------------ app/views/pages/help/_polls.html.erb | 29 +++++++------- app/views/pages/help/_processes.html.erb | 32 +++++++-------- app/views/pages/help/_proposals.html.erb | 22 +++-------- 7 files changed, 76 insertions(+), 92 deletions(-) create mode 100644 app/components/pages/help/section_component.html.erb create mode 100644 app/components/pages/help/section_component.rb diff --git a/app/components/pages/help/section_component.html.erb b/app/components/pages/help/section_component.html.erb new file mode 100644 index 000000000..a577d8026 --- /dev/null +++ b/app/components/pages/help/section_component.html.erb @@ -0,0 +1,16 @@ +
+
+

+ <%= t("pages.help.#{section}.title") %> +

+ + <%= content %> + + <% if image_path %> +
+ <%= image_tag image_path, alt: t("pages.help.#{section}.image_alt") %> +
<%= t("pages.help.#{section}.figcaption") %>
+
+ <% end %> +
+
diff --git a/app/components/pages/help/section_component.rb b/app/components/pages/help/section_component.rb new file mode 100644 index 000000000..3d15072c0 --- /dev/null +++ b/app/components/pages/help/section_component.rb @@ -0,0 +1,8 @@ +class Pages::Help::SectionComponent < ApplicationComponent + attr_reader :section, :image_path + + def initialize(section, image_path = nil) + @section = section + @image_path = image_path + end +end diff --git a/app/views/pages/help/_budgets.html.erb b/app/views/pages/help/_budgets.html.erb index 2504d60d3..00f086054 100644 --- a/app/views/pages/help/_budgets.html.erb +++ b/app/views/pages/help/_budgets.html.erb @@ -1,16 +1,6 @@ -
-
-

- <%= t("pages.help.budgets.title") %> -

-

- <%= sanitize(t("pages.help.budgets.description", - link: link_to(t("pages.help.budgets.link"), budgets_path))) %> -

- -
- <%= image_tag "help/budgets_#{I18n.locale}.png", alt: t("pages.help.budgets.image_alt") %> -
<%= t("pages.help.budgets.figcaption") %>
-
-
-
+<%= render Pages::Help::SectionComponent.new("budgets", "help/budgets_#{I18n.locale}.png") do %> +

+ <%= sanitize(t("pages.help.budgets.description", + link: link_to(t("pages.help.budgets.link"), budgets_path))) %> +

+<% end %> diff --git a/app/views/pages/help/_debates.html.erb b/app/views/pages/help/_debates.html.erb index c90a58038..ebc3800d0 100644 --- a/app/views/pages/help/_debates.html.erb +++ b/app/views/pages/help/_debates.html.erb @@ -1,25 +1,14 @@ -
-
-

- <%= t("pages.help.debates.title") %> -

-

- <%= sanitize(t("pages.help.debates.description", - org: setting["org_name"], - link: link_to(t("pages.help.debates.link"), - debates_path))) %> -

-
    -
  • - <%= sanitize(t("pages.help.debates.feature", - link: link_to(t("pages.help.debates.feature_link", org: setting["org_name"]), - new_user_registration_path))) %> -
  • -
- -
- <%= image_tag "help/debates.png", alt: t("pages.help.debates.image_alt") %> -
<%= t("pages.help.debates.figcaption") %>
-
-
-
+<%= render Pages::Help::SectionComponent.new("debates", "help/debates.png") do %> +

+ <%= sanitize(t("pages.help.debates.description", + org: setting["org_name"], + link: link_to(t("pages.help.debates.link"), debates_path))) %> +

+ +<% end %> diff --git a/app/views/pages/help/_polls.html.erb b/app/views/pages/help/_polls.html.erb index 7ce3a13cb..c7d1dd40c 100644 --- a/app/views/pages/help/_polls.html.erb +++ b/app/views/pages/help/_polls.html.erb @@ -1,16 +1,13 @@ -
-
-

<%= t("pages.help.polls.title") %>

-

- <%= sanitize(t("pages.help.polls.description", - link: link_to(t("pages.help.polls.link"), polls_path))) %> -

-
    -
  • - <%= sanitize(t("pages.help.polls.feature_1", - link: link_to(t("pages.help.polls.feature_1_link", org_name: setting["org_name"]), - new_user_registration_path))) %> -
  • -
-
-
+<%= render Pages::Help::SectionComponent.new("polls") do %> +

+ <%= sanitize(t("pages.help.polls.description", + link: link_to(t("pages.help.polls.link"), polls_path))) %> +

+ +<% end %> diff --git a/app/views/pages/help/_processes.html.erb b/app/views/pages/help/_processes.html.erb index f53e4e20e..388048a79 100644 --- a/app/views/pages/help/_processes.html.erb +++ b/app/views/pages/help/_processes.html.erb @@ -1,19 +1,13 @@ -
-
-

- <%= t("pages.help.processes.title") %> -

- -

- <% link = link_to(t("pages.help.processes.link"), legislation_processes_path) %> - <%= sanitize(t("pages.help.processes.description", link: link)) %> -

-
    -
  • - <%= sanitize(t("pages.help.processes.feature", - link: link_to(t("pages.help.processes.feature_link", org_name: setting["org_name"]), - new_user_registration_path))) %> -
  • -
-
-
+<%= render Pages::Help::SectionComponent.new("processes", nil) do %> +

+ <% link = link_to(t("pages.help.processes.link"), legislation_processes_path) %> + <%= sanitize(t("pages.help.processes.description", link: link)) %> +

+ +<% end %> diff --git a/app/views/pages/help/_proposals.html.erb b/app/views/pages/help/_proposals.html.erb index acfd8ef60..fd9cf18bc 100644 --- a/app/views/pages/help/_proposals.html.erb +++ b/app/views/pages/help/_proposals.html.erb @@ -1,16 +1,6 @@ -
-
-

- <%= t("pages.help.proposals.title") %> -

-

- <%= sanitize(t("pages.help.proposals.description", - link: link_to(t("pages.help.proposals.link"), proposals_path))) %> -

- -
- <%= image_tag "help/proposals_#{I18n.locale}.png", alt: t("pages.help.proposals.image_alt") %> -
<%= t("pages.help.proposals.figcaption") %>
-
-
-
+<%= render Pages::Help::SectionComponent.new("proposals", "help/proposals_#{I18n.locale}.png") do %> +

+ <%= sanitize(t("pages.help.proposals.description", + link: link_to(t("pages.help.proposals.link"), proposals_path))) %> +

+<% end %>