Replace helper function by decorator methods

This commit is contained in:
kikito
2016-12-05 17:28:30 +01:00
parent 09539028a2
commit 703cc72953
8 changed files with 24 additions and 15 deletions

View File

@@ -1,10 +1,4 @@
module BudgetHelper
def format_price(budget, number)
number_to_currency(number,
precision: 0,
locale: I18n.default_locale,
unit: budget.currency_symbol)
end
def heading_name(heading)
heading.present? ? heading.name : t("budget.headings.none")

View File

@@ -42,5 +42,16 @@ class Budget < ActiveRecord::Base
def heading_price(heading)
heading_ids.include?(heading.id) ? heading.price : -1
end
def formatted_amount(amount)
ActionController::Base.helpers.number_to_currency(amount,
precision: 0,
locale: I18n.default_locale,
unit: currency_symbol)
end
def formatted_heading_price(heading)
formatted_ammount(heading_price(heading))
end
end

View File

@@ -203,6 +203,10 @@ class Budget
budget.balloting?
end
def formatted_price
budget.formatted_amount(price)
end
private
def set_denormalized_ids

View File

@@ -28,7 +28,7 @@
<h4 class="amount-spent text-right">
<%= t("budgets.ballots.show.amount_spent") %>
<span>
<%= format_price(@budget, @ballot.amount_spent(@ballot.heading_for_group(group).id)) %>
<%= @budget.formatted_amount(@ballot.amount_spent(@ballot.heading_for_group(group).id))) %>
</span>
</h4>
<% else %>
@@ -47,9 +47,9 @@
<h4>
<%= t("budgets.ballots.show.remaining",
amount_city: format_price(@budget, @ballot.amount_available(@ballot.heading_for_group(group)))).html_safe %>
amount_city: @budget.formatted_amount(@ballot.amount_available(@ballot.heading_for_group(group))))).html_safe %>
</h4>
</div>
<% end %>
</div>
</div>
</div>

View File

@@ -1,6 +1,6 @@
<li id="<%= dom_id(investment) %>">
<%= link_to investment.title, budget_investment_path(@budget, investment) %>
<span><%= format_price(@budget, investment.price) %></span>
<span><%= investment.formatted_price %></span>
<% if @budget.balloting? %>
<%= link_to budget_ballot_line_path(@budget, id: investment.id),

View File

@@ -1,6 +1,6 @@
<li id="<%= dom_id(investment) %>_sidebar">
<%= investment.title %>
<span><%= format_price(@budget, investment.price) %></span>
<span><%= investment.formatted_price %></span>
<% if @budget.balloting? %>
<%= link_to budget_ballot_line_url(id: investment.id,

View File

@@ -1,5 +1,5 @@
<span class="total-amount">
<%= format_price(@budget, @budget.heading_price(@heading)) %>
<%= @budget.formatted_heading_price(@heading) %>
</span>
<div class="progress" role="progressbar" tabindex="0"
@@ -18,10 +18,10 @@
<%= progress_bar_width(@budget.heading_price(@heading),
@ballot.amount_spent(@heading.id)) %>">
<p id="amount-spent" class="progress-meter-text spent-amount-text">
<%= format_price(@budget, @ballot.amount_spent(@heading.id)) %>
<%= @budget.format_amount(@ballot.amount_spent(@heading.id)) %>
<span id="amount-available" class="amount-available">
<%= t("spending_proposals.index.available") %>
<span><%= format_price(@budget, @ballot.amount_available(@heading)) %></span>
<span><%= @budget.format_amount(@ballot.amount_available(@heading)) %></span>
</span>
</p>
</span>

View File

@@ -13,7 +13,7 @@
<em>
<%= t("budget.investments.index.sidebar.voted_html",
count: @ballot.investments.by_heading(@heading.id).count,
amount_spent: format_price(@budget, @ballot.amount_spent(@heading))) %>
amount_spent: @budget.format_amount(@ballot.amount_spent(@heading))) %>
</em>
</p>
<% else %>