Module: Pyk::Helpers
- Defined in:
- lib/pyk/helpers.rb
Instance Method Summary collapse
- #color_amount(d) ⇒ Object
-
#devise_error_messages! ⇒ Object
DEVISE end.
- #devise_mapping ⇒ Object
- #dp(email, size = 20) ⇒ Object
- #icon_d ⇒ Object
- #location_map(u) ⇒ Object
-
#location_summary(u) ⇒ Object
————————————————————————————————————– ADDRESS ————————————————————————————————————–.
- #location_summary_short(u) ⇒ Object
- #n2h(d) ⇒ Object
- #r ⇒ Object
- #remove_decimal(str) ⇒ Object
- #resource ⇒ Object
-
#resource_name ⇒ Object
————————————————————————————————————– DEVISE ————————————————————————————————————–.
-
#smart_date(i, mode = "date") ⇒ Object
————————————————————————————————————– DATE ————————————————————————————————————–.
- #smart_due_date(i) ⇒ Object
- #stock_market(d) ⇒ Object
-
#title(page_title) ⇒ Object
————————————————————————————————————– GENERIC ————————————————————————————————————–.
-
#two_decimal_points(ff) ⇒ Object
————————————————————————————————————– NUMBERS ————————————————————————————————————–.
Instance Method Details
#color_amount(d) ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/pyk/helpers.rb', line 57 def color_amount(d) if d < 0 "<span class='red'>(#{number_to_currency(d, unit: '')})</span>".html_safe else number_to_currency(d, unit: '') end end |
#devise_error_messages! ⇒ Object
DEVISE end
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/pyk/helpers.rb', line 131 def flash_alerts = [] error_key = 'errors.messages.not_saved' if !flash.empty? flash_alerts.push(flash[:error]) if flash[:error] flash_alerts.push(flash[:alert]) if flash[:alert] flash_alerts.push(flash[:notice]) if flash[:notice] error_key = 'devise.failure.invalid' end return "" if resource.errors.empty? && flash_alerts.empty? errors = resource.errors.empty? ? flash_alerts : resource.errors. = errors.map { |msg| content_tag(:li, msg) }.join sentence = I18n.t(error_key, :count => errors.count, :resource => resource.class.model_name.human.downcase) html = <<-HTML <div id="error_explanation"> <h2>#{sentence}</h2> <ul>#{}</ul> </div> HTML html.html_safe end |
#devise_mapping ⇒ Object
125 126 127 |
# File 'lib/pyk/helpers.rb', line 125 def devise_mapping @devise_mapping ||= Devise.mappings[:user] end |
#dp(email, size = 20) ⇒ Object
11 12 13 |
# File 'lib/pyk/helpers.rb', line 11 def dp(email, size=20) Pyk::Gravatar.dp(email, size) end |
#icon_d ⇒ Object
15 16 17 |
# File 'lib/pyk/helpers.rb', line 15 def icon_d "<span class='glyphicon glyphicon-trash'></span>".html_safe end |
#location_map(u) ⇒ Object
109 110 111 |
# File 'lib/pyk/helpers.rb', line 109 def location_map(u) return Pyk::Address.map(u, 300, 95) end |
#location_summary(u) ⇒ Object
ADDRESS
101 102 103 |
# File 'lib/pyk/helpers.rb', line 101 def location_summary(u) return Pyk::Address.to_s(u) end |
#location_summary_short(u) ⇒ Object
105 106 107 |
# File 'lib/pyk/helpers.rb', line 105 def location_summary_short(u) return Pyk::Address.gist(u) end |
#n2h(d) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/pyk/helpers.rb', line 39 def n2h(d) begin return number_to_human(d, significant: false, precision: 1) rescue return d end end |
#r ⇒ Object
19 20 21 |
# File 'lib/pyk/helpers.rb', line 19 def r "<i class='icon-repeat'></i>".html_safe end |
#remove_decimal(str) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/pyk/helpers.rb', line 31 def remove_decimal(str) str = str.to_s if str.index(".").present? str = str[0..(str.index(".") - 1)] end str end |
#resource ⇒ Object
121 122 123 |
# File 'lib/pyk/helpers.rb', line 121 def resource @resource ||= User.new end |
#resource_name ⇒ Object
DEVISE
117 118 119 |
# File 'lib/pyk/helpers.rb', line 117 def resource_name :user end |
#smart_date(i, mode = "date") ⇒ Object
DATE
69 70 71 72 73 74 75 76 77 |
# File 'lib/pyk/helpers.rb', line 69 def smart_date(i, mode="date") if i.blank? return "" elsif (i.class.to_s == "Time" or i.class.to_s == "ActiveSupport::TimeWithZone") and mode == "time" return i.year == Time.now.year ? i.strftime("%d-%b %H:%M") : i.strftime("%d-%b-%Y %H:%M") else return i.year == Time.now.year ? i.strftime("%d-%b") : i.strftime("%d-%b-%Y") end end |
#smart_due_date(i) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/pyk/helpers.rb', line 79 def smart_due_date(i) if i == nil return "" elsif i.class.to_s == "Time" or i.class.to_s == "ActiveSupport::TimeWithZone" i = i.to_date end if Date.today == i return "<span style=\"background-color:#F7FAB9;padding:0px 2px 0px 2px;\">Today</span>" elsif i - Date.today == 1 return "<span style=\"background-color:#F7FAB9;padding:0px 2px 0px 2px;\">Tomorrow</span>" elsif Date.today - i > 0.9 return "<span style=\"background-color:#FFC7C7;padding:0px 2px 0px 2px;\">" + smart_date(i) + "</span>" elsif Date.today - i < 1 return "<span style=\"background-color:#D2FFCC;padding:0px 2px 0px 2px;\">" + smart_date(i) + "</span>" end return smart_date(i, "date") end |
#stock_market(d) ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/pyk/helpers.rb', line 47 def stock_market(d) if d < 0 return "<span style='color: red;'><i class='icon-arrow-down'></i></span> #{d}%".html_safe elsif d > 0 return "<span style='color: green;'><i class='icon-arrow-up'></i></span> #{d}%".html_safe else return d end end |
#title(page_title) ⇒ Object
GENERIC
7 8 9 |
# File 'lib/pyk/helpers.rb', line 7 def title(page_title) content_for(:title) { page_title } end |
#two_decimal_points(ff) ⇒ Object
NUMBERS
27 28 29 |
# File 'lib/pyk/helpers.rb', line 27 def two_decimal_points(ff) sprintf("%0.02f", ff) end |