Skip to content

Commit

Permalink
Refactor loading of theme Pro Price helper
Browse files Browse the repository at this point in the history
Prepending module to the Pro Price helper was causing issues in CI only.
We don't actually have to do this as helper modules are all included
into the same context via ActionView::Base.
  • Loading branch information
gbp committed Nov 22, 2024
1 parent 1d1412b commit e7f6565
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 27 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 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
2 changes: 1 addition & 1 deletion lib/views/alaveteli_pro/plans/_pricing_tiers.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</p>

<p class="price-label-option">
<%= link_to short_alternative_price_text(@prices[1]), plan_path(@prices[1]) %>
<%= link_to alternative_price_text(@prices[1]), plan_path(@prices[1]) %>
</p>
</div>

Expand Down

0 comments on commit e7f6565

Please sign in to comment.