Skip to content

Instantly share code, notes, and snippets.

@r38y
Created February 18, 2012 22:03
Show Gist options
  • Save r38y/1861121 to your computer and use it in GitHub Desktop.
Save r38y/1861121 to your computer and use it in GitHub Desktop.
class ApplicationDecorator < Draper::Base
def initialize(input, options={})
input = input.model if input.is_a?(self.class)
super input, options
end
end
class PlanDecorator < ApplicationDecorator
decorates :plan
decorates_association :weigh_ins
decorates_association :purchase
decorates_association :owner
def description
purchase.description
end
def number
"##{plan.id}"
end
def admin_link
if plan
h.link_to number, h.admin_plan_path(plan)
else
"n/a"
end
end
def wager
h.lioli_money plan.wager
end
def penalty
h.lioli_money plan.penalty
end
def refund
h.lioli_money plan.refund
end
def goal_delta
"#{plan.goal_delta.to_i} lb"
end
def skipped_weigh_in_penalty
h.lioli_money plan.skipped_weigh_in_penalty
end
def missed_goal_penalty
h.lioli_money plan.missed_goal_penalty
end
def type_description
if plan.keep_it_off?
"keep it off"
else
"lose #{goal_delta}"
end
end
def no_friends_message(current_user=nil)
edit_friends_link = h.link_to "Notify some friends", h.edit_friends_path
h.content_tag(:p, :class => 'blank') do
if plan.owned_by?(current_user)
if plan.keep_it_off?
"Keeping off the weight alone sucks. #{edit_friends_link} to help you with keeping it off!"
else
"Losing weight alone sucks. #{edit_friends_link} to help you with losing weight!"
end
else
"They haven't added friends yet."
end.html_safe
end
end
def no_strategy_message(current_user=nil)
edit_strategy_link = h.link_to 'Come up with a strategy', h.edit_strategy_path
h.content_tag(:p, :class => 'blank') do
if plan.owned_by?(current_user)
if plan.keep_it_off?
"#{ edit_strategy_link } for keeping off the weight so whenever you are unsure of what to do, you can come back to it and decide."
else
"#{ edit_strategy_link } for losing the weight so whenever you are unsure of what to do, you can come back to it and decide."
end
else
"They haven't added a strategy yet."
end.html_safe
end
end
def no_incentives_message(current_user=nil)
edit_incentives_link = h.link_to 'adding some incentives', h.edit_incentives_path
h.content_tag(:p, :class => 'blank') do
if plan.owned_by?(current_user)
"Keep yourself motivated by #{edit_incentives_link} to your profile which you will buy with your reward."
else
"They haven't added incentives yet."
end.html_safe
end
end
def edit_strategy_intro
h.content_tag(:p, :class => 'introduction') do
if plan.keep_it_off?
"How are you going to keep off the weight this time? Share some details&hellip;"
else
"How are you going to lose weight this time? Share some details&hellip;"
end.html_safe
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment