| 1 | # category_to_tag.rb - show categories list in end of each section |
|---|
| 2 | # $Revision: 1.6 $ |
|---|
| 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 | end |
|---|
| 28 | alias subtitle_link_original subtitle_link |
|---|
| 29 | def subtitle_link( date, index, subtitle ) |
|---|
| 30 | s = '' |
|---|
| 31 | if subtitle then |
|---|
| 32 | s = subtitle.sub( /^(\[([^\[]+?)\])+/ ) do |
|---|
| 33 | $&.scan( /\[(.*?)\]/ ) do |tag| |
|---|
| 34 | @category_to_tag_list[CGI::unescapeHTML(tag[0])] = false # false when diary |
|---|
| 35 | end |
|---|
| 36 | '' |
|---|
| 37 | end |
|---|
| 38 | end |
|---|
| 39 | subtitle_link_original( date, index, s.strip ) |
|---|
| 40 | end |
|---|
| 41 | add_section_leave_proc do |date, index| |
|---|
| 42 | feed ? '' : category_to_tag_list |
|---|
| 43 | end |
|---|
| 44 | end |
|---|
| 45 | |
|---|
| 46 | def category_to_tag_list |
|---|
| 47 | if @category_to_tag_list and not @category_to_tag_list.empty? then |
|---|
| 48 | r = '<div class="tags">Tags: ' |
|---|
| 49 | @category_to_tag_list.each do |tag, blog| |
|---|
| 50 | if blog |
|---|
| 51 | r << %Q|<a href="#{h @index}?blogcategory=#{h tag}">#{tag}</a> | |
|---|
| 52 | else |
|---|
| 53 | r << category_anchor( "#{tag}" ).sub( /^\[/, '' ).sub( /\]$/, '' ) << ' ' |
|---|
| 54 | end |
|---|
| 55 | end |
|---|
| 56 | r << "</div>\n" |
|---|
| 57 | end |
|---|
| 58 | end |
|---|
| 59 | |
|---|