X-Git-Url: http://git.osdn.net/view?p=fswiki%2Fsandbox.git;a=blobdiff_plain;f=takezoe%2Fplugin%2Fbook%2FSLink.pm;fp=takezoe%2Fplugin%2Fbook%2FSLink.pm;h=495766e46898ef42f1076f90812b9125e13c91f5;hp=0000000000000000000000000000000000000000;hb=7ad484083175ee38b3118ac2f445e8d3c48f927d;hpb=4a3818ba405b07e5a72108e70c5e2b404b553533 diff --git a/takezoe/plugin/book/SLink.pm b/takezoe/plugin/book/SLink.pm new file mode 100644 index 0000000..495766e --- /dev/null +++ b/takezoe/plugin/book/SLink.pm @@ -0,0 +1,101 @@ +################################################################################ +# +#

¸«½Ð¤·¤ä¿Þɽ¤Ø¤Î¥ê¥ó¥¯¤ò½ÐÎϤ¹¤ë¤¿¤á¤Î¥¤¥ó¥é¥¤¥ó¥×¥é¥°¥¤¥ó¤Ç¤¹¡£

+#

°ú¿ô¤Ë¤Ïtitle1¡Átitle3¥×¥é¥°¥¤¥ó¤äcaption¥×¥é¥°¥¤¥ó¤Çµ­½Ò¤·¤¿»²¾ÈÍѤΥé¥Ù¥ë¤ò»ØÄꤷ¤Þ¤¹¡£

+#
+# !!!{{title1 installation}}¥¤¥ó¥¹¥È¡¼¥ëÊýË¡
+# ...
+# ¥¤¥ó¥¹¥È¡¼¥ëÊýË¡¤Ë¤Ä¤¤¤Æ¤Ï{{slink installation}}¤ò»²¾È¤·¤Æ¤¯¤À¤µ¤¤¡£
+# 
+#

Âè2°ú¿ô¤Ç¥Ú¡¼¥¸¤ò»ØÄꤹ¤ë¤³¤È¤Ç¡¢ÊÌ¥Ú¡¼¥¸¤Î¸«½Ð¤·¤ä¿Þɽ¤ò»²¾È¤¹¤ë¤³¤È¤â¤Ç¤­¤Þ¤¹¡£

+#
+# ¥¤¥ó¥¹¥È¡¼¥ëÊýË¡¤Ë¤Ä¤¤¤Æ¤Ï{{slink installation,Chapter1}}¤ò»²¾È¤·¤Æ¤¯¤À¤µ¤¤¡£
+# 
+# +################################################################################ +package plugin::book::SLink; +#============================================================================== +# ¥³¥ó¥¹¥È¥é¥¯¥¿ +#============================================================================== +sub new { + my $class = shift; + my $self = {}; + my $self->{cache} = {}; + return bless $self,$class; +} + +#============================================================================== +# ¥¤¥ó¥é¥¤¥ó¥á¥½¥Ã¥É +#============================================================================== +sub inline { + my $self = shift; + my $wiki = shift; + my $anchor = shift; + my $page = shift; + + $page = $wiki->get_CGI->param('page') unless $page; + my $source = $wiki->get_page($page); + + unless(defined($self->{cache}->{$page})){ + $self->{cache}->{$page} = {}; + my $source = $wiki->get_page($page); + + my $text = ''; + + my @lines = split(/\n/,$wiki->get_page($page)); + my $chapter = ''; + my $count = {}; + my $title1Count = 0; + my $title2Count = 0; + my $title3Count = 0; + + # TODO {{pre}}¥×¥é¥°¥¤¥óÆâ¤Îµ­½Ò¤ÏÈô¤Ð¤µ¤Ê¤¤¤È¥À¥á¡ª¡ª¥Ñ¡¼¥µ¤òºî¤é¤Ê¤¤¤È¥À¥á¤Ã¤Ý¤¤¡© + foreach my $line (@lines){ + if($line =~ /^{{(chapter.+}})$/){ + my $plugin = $wiki->parse_inline_plugin($1); + $chapter = $plugin->{'args'}->[0]; + $title1Count = 0; + $title2Count = 0; + $title3Count = 0; + foreach my $key (keys(%$count)){ + $count->{$key} = 0; + } + } elsif($line =~ /^!!!{{(title1.+}})(.+)$/){ + my $plugin = $wiki->parse_inline_plugin($1); + $title1Count++; + $title2Count = 0; + $title3Count = 0; + $text= $chapter.'-'.$title1Count; + $self->{cache}->{$page}->{$plugin->{'args'}->[0]} = $text; + + } elsif($line =~ /^!!{{(title2.+}})$/){ + my $plugin = $wiki->parse_inline_plugin($1); + $title2Count++; + $title3Count = 0; + $text= $chapter.'-'.$title1Count.'-'.$title2Count; + $self->{cache}->{$page}->{$plugin->{'args'}->[0]} = $text; + + } elsif($line =~ /^!{{(title3.+}})$/){ + my $plugin = $wiki->parse_inline_plugin($1); + $title3Count++; + $text= $chapter.'-'.$title1Count.'-'.$title2Count.'-'.$title3Count; + $self->{cache}->{$page}->{$plugin->{'args'}->[0]} = $text; + + } elsif($line =~ /^{{(caption.+}})$/){ + my $plugin = $wiki->parse_inline_plugin($1); + my $type = $plugin->{'args'}->[0]; + $count->{$type}++; + $text = $type.$chapter.'-'.$count->{$type}; + $self->{cache}->{$page}->{$plugin->{'args'}->[2]} = $text; + } + } + } + if(defined($self->{cache}->{$page}->{$anchor})){ + my $text = $self->{cache}->{$page}->{$anchor}; + return ''.Util::escapeHTML($text).''; + } else { + return '»²¾ÈÀ褬¸«¤Ä¤«¤ê¤Þ¤»¤ó¡ª'; + } +} + +1;