File: recent_list.rb

package info (click to toggle)
tdiary 2.2.1%2Bdfsg1-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 14,044 kB
  • ctags: 2,796
  • sloc: ruby: 32,562; lisp: 514; makefile: 83; sh: 72; sql: 40
file content (85 lines) | stat: -rw-r--r-- 2,943 bytes parent folder | download | duplicates (2)
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# $Revision: 1.24 $
# recent_list: Ƕ񤤤Υȥ롤֥ȥɽ
#   ѥ᥿(å̤):
#     days:            ʬɽ뤫(20)
#     date_format:     ɽեޥå(եեޥå)
#     title_with_body: truedzƥѥ饰դؤΥ󥯤title°ˤΥѥ饰դΰ(false)
#     show_size:       trueĹɽ(false)
#     show_title:      truedzΥȥɽ(false)
#
#   : 奢⡼ɤǤϻȤޤ
#   : ȥꥹȤϡ쥤Ȥפʤ
#         ʤޤ󡣥إåեåtableȤäꡢCSS񤭴
#         ɬפǤ礦
#
# Copyright (c) 2001,2002 Junichiro KITA <kita@kitaj.no-ip.com>
# Distributed under the GPL
#
eval( <<MODIFY_CLASS, TOPLEVEL_BINDING )
module TDiary
	class TDiaryMonth
		attr_reader :diaries
	end
end
MODIFY_CLASS

def recent_list( days = 30, date_format = nil, title_with_body = nil, show_size = nil, show_title = nil )
	days = days.to_i
	date_format ||= @date_format

	result = %Q|<ul class="recent-list">\n|

	cgi = CGI::new
	def cgi.referer; nil; end

	catch(:exit) {
		@years.keys.sort.reverse_each do |year|
			@years[year].sort.reverse_each do |month|
				cgi.params['date'] = ["#{year}#{month}"]
				m = TDiaryMonth::new(cgi, '', @conf)
				m.diaries.keys.sort.reverse_each do |date|
					next unless m.diaries[date].visible?
					result << %Q|<li><a href="#{@index}#{anchor date}">#{m.diaries[date].date.strftime(date_format)}</a>\n|
					if show_title and m.diaries[date].title
						result << %Q| #{m.diaries[date].title}|
					end
					if show_size == true
						s = 0
						m.diaries[date].each_section do |section|
							s = s + section.to_s.size.to_i
						end
						result << ":#{s}"
					end
					result << %Q|\t<ul class="recent-list-item">\n|
					i = 1
					if !@plugin_files.grep(/\/category.rb$/).empty? and m.diaries[date].categorizable?
						m.diaries[date].each_section do |section|
							if section.stripped_subtitle
								result << %Q|\t<li><a href="#{h( @index )}#{anchor( "%s#p%02d" % [date, i] )}"|
								result << %Q| title="#{h( @conf.shorten( apply_plugin( section.body_to_html, true) ) )}"| if title_with_body == true
								result << %Q|>#{i}</a>. | \
										<< %Q|#{section.stripped_subtitle_to_html}</li>\n|
							end
							i += 1
						end
					else
						m.diaries[date].each_section do |section|
							if section.subtitle
								result << %Q|\t<li><a href="#{h( @index )}#{anchor( "%s#p%02d" % [date, i] )}"|
								result << %Q| title="#{h( @conf.shorten( apply_plugin(section.body_to_html, true) ) )}"| if title_with_body == true
								result << %Q|>#{i}</a>. | \
										<< %Q|#{section.subtitle_to_html}</li>\n|
							end
							i += 1
						end
					end
					result << "\t</ul>\n</li>\n"
					days -= 1
					throw :exit if days == 0
				end
			end
		end
	}
	apply_plugin( result << "</ul>\n" )
end
# vim: ts=3