1 # Methods added to this helper will be available to all templates in the application.
2 module ApplicationHelper
7 return @@theme_prefix if @@theme_prefix
8 @@theme_prefix = '/themes'
9 if ActionController::Base.relative_url_root
10 @@theme_prefix = ActionController::Base.relative_url_root + @@theme_prefix
15 def compute_asset_host(source)
16 if defined? USE_STATIC
17 if source.slice(0, theme_prefix.length) == theme_prefix
18 return "http://static.opensuse.org"
20 return "http://static.opensuse.org/hosts/#{USE_STATIC}"
27 scr = "setCookie('search_baseproject','#{@baseproject}');\n"
29 scr = "var p = getCookie('search_baseproject'); if (p) { $(\"#baseproject option[value='\" + p + \"']\").attr('selected', 'selected'); }\n"
31 "<script type=\"text/javascript\">\n" +
39 r = Rails.cache.read('top_downloads')
40 # it's possible we will have to enqueue one on cold caches
41 Delayed::Job.enqueue SearchHelperJob.new unless r
46 Time.now - Time.parse(time)
49 def fuzzy_time_string(time)
50 return "unknown date" if time.blank?
51 return "now" if time_diff(time) < 60
52 diff = Integer(time_diff(time)/60) # now minutes
53 return diff.to_s + (diff == 1 ? " min ago" : " mins ago") if diff < 60
54 diff = Integer(diff/60) # now hours
55 return diff.to_s + (diff == 1 ? " hour ago" : " hours ago") if diff < 24
56 diff = Integer(diff/24) # now days
57 return diff.to_s + (diff == 1 ? " day ago" : " days ago") if diff < 14
58 diff = Integer(diff/7) # now weeks
59 return diff.to_s + (diff == 1 ? " week ago" : " weeks ago") if diff < 9
60 diff = Integer(diff/4.1) # roughly months
61 return diff.to_s + " months ago" if diff < 24
62 diff = Integer(diff/12) # years
63 return diff.to_s + " years ago"
72 key.gsub(/_SP/,'.').gsub(/_Factory/,'_100').split(/_/).map { |v| v =~ /\A\d+(\.\d+)?\z/ ? -(v.to_f) : v.downcase }