Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
gbp committed Nov 22, 2024
1 parent 32565b8 commit d41b88d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 26 deletions.
28 changes: 2 additions & 26 deletions lib/helper_patches.rb
Original file line number Diff line number Diff line change
@@ -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?
Expand Down Expand Up @@ -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
21 changes: 21 additions & 0 deletions lib/helpers/alaveteli_pro/alternative_price_text_helper.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit d41b88d

Please sign in to comment.