From d41b88d88add6be57c7656d7b3aa73635d6cf6dd Mon Sep 17 00:00:00 2001 From: Graeme Porteous Date: Fri, 22 Nov 2024 10:20:11 +0000 Subject: [PATCH] WIP --- lib/helper_patches.rb | 28 ++----------------- .../alternative_price_text_helper.rb | 21 ++++++++++++++ 2 files changed, 23 insertions(+), 26 deletions(-) create mode 100644 lib/helpers/alaveteli_pro/alternative_price_text_helper.rb diff --git a/lib/helper_patches.rb b/lib/helper_patches.rb index 117f1213..fb1fc13f 100644 --- a/lib/helper_patches.rb +++ b/lib/helper_patches.rb @@ -1,8 +1,10 @@ # Load our helpers require 'helpers/donation_helper' +require 'helpers/alaveteli_pro/alternative_price_text_helper' Rails.configuration.to_prepare do ActionView::Base.send(:include, DonationHelper) + ActionView::Base.send(:include, AlaveteliPro::AlternativePriceTextHelper) ApplicationHelper.class_eval do def is_contact_page? @@ -31,30 +33,4 @@ def hidden_by_excel_analyzer? prepend ExcelAnalyzerDisableContactUs end - - AlaveteliPro::PriceHelper.class_eval do - module AlternativePriceText - def short_alternative_price_text(price) - amount = format_currency( - price.unit_amount_with_tax, no_cents_if_whole: true - ) - - if interval(price) == 'day' && interval_count(price) == 1 - _('or {{amount}} daily', amount: amount) - elsif interval(price) == 'week' && interval_count(price) == 1 - _('or {{amount}} weekly', amount: amount) - elsif interval(price) == 'month' && interval_count(price) == 1 - _('or {{amount}} monthly', amount: amount) - elsif interval(price) == 'year' && interval_count(price) == 1 - _('or {{amount}} annually', amount: amount) - else - _('or {{amount}} every {{interval}}', - amount: amount, - interval: pluralize_interval(price)) - end - end - end - - prepend AlternativePriceText - end end diff --git a/lib/helpers/alaveteli_pro/alternative_price_text_helper.rb b/lib/helpers/alaveteli_pro/alternative_price_text_helper.rb new file mode 100644 index 00000000..dd8d0e66 --- /dev/null +++ b/lib/helpers/alaveteli_pro/alternative_price_text_helper.rb @@ -0,0 +1,21 @@ +module AlaveteliPro::AlternativePriceTextHelper + def short_alternative_price_text(price) + amount = format_currency( + price.unit_amount_with_tax, no_cents_if_whole: true + ) + + if interval(price) == 'day' && interval_count(price) == 1 + _('or {{amount}} daily', amount: amount) + elsif interval(price) == 'week' && interval_count(price) == 1 + _('or {{amount}} weekly', amount: amount) + elsif interval(price) == 'month' && interval_count(price) == 1 + _('or {{amount}} monthly', amount: amount) + elsif interval(price) == 'year' && interval_count(price) == 1 + _('or {{amount}} annually', amount: amount) + else + _('or {{amount}} every {{interval}}', + amount: amount, + interval: pluralize_interval(price)) + end + end +end