Module: IshManager::ApplicationHelper

Defined in:
app/helpers/ish_manager/application_helper.rb

Instance Method Summary collapse

Instance Method Details

#api_map_path(map) ⇒ Object

api paths



8
9
10
# File 'app/helpers/ish_manager/application_helper.rb', line 8

def api_map_path map
  "/api/maps/view/#{map.slug}"
end

#api_marker_path(marker) ⇒ Object



12
13
14
# File 'app/helpers/ish_manager/application_helper.rb', line 12

def api_marker_path marker
  "/api/markers/view/#{marker.id}"
end

#current_layoutObject



17
18
19
20
21
22
23
24
25
26
27
# File 'app/helpers/ish_manager/application_helper.rb', line 17

def current_layout
  layout = controller.class.send(:_layout)
  if layout.nil?
    '<default>'
  elsif layout.instance_of? String or layout.instance_of? Symbol
    layout
  else
    layout.inspect
    # File.basename(layout.identifier).split('.').first
  end
end

#my_truthy?(which) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
# File 'app/helpers/ish_manager/application_helper.rb', line 29

def my_truthy? which
  ["1", "t", "T", "true"].include?( which )
end

#obfuscate(link) ⇒ Object

def self.obfuscate link

obf = Office::ObfuscatedRedirect.find_or_create_by({ to: link })
return Ishapi::Engine.routes.url_helpers.obf_url( obf.id )

end



45
46
47
48
49
# File 'app/helpers/ish_manager/application_helper.rb', line 45

def obfuscate link
  puts! link, 'obfuscate helper' if DEBUG
  obf = Office::ObfuscatedRedirect.find_or_create_by({ to: link })
  return Ishapi::Engine.routes.url_helpers.obf_url( obf.id )
end

#pp_amount(a) ⇒ Object



85
86
87
88
# File 'app/helpers/ish_manager/application_helper.rb', line 85

def pp_amount a
  return '-' if !a
  "$ #{'%.2f' % a}"
end

#pp_bool(a) ⇒ Object



95
96
97
# File 'app/helpers/ish_manager/application_helper.rb', line 95

def pp_bool a
  a ? 'Y' : '-'
end

#pp_currency(a) ⇒ Object



90
# File 'app/helpers/ish_manager/application_helper.rb', line 90

def pp_currency a; pp_amount a; end

#pp_date(a) ⇒ Object



73
# File 'app/helpers/ish_manager/application_helper.rb', line 73

def pp_date a; pretty_date a; end

#pp_datetime(date) ⇒ Object



75
76
77
# File 'app/helpers/ish_manager/application_helper.rb', line 75

def pp_datetime date
  date&.strftime('%Y-%m-%d %l:%M%P %z')
end

#pp_errors(errors) ⇒ Object

P



55
56
57
# File 'app/helpers/ish_manager/application_helper.rb', line 55

def pp_errors errors
  return errors
end

#pp_list(inns) ⇒ Object



99
100
101
102
103
104
105
106
# File 'app/helpers/ish_manager/application_helper.rb', line 99

def pp_list inns
  out = "<ul>"
  inns.each do |inn|
    out = "#{out}<li>#{inn}</li>"
  end
  out = "#{out}</ul>"
  return raw out
end

#pp_money(a) ⇒ Object



89
# File 'app/helpers/ish_manager/application_helper.rb', line 89

def pp_money a; pp_amount a; end

#pp_percent(a) ⇒ Object



91
92
93
# File 'app/helpers/ish_manager/application_helper.rb', line 91

def pp_percent a
  "#{(a*100).round(2)}%"
end

#pp_time(date) ⇒ Object



79
80
81
82
83
# File 'app/helpers/ish_manager/application_helper.rb', line 79

def pp_time date
  return nil if !date
  # return date.strftime('%l:%M%P %z')
  return date.in_time_zone( Rails.application.config.time_zone ).strftime('%l:%M%P')
end

#pretty_date(date) ⇒ Object



69
70
71
72
# File 'app/helpers/ish_manager/application_helper.rb', line 69

def pretty_date date
  # date.to_s[0, 10]
  date&.strftime('%Y-%m-%d')
end

#user_path(user) ⇒ Object



59
60
61
62
63
64
65
66
67
# File 'app/helpers/ish_manager/application_helper.rb', line 59

def user_path user
  if user.class == 'String'
    "/users/#{user}"
  elsif user.class == User
    "/users/#{user.id}"
  elsif user.class == NilClass
    "/users"
  end
end