# -*- coding: utf-8 -*- # my-ex.rb # # my(拡張版): myプラグインを拡張し、title属性に参照先の内容を挿入します。 # 参照先がセクションの場合は(あれば)サブタイトルを、 # ツッコミの場合はツッコんだ人の名前と内容の一部を使います。 # パラメタ: # a: 自分の日記内のリンク先情報('YYYYMMDD#pNN' または 'YYYYMMDD#cNN') # URLをそのまま書くこともできます。 # str: リンクにする文字列 # # Copyright (c) 2002 TADA Tadashi # Distributed under the GPL unless @conf.mobile_agent? alias :my_overridden_by_my_ex :my def my( a, str, title = nil ) title = h(title) if title m = /^(\d{8})\D*(?:([pct])(\d+))?$/.match( a ) return my_overridden_by_my_ex( a, str, title ) unless m _, date, place, frag = *m if title.nil? and date and frag and @diaries[date] then title = h( "%d年% 2d月% 2d日: " % [ date[0,4].to_i, date[4,2].to_i, date[6,2].to_i ] ) case place when 'p' section = nil idx = 1 @diaries[date].each_section do |s| section = s break if idx == frag.to_i idx += 1 end if section and section.subtitle then title += h( apply_plugin( section.subtitle_to_html, true ).sub( /^(\[([^\]]+)\])+ */, '' ) ) end when 'c' com = nil @diaries[date].each_comment( frag.to_i ) {|c| com = c} if com then title += h( "[#{com.name}] #{com.shorten( @conf.comment_length )}" ) end when 't' if @plugin_files.grep(/tb-show.rb\z/) tb = nil @diaries[date].each_visible_trackback( frag.to_i ) {|t, idx| tb = t} if tb then url, name, tbtitle, excerpt = tb.body.split( /\n/,4 ) title += h( "[#{name}] #{@conf.shorten( excerpt, @conf.comment_length )}" ) end end end end index = /^https?:/ =~ @index ? '' : @conf.base_url index += @index.sub(%r|^\./|, '') if title then %Q[#{str}] else %Q[#{str}] end end end # Local Variables: # mode: ruby # indent-tabs-mode: t # tab-width: 3 # ruby-indent-level: 3 # End: