Module: Discobolo::WebHelpers
- Defined in:
- lib/discobolo/web.rb
Instance Method Summary collapse
- #client ⇒ Object
- #link_to(name, path, options = {}) ⇒ Object
- #relative_time(start_time) ⇒ Object
- #url_for(path) ⇒ Object
Instance Method Details
#client ⇒ Object
16 17 18 |
# File 'lib/discobolo/web.rb', line 16 def client Discobolo::Config.client end |
#link_to(name, path, options = {}) ⇒ Object
25 26 27 |
# File 'lib/discobolo/web.rb', line 25 def link_to(name, path, ={}) "<a href='#{url_for(path)}'>#{name}</a>" end |
#relative_time(start_time) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/discobolo/web.rb', line 29 def relative_time(start_time) #start_time = start_time.is_a?(Integer) ? Time.at(start_time) : start_time diff_seconds = start_time case start_time when 0 .. 59 out = "in #{diff_seconds.round(2)} seconds" when 60 .. (3600-1) out = "in #{(diff_seconds/60).round(2)} minutes" when 3600 .. (3600*24-1) out = "in #{(diff_seconds/3600).round(2)} hours" when (3600*24) .. (3600*24*30) out = "in #{diff_seconds/(3600*24).round(2)} days" else out = start_time.strftime("%m/%d/%Y") end out end |
#url_for(path) ⇒ Object
20 21 22 23 |
# File 'lib/discobolo/web.rb', line 20 def url_for(path) base_path = request.script_name [base_path,path].join("/") end |