過去のリビジョンを参照 (2)
2004-06-18
先日の日記に書いた案だけど、 BitChannelの書式を拡張して過去のリビジョンへのリンクを張れるようにした。
* [[SandBox#11]] … SandBox のリビジョン 11
* [[SandBox#11-16]] … SandBox のリビジョン 11 と 16 の差分
セパレータに「:」を使うと InterWikiName と衝突してしまうので、 「#」を使うようにした。 これで、cvsにタグを打つような感じで使えるかな。
lib/bitchannel/page.rb (今日時点での CVS HEAD) を修正している。 変更点は以下の通り。 ちなみに今のところ、存在しないリビジョンを指定するとエラーになっちゃう。
--- tohtml.rb.org Thu Jun 17 18:48:55 2004
+++ tohtml.rb Fri Jun 18 13:41:49 2004
@@ -403,20 +403,28 @@
}
end
- def internal_link(name)
+ def internal_link(name, rev1 = nil, rev2 = nil)
return escape_html(name) if name == @page_name
return escape_html(name) if @repository.invalid?(name)
@internal_links.push name
+ rev = ''
+ rev += '#' + rev1 if rev1
+ rev += '-' + rev2 if rev2
if @repository.exist?(name)
- then %Q[<a href="#{view_url(name)}">#{escape_html(name)}</a>]
- else %Q[<a href="#{view_url(name)}">?</a>#{escape_html(name)}]
+ then %Q[<a href="#{view_url(name, rev1, rev2)}">#{escape_html(name + rev)}</a>]
+ else %Q[<a href="#{view_url(name)}">?</a>#{escape_html(name + rev)}]
end
end
- def view_url(name)
- if @config.html_url?
- then "#{escape_html(URI.escape(name))}#{@config.document_suffix}"
- else "#{cgi_href()}?cmd=view;name=#{escape_html(URI.escape(name))}"
+ def view_url(name, rev1 = nil, rev2 = nil)
+ if rev1 && rev2
+ "#{cgi_href()}?cmd=diff;rev1=#{rev1};rev2=#{rev2};name=#{escape_html(URI.escape(name))}"
+ elsif rev1
+ "#{cgi_href()}?cmd=view;rev=#{rev1};name=#{escape_html(URI.escape(name))}"
+ elsif @config.html_url?
+ "#{escape_html(URI.escape(name))}#{@config.document_suffix}"
+ else
+ "#{cgi_href()}?cmd=view;name=#{escape_html(URI.escape(name))}"
end
end
@@ -449,7 +457,7 @@
end
when SeemsURL then %[<a href="#{escape_html(link)}">#{escape_html(link)}</a>]
when /\A[\w\-]+:/n then interwiki(*link.split(/:/, 2))
- when /\A\w+\z/n then internal_link(link)
+ when /\A(\w+)(#(\d+)(-(\d+))?)?\z/n then internal_link($1, $3, $5)
else link
end
end