~ubuntu-branches/ubuntu/wily/tdiary/wily

« back to all changes in this revision

Viewing changes to contrib2/plugin/category_to_tag.rb

  • Committer: Bazaar Package Importer
  • Author(s): Daigo Moriwaki
  • Date: 2011-04-11 21:53:16 UTC
  • mfrom: (1.2.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20110411215316-ih4gt4q8p29d2wf8
Tags: 3.0.1-1
* New upstream release (Closes: #542801, #594947)
* debian/control:
 - Bumped up Standards-Version to 3.9.1.
 - Updated version dependency.
* debian/tdiary-setup.rb: Followed the upstream changes, incorporating js and
  index.fcgi

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
# category_to_tag.rb - show categories list in end of each section
 
3
#
 
4
# Copyright (C) 2005, TADA Tadashi <sho@spc.gr.jp>
 
5
# You can redistribute it and/or modify it under GPL2.
 
6
#
 
7
 
 
8
if respond_to?( :categorized_title_of_day ) then # BlogKit
 
9
        def categorized_title_of_day( date, title )
 
10
                @category_to_tag_list = {}
 
11
                cats, stripped = title.scan( /^((?:\[[^\]]+\])+)\s*(.*)/ )[0]
 
12
                if cats then
 
13
                        cats.scan( /\[([^\]]+)\]+/ ).flatten.each do |tag|
 
14
                                @category_to_tag_list[tag] = true # true when blog
 
15
                        end
 
16
                else
 
17
                        stripped = title
 
18
                end
 
19
                stripped
 
20
        end
 
21
        add_body_leave_proc do |date|
 
22
                feed ? '' : category_to_tag_list
 
23
        end
 
24
elsif respond_to?( :category_anchor ) # diary
 
25
        add_section_enter_proc do |date, index|
 
26
                @category_to_tag_list = {}
 
27
                ''
 
28
        end
 
29
        alias subtitle_link_original subtitle_link
 
30
        def subtitle_link( date, index, subtitle )
 
31
                s = ''
 
32
                if subtitle then
 
33
                        s = subtitle.sub( /^(\[([^\[]+?)\])+/ ) do
 
34
                                $&.scan( /\[(.*?)\]/ ) do |tag|
 
35
                                        @category_to_tag_list[CGI::unescapeHTML(tag[0])] = false # false when diary
 
36
                                end
 
37
                                ''
 
38
                        end
 
39
                end
 
40
                subtitle_link_original( date, index, s.strip )
 
41
        end
 
42
        add_section_leave_proc do |date, index|
 
43
                feed ? '' : category_to_tag_list
 
44
        end
 
45
end
 
46
 
 
47
def category_to_tag_list
 
48
        if @category_to_tag_list and not @category_to_tag_list.empty? then
 
49
                r = '<div class="tags">Tags: '
 
50
                @category_to_tag_list.each do |tag, blog|
 
51
                        if blog
 
52
                                r << %Q|<a href="#{h @index}?blogcategory=#{h tag}">#{tag}</a> |
 
53
                        else
 
54
                                r << category_anchor( "#{tag}" ).sub( /^\[/, '' ).sub( /\]$/, '' ) << ' '
 
55
                        end
 
56
                end
 
57
                r << "</div>\n"
 
58
        end
 
59
end
 
60