File: category.rb

package info (click to toggle)
hiki 0.8.7-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 1,796 kB
  • ctags: 1,736
  • sloc: ruby: 20,269; lisp: 926; sh: 269; makefile: 12
file content (39 lines) | stat: -rw-r--r-- 954 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# $Id: category.rb,v 1.6 2005/09/30 11:45:49 fdiary Exp $
# Copyright (C) 2002-2003 TAKEUCHI Hitoshi <hitoshi@namaraii.com>

def category_list(*category)
  category_re = /^\(([^\)]+?)\)/

  category.collect! {|a| a.unescapeHTML}
  
  l = Hash::new
  @db.page_info.each do |a|
    if category_re =~ a.keys[0] && (category.size == 0 || category.index($1))
      l[$1] = [] unless l[$1]
      l[$1] << a
    end
  end

  # sort by category
  list = l.to_a.sort {|a,b| a[0] <=> b[0]}
  s = ''

  list.each do |j|
    category = j[0]
    p = j[1]
    s << "<h2>#{view_title(category)}</h2>\n"
    s << "<ul>\n"
    # sort by page name
    p.collect! { |i| i.to_a.flatten! }.sort! do |p1, p2|
      p2[1][:last_modified] <=> p1[1][:last_modified]
    end
    
    p.each do |a|
      name = a[0]
      tm = a[1][:last_modified]
      s << "<li>#{format_date( tm )}: #{hiki_anchor(name.escape, page_name(name))}</li>\n"
    end
    s << "</ul>\n"
  end
  s
end