Module: SimpleCataloger::Helpers
- Defined in:
- lib/dircat/server/helpers.rb
Instance Method Summary collapse
- #base_url ⇒ Object
- #gen_url(field, visible_field = nil) ⇒ Object
- #partial(template, *args) ⇒ Object
- #partial_erb(template) ⇒ Object
- #rfc_3339(timestamp) ⇒ Object
- #when_updated(time) ⇒ Object
Instance Method Details
#base_url ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/dircat/server/helpers.rb', line 25 def base_url if Sinatra::Application.port == 80 "http://#{Sinatra::Application.host}/" else "http://#{Sinatra::Application.host}:#{Sinatra::Application.port}/" end end |
#gen_url(field, visible_field = nil) ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/dircat/server/helpers.rb', line 45 def gen_url(field, visible_field = nil) visible_field ||= field pos = request.env['REQUEST_URI'].index "?" url = if pos request.env['REQUEST_URI'][0...pos] else request.env['REQUEST_URI'] end "<a href='#{url}?order=#{field}'>#{visible_field}</a>" end |
#partial(template, *args) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/dircat/server/helpers.rb', line 5 def partial(template, *args) = args. .merge!(:layout => false) if collection = .delete(:collection) then collection.inject([]) do |buffer, member| buffer << haml(template, .merge( :layout => false, :locals => {template.to_sym => member} ) ) end.join("\n") else haml(template, ) end end |
#partial_erb(template) ⇒ Object
21 22 23 |
# File 'lib/dircat/server/helpers.rb', line 21 def partial_erb(template) erb template end |
#rfc_3339(timestamp) ⇒ Object
56 57 58 |
# File 'lib/dircat/server/helpers.rb', line 56 def rfc_3339() .strftime("%Y-%m-%dT%H:%M:%SZ") end |
#when_updated(time) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/dircat/server/helpers.rb', line 33 def when_updated(time) days = (Time.now - time) / (60 * 60 * 24) case days.to_i when 0 "today" when 1 "yesterday" else "#{sprintf("%i", days) } days ago" end end |