2 def shorten_description(text, chars)
3 text.sub /^(.{0,#{chars}}\b).*/m, '\1'
7 desc.gsub(/([\w.]+)@([\w.]+)/,'\1 [at] xxx').gsub(/\n/, "<br/>")
10 # returns an array of tokens: :prev, :next, :dots or
12 def paginator_list(page_count, current_page)
13 range = 3 #show 4 pages around current page
15 return list if page_count == 1
17 list << :prev unless current_page == 1
19 # add start block unless midrange includes first page
20 if current_page > range+1
21 1.upto current_page-range-1 do |page|
30 midstart = current_page-range < 1 ? 1 : current_page-range
31 midend = page_count-range < current_page ? page_count : current_page+range
32 midstart.upto midend do |page|
36 list << :dots if midend < page_count-range-1
38 if page_count > current_page+range
39 (page_count-range).upto page_count do |page|
40 next if page <= midend
45 list << :next if current_page != page_count
49 def default_baseproject
55 Rails.cache.fetch('top_downloads', :expires_in => 12.hours) do
56 list=ActiveRecord::Base.connection.execute('select query, count(*) as c from download_histories where query is NOT NULL group by query order by c desc limit 200;')
59 s = entry[0].strip.downcase
61 queries[s] += entry[1].to_i
64 queries = queries.to_a.sort { |x,y| y[1] <=> x[1] }
68 tops << { :query => q, :count => c}