From 4ade857a1bec0b63afdcfaa241ce9e6abbb0b628 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Fri, 4 Jan 2019 19:19:07 +0100 Subject: [PATCH] Extract method to render number and info We're going to use it in many places, so removing duplication is useful. --- app/helpers/stats_helper.rb | 6 ++++ .../shared/stats/_participation.html.erb | 33 +++++++++---------- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/app/helpers/stats_helper.rb b/app/helpers/stats_helper.rb index 5fd42027e..eef463a99 100644 --- a/app/helpers/stats_helper.rb +++ b/app/helpers/stats_helper.rb @@ -34,4 +34,10 @@ module StatsHelper def number_to_stats_percentage(number, options = {}) number_to_percentage(number, { strip_insignificant_zeros: true, precision: 2 }.merge(options)) end + + def number_with_info_tags(number, text, html_class: "") + content_tag :p, class: "number-with-info #{html_class}".strip do + content_tag(:span, number, class: "number") + content_tag(:span, text, class: "info") + end + end end diff --git a/app/views/shared/stats/_participation.html.erb b/app/views/shared/stats/_participation.html.erb index d49fb839b..a806e2d0a 100644 --- a/app/views/shared/stats/_participation.html.erb +++ b/app/views/shared/stats/_participation.html.erb @@ -4,30 +4,27 @@

<%= t("stats.total_participants") %>

-

- <%= stats[:total_participants] %> - <%= t("polls.show.stats.total_votes") %> -

+ <%= number_with_info_tags( + stats[:total_participants], + t("polls.show.stats.total_votes"), + html_class: "participants total-participants" + ) %>

<%= t("stats.by_gender") %>

-

- <%= stats[:total_male_participants] %> - - <%= I18n.t("stats.men_percentage", - percentage: number_to_stats_percentage(stats[:male_percentage])) %> - -

+ <%= number_with_info_tags( + stats[:total_male_participants], + t("stats.men_percentage", percentage: number_to_stats_percentage(stats[:male_percentage])), + html_class: "participants male" + ) %> -

- <%= stats[:total_female_participants] %> - - <%= I18n.t("stats.women_percentage", - percentage: number_to_stats_percentage(stats[:female_percentage])) %> - -

+ <%= number_with_info_tags( + stats[:total_female_participants], + t("stats.women_percentage", percentage: number_to_stats_percentage(stats[:female_percentage])), + html_class: "participants female" + ) %>