root/platform/tdiary/plugin/monthly_autopagerize.rb

Revision 37332, 1.8 kB (checked in by drry, 2 years ago)
  • fixed regexes.
  • fixed HTML.
  • et cetera.
Line 
1#
2# monthly_autopagerize.rb - tDiary plugin
3#
4# add <link rel="prev"> and <link rel="next"> tags for AutoPagerize at monthly mode
5#
6# Copyright (C) 2009 MATSUI Shinsuke <poppen@karashi.org>
7# You can redistribute it and/or modify it under GPL2.
8#
9
10if @mode == 'month' then
11        add_header_proc do
12                stream = @conf['monthly_autopagerize.stream'] || 0
13                result = String.new
14
15                ym = []
16                @years.keys.each do |y|
17                        ym += @years[y].collect {|m| y + m}
18                end
19                ym.sort!
20                now = @date.strftime( '%Y%m' )
21                return '' unless ym.index( now )
22                prev_month = ym.index( now ) == 0 ? nil : ym[ym.index( now )-1]
23                next_month = ym[ym.index( now )+1]
24
25                case stream
26                #when 0
27                #       rel_prev_month = 'next'
28                #       rel_next_month = 'prev'
29                when 1
30                        rel_prev_month = 'prev'
31                        rel_next_month = 'next'
32                else
33                        rel_prev_month = 'next'
34                        rel_next_month = 'prev'
35                end
36
37                if prev_month then
38                        result << %Q[<link rel="#{rel_prev_month}" title="#{h navi_prev_month}" href="#{h @index}#{anchor( prev_month )}">\n\t]
39                end
40                if next_month then
41                        result << %Q[<link rel="#{rel_next_month}" title="#{h navi_next_month}" href="#{h @index}#{anchor( next_month )}">\n\t]
42                end
43
44                result.chop.chop
45        end
46end
47
48add_conf_proc( 'monthly_autopagerize', 'Monthly AutoPagerize' ) do
49        if @mode == 'saveconf' then
50                @conf['monthly_autopagerize.stream'] = @cgi.params['monthly_autopagerize.stream'][0].to_i
51        end
52        <<-HTML
53                <h3>Stream of Monthly AutoPagerize</h3>
54                <p><select name="monthly_autopagerize.stream">
55                        <option value="0"#{' selected' if @conf['monthly_autopagerize.stream'] == 0}>To Past</option>
56                        <option value="1"#{' selected' if @conf['monthly_autopagerize.stream'] == 1}>To Future</option>
57                </select></p>
58        HTML
59end
60
61# Local Variables:
62# mode: ruby
63# indent-tabs-mode: t
64# tab-width: 3
65# ruby-indent-level: 3
66# End:
67# vi: ts=3 sw=3
Note: See TracBrowser for help on using the browser.