画像が見つからないときにテキストリンクを表示する(true)か noimage画像を表示する(false)かの設定。
class="amazon"の時に画像の横に表示されるテキストと、画像の代替テキストなど(alt, title)は区別して、altや titleは常に設定されるようにして欲しい。
この辺のことです。
if with_image and @conf['amazon.hidename'] || pos != 'amazon' then
label = ''
elsif not label
label = %Q|#{amazon_title( item )}#{author}|
end
両方とも自分でなんとかしてみる。
def amazon_image( item )
image = {}
begin
size = case @conf['amazon.imgsize']
when 0; 'Large'
when 2; 'Small'
else; 'Medium'
end
image[:src] = item.elements.to_a( "#{size}Image/URL" )[0].text
image[:height] = item.elements.to_a( "#{size}Image/Height" )[0].text
image[:width] = item.elements.to_a( "#{size}Image/Width" )[0].text
rescue
image[:src] = image[:height] = image[:width] = nil
end
image
end
def amazon_default_image
image = {}
base = @conf['amazon.default_image_base'] || 'http://www.tdiary.org/images/amazondefaults/'
case @conf['amazon.imgsize']
when 0
image[:src] = "#{base}large.png"
image[:height] = 500
image[:width] = 380
when 2
image[:src] = "#{base}small.png"
image[:height] = 75
image[:width] = 57
else
image[:src] = "#{base}medium.png"
image[:height] = 160
image[:width] = 122
end
image
end
def amazon_to_html( item, with_image = true, label = nil, pos = 'amazon' )
with_image = false if @mode == 'categoryview'
author = amazon_author( item )
author = "(#{author})" unless author.empty?
label = %Q|#{amazon_title( item )}#{author}| unless label
if with_image
image = amazon_image( item )
image = amazon_default_image if not image[:src] and not @conf['amazon.nodefault']
if image[:src] then
img = <<-HTML
<img class="#{h pos}" src="#{h image[:src]}"
height="#{h image[:height]}" width="#{h image[:width]}"
alt="#{h label}" title="#{h label}">
HTML
img.gsub!( /\t/, '' )
label = '' if @conf['amazon.hidename'] || pos != 'amazon'
else
img = ''
end
end
url = amazon_url( item )
%Q|<a href="#{h url}">#{img}#{h label}</a>|
end
動いているようだ。labelという変数に二つの役割が与えられているのが微かに気になるが。
def amazon_get( asin, with_image = true, label = nil, pos = 'amazon' )
……(省略)……
rescue Timeout::Error
asin
rescue NoMethodError
if item == nil then
message = doc.elements.to_a( 'Items/Request/Errors/Error/Message' )[0].text
"#{label ? label : asin}<!--#{h @conf.to_native( message, 'utf-8' )}-->"
else
"#{label ? label : asin}<!--#{h $!}\n#{h $@.join( ' / ' )}-->"
end
end
labelは他の場所で HTMLエスケープ前の文字列として扱われているのでエスケープするのがよい。asinだって中身が英数字に違いなかろうがなんだろうがエスケープすればいい。
コメント(<!---->)の中身は h(ERB::Util.html_escape) する必要はなく .gsub(/--+/, '-') した方が良い、とまで言うとパラノイア・原理主義者っぽい気がするのは何故? コメントに起因する不具合に遭ったことがないから?
tDiary-2.1.4からは section_enter_procと section_leave_procが用意されてるので、現在 body_leave_procを使って一日毎に行ってることを、section_leave_procでセクション毎に行うだけ。
構わないと思うのですよ、リロードの度にプラグインを評価しなくても。
--- index.rb~ 2005-06-13 14:05:11.000000000 +0900 +++ index.rb 2006-06-11 00:52:18.203125000 +0900 @@ -60,11 +60,15 @@ body = '' head['Last-Modified'] = CGI::rfc1123_date( tdiary.last_modified ) + require 'time' + ims = ENV['HTTP_IF_MODIFIED_SINCE']; ims = ims ? Time.httpdate(ims) : Time.at(0); # ENV? + diary_changed = (tdiary.last_modified - ims) > 30; # 30? + # ETag testing code #require 'md5' #head['ETag'] = MD5::md5( body ) - if /HEAD/i !~ @cgi.request_method then + if /HEAD/i !~ @cgi.request_method and diary_changed then if @cgi.mobile_agent? then body = conf.to_mobile( tdiary.eval_rhtml( 'i.' ) ) head['charset'] = conf.mobile_encoding @@ -73,15 +77,15 @@ body = tdiary.eval_rhtml head['charset'] = conf.encoding head['Content-Length'] = body.size.to_s - head['Pragma'] = 'no-cache' - head['Cache-Control'] = 'no-cache' +# head['Pragma'] = 'no-cache' +# head['Cache-Control'] = 'no-cache' end head['cookie'] = tdiary.cookies if tdiary.cookies.size > 0 print @cgi.header( head ) print body else - head['Pragma'] = 'no-cache' - head['Cache-Control'] = 'no-cache' +# head['Pragma'] = 'no-cache' +# head['Cache-Control'] = 'no-cache' print @cgi.header( head ) end rescue TDiary::ForceRedirect
以前から横にだらだら延びた段落は醜いと思っていた。
このようなページを見つけた。C O U L D:固定か可変かそれが問題だ
早速 cssに下記の一行を追加した。
body { max-width: 50em }
emってな曖昧な単位に少し不安があるが Firefox1.5と IE7.0で同じように見えるので良しとする。
<pre>の中だからってタグが書けないわけじゃなし。インライン要素なら OKのはず。
C:\Documents and Settings\ds14050\デスクトップ>diff -u hikidoc.rb~ hikidoc.rb --- hikidoc.rb~ 2005-10-06 16:42:35.000000000 +0900 +++ hikidoc.rb 2006-05-30 06:34:32.265625000 +0900 @@ -142,8 +142,9 @@ end def restore_pre( text ) - ret = unescape_meta_char( text, true ) - ret = restore_plugin_block( ret, true ) + text = inline_parser( text ) +# ret = unescape_meta_char( text, true ) +# ret = restore_plugin_block( ret, true ) end ######################################################################
''test'' ''test'' ''test&'test\''' ''test&'test\'''
<p><em>test</em></p> <pre> <em>test</em> </pre> <p><em>test&'test'</em></p> <pre> <em>test&'test'</em> </pre>
20050929p02で引用の中で <pre>を使いたい言うてましたが、どうやら最初から可能だったご様子。
hikidoc.rbからの引用。
######################################################################
# blockquote
BLOCKQUOTE_RE = /^""[ \t]?/
BLOCKQUOTES_RE = /(#{BLOCKQUOTE_RE}.*\n?)+/
def parse_blockquote( text )
text.gsub( BLOCKQUOTES_RE ) do |str|
str.chomp!
str.gsub!( BLOCKQUOTE_RE, '' )
"\n<blockquote>\n%s\n</blockquote>\n\n" % block_parser(str)
end
end
###################################################################### # block parser ###################################################################### def block_parser( text ) ret = text ret = parse_plugin( ret ) ret = parse_pre( ret ) ret = parse_comment( ret ) ret = parse_header( ret ) ret = parse_hrules( ret ) ret = parse_list( ret ) ret = parse_definition( ret ) ret = parse_blockquote( ret ) ret = parse_table( ret ) ret = parse_paragraph( ret ) ret.lstrip end
block_parser()は見ての通り、整形済みテキスト(pre)、見出し、リスト、引用、テーブル、段落などを解釈する。
つまり、引用の中には (<pre>も含めて) block_parserが解釈するブロック要素が全て書ける。
何故今日まで気付かなかったのかというとコレ↓
BLOCKQUOTE_RE = /^""[ \t]?/
ドキュメントでは一般的に、「行頭に "" を付ければ引用になります」と書かれるけど、hikidoc.rbの実装では それに続く空白・タブ文字も引用を表す記号の一部として扱われている。行頭の空白は整形済みテキストを表すりっぱな Wiki記法の一部なのに。
そういうわけで
引用の中で整形済みテキストを書くときは 行頭を「"" 」(注:スペースは 2つ)で始めます。
現在のフォーマット:
'#{author} 【#{title}】 #{label.empty? ? publisher : label}'
20051108#p06のやり方では、『9S(3)』を使って「電撃文庫」を取得できるのは試したし、「ジャンプコミックス」と「角川スニーカー文庫」も多分取得できる。でもこれら一部大手を除くと、富士見ミステリーもファミ通文庫も、その他殆どのレーベルで取得できない。<ItemAttributes>拡張してよ、アマゾンさん。
最終更新: 2011-02-13T06:07+0900
引用文の表現力が上がってるのだけど、もうひとつ、引用の中で整形済みテキスト(pre)を使いたい。
すぐ上のセクション(↑)で、改行を維持するために引用の中のコード部分だけを<pre>で囲ってるのだけど、そのソースはちょっと汚い。(上から二行目と下から二行目で)直接HTMLを埋め込んでるから後々 tDiaryをXHTML化したりするのが難しくなる。HTML化はWikiパーサに全て任せたい。tdiary/hikidoc.rbを拡張して引用文中の<pre>が可能にならないものか。
""7×7の二次元配列aがあるとする。たとえば、以下のようなものである。
"" int a[7,7] ={
"" {1,1,1,1,1,1,1},
"" {1,0,0,0,0,0,1},
"" {1,0,1,1,1,0,1},
"" {1,0,0,0,1,1,1},
"" {1,0,0,1,0,0,1},
"" {1,0,0,0,1,0,1},
"" {1,1,1,1,1,1,1}
"" };
""いま、aを迷路と見立てる。a[x,y]が0の箇所は歩けて、1の箇所は歩けな
新しい Wikiスタイル(HikiDoc)を使いたいがために。
引用の中に
見出しとか
孫引用とか
- リストを挿入してみたりできる
でも多分 http://vvvvvv.sakura.ne.jp/ds14050/diary/ で日記にアクセスすると上の引用部分が下のように見えてるはず。(実際にはキャッシュが働くので新旧tDiaryのどっちが最後にキャッシュを作ったかによる)
引用の中に
!見出しとか
""孫引用とか
*リストを挿入してみたりできる
http://vvvvvv.sakura.ne.jp/ds14050/diary/ に加えた変更を http://vvvvvv.sakura.ne.jp/ds14050/diary-test/ に写し終えたら diary-test/ を diary/ にリネーム。
同カテゴリの日記をリスト表示するページでメインのHTMLを出力してるのは category.rbの中の category_list_sections()。こいつとか Category::Info#make_anchor()はパラメータとして複数のカテゴリを与えられることを想定している。けれどこの 2つのメソッドは「@mode == 'categoryview'」なページの中でしか使えない。
どういうことか。複数のカテゴリ名がパラメータとして与えられればそれらを全てリスト表示できるのに、そういうパラメータを持ったリンクを作る手段がなかった。(Category::Info#make_anchor()にはその可能性があったけど使える場所がカテゴリページ内に限られるので外からの入り口にはなれない)
カテゴリページへのリンクを作るのにはもう一つ方法があって、それが同じ category.rb内にある category_anchor()。これは Category::Info#make_anchor()とは対照的にカテゴリページの外でしか使えない*。category_anchor()を複数カテゴリ対応にすれば晴れて入り口のできあがり。
* 「カテゴリページ」を表す「class TDiaryCategoryView < TDiaryBase」には @dateが存在しないから、Pluginオブジェクトの @dateも nullになって、category_anchor()が @dateを参照するところでエラーになる 。
細かいことは以前の日記に書いてあるので、ここではビャッとソースを引用。
# index_list.rb
#
# 「最新」「月」表示に対応した目次を表示。
# recent_listやtitle_listと違い日付のリンク先は日別表示でなくページ内。
# その為に、diary.rhtmlをいじって日付にアンカーを付ける必要がある。
# 骨格にrecent_list.rbを使用。
# [2005-06-15] tdiary-2.1.1 N日表示対応
# [2005-04-20] 月表示では昇順に。
def index_list(date_format = nil, show_title = true)
if(@mode == 'latest')
limit = @conf.latest_limit;
elsif(@mode == 'month')
limit = 31;
else
return '';
end
date_format ||= @date_format;
latest_start_ymd = @date.strftime('%Y%m%d');
result = %Q[<ul class="index-list">\n];
b = lambda {|ymd|
next if(@mode == 'latest' && latest_start_ymd < ymd);
break if(limit <= 0);
diary = @diaries[ymd];
next unless(diary.visible?);
result << %Q[\t<li><a href="##{ymd}">#{diary.date.strftime(date_format)}</a>];
if(show_title && diary.title)
result << %Q[ #{diary.title}];
end
result << %Q[\n\t\t<ul class="index-list-item">\n];
i = 1;
if(!@plugin_files.grep(/\/category.rb$/).empty? && diary.categorizable?)
diary.each_section{|section|
result << "\t\t<li>";
result << section.categories.collect{|c| category_anchor("#{c}")}.join;
result << ' '+section.stripped_subtitle_to_html if(section.stripped_subtitle);
result << "</li>\n";
i += 1;
}
else
diary.each_section{|section|
if(section.subtitle)
result << %Q[\t\t<li>#{section.subtitle_to_html}</li>\n];
end
i += 1;
}
end
result << "\t\t</ul>\n\t</li>\n";
limit -= 1;
}
begin
@diaries.keys.sort.send( (@mode=='latest' ? :reverse_each : :each), &b);
rescue LocalJumpError # <- break
# Procオブジェクトで breakは使えないのだろうけど
# それをブロックとして渡してるんやからエラーにせんでもええやん。> ruby-1.8.2
end
result << "<ul>";
return apply_plugin(result);
end