2003-09-29 (Mon) [長年日記]
▲ include プラグイン
VikiWiki のimport プラグインが羨ましくなり、himi さんからの要望もあったので Hiki 用の include プラグインをでっちあげてみた。
# $Id $ # Copyright (C) 2003 Koichiro Ohba <koichiro@meadowy.org> def include( page ) @content = '' return '' unless @db.exist?( page ) include_content( page ) @content end def include_content( page ) include_page_backup( page ) parser = Parser::new tokens = parser.parse( @db.load( page ) ) formatter = HikiFormatter::new( tokens, @db, @db.plugin ) @content << formatter.apply_tdiary_theme_include(formatter.to_s).sanitize include_page_restore end def include_page_backup( page ) @tmp_page = @page @page = page end def include_page_restore @page = @tmp_page end
hiki/hiki_formatter.rb への修正。
diff -c -r1.1.2.2 hiki_formatter.rb
*** hiki/hiki_formatter.rb 31 May 2003 10:13:01 -0000 1.1.2.2
--- hiki/hiki_formatter.rb 22 Oct 2003 15:16:02 -0000
***************
*** 15,20 ****
--- 15,42 ----
if /(.*?)(<h2>.+)/ =~ line
section << $1
if section.size > 0 or first_f
+ tdiary_html << tdiary_day(title, section)
+ section = ''
+ end
+ first_f = true
+ title = $2
+ else
+ section << line
+ end
+ end
+ tdiary_html << tdiary_day(title, section)
+ end
+
+ def apply_tdiary_theme_include(html)
+ section = ''
+ title = ''
+ tdiary_html = ''
+ first_f = false
+
+ html.each do |line|
+ if /(.*?)(<h2>.+)/ =~ line
+ section << $1
+ if section.size > 0 or first_f
tdiary_html << tdiary_section(title, section)
section = ''
end
***************
*** 30,42 ****
private
def tdiary_section(title, section)
<<"EOS"
- <div class="day">
#{title}
<div class="body">
<div class="section">
#{section}
</div>
</div>
</div>
EOS
end
--- 52,70 ----
private
def tdiary_section(title, section)
<<"EOS"
#{title}
<div class="body">
<div class="section">
#{section}
</div>
</div>
+ EOS
+ end
+
+ def tdiary_day(title, section)
+ <<"EOS"
+ <div class="day">
+ #{tdiary_section(title, section)}
</div>
EOS
end
使い方は埋め込みたい場所でページ名を指定する。
{{include('SandBox')}}
実行例 about:SandBox
セクションが分かれるようにしたほうがよいのかな。 <div class="day"> が入れ子にならないように対処。
あとこのままでは include 先のプラグインが元ページの情報で実行されてしまうために BBS プラグインなどが正常に動かない。include 先に合わせて Plugin クラスを初期化するとかしないとイカンかも。安直に対応。
[ツッコミを入れる]





