OSDN Git Service

コラムの一覧を表示するプラグインを追加。
authortakezoe <takezoe@871d6764-1e22-0410-b313-a55050885396>
Fri, 30 Dec 2011 20:03:47 +0000 (20:03 +0000)
committertakezoe <takezoe@871d6764-1e22-0410-b313-a55050885396>
Fri, 30 Dec 2011 20:03:47 +0000 (20:03 +0000)
takezoe/plugin/book/ColumnList.pm [new file with mode: 0644]
takezoe/plugin/book/Install.pm

diff --git a/takezoe/plugin/book/ColumnList.pm b/takezoe/plugin/book/ColumnList.pm
new file mode 100644 (file)
index 0000000..83c45fc
--- /dev/null
@@ -0,0 +1,95 @@
+################################################################################
+#
+# <p>column¥×¥é¥°¥¤¥ó¤Çµ­½Ò¤·¤¿¥³¥é¥à¤Î°ìÍ÷¤ò½ÐÎϤ·¤Þ¤¹¡£</p>
+# <pre>
+# {{column}}
+# </pre>
+# <p>
+#   ¥Ú¡¼¥¸Ì¾¤ò»ØÄꤹ¤ë¤³¤È¤Ç¾¤Î¥Ú¡¼¥¸¤Î¥³¥é¥à°ìÍ÷¤ò½ÐÎϤ¹¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£
+#   ¥Ú¡¼¥¸Ì¾¤ÏÊ£¿ô»ØÄꤹ¤ë¤³¤È¤â¤Ç¤­¤Þ¤¹¡£
+# </p>
+# <pre>
+# {{toc ¥Ú¡¼¥¸Ì¾1,¥Ú¡¼¥¸Ì¾2,...}}
+# </pre>
+#
+################################################################################
+package plugin::book::ColumnList;
+#==============================================================================
+# ¥³¥ó¥¹¥È¥é¥¯¥¿
+#==============================================================================
+sub new {
+       my $class = shift;
+       my $self = {};
+       return bless $self,$class;
+}
+
+#==============================================================================
+# ¥Ñ¥é¥°¥é¥Õ¥á¥½¥Ã¥É
+#==============================================================================
+sub paragraph {
+       my $self  = shift;
+       my $wiki  = shift;
+       my @pages = @_;
+
+       my $parser = plugin::book::ColumnListParser->new($wiki);
+       if($#pages == -1){
+               my $page = $wiki->get_CGI->param('page');
+               $parser->parse('', $wiki->get_page($page));
+       } else {
+               foreach my $page (@pages){
+                       $parser->parse($page, $wiki->get_page($page));
+               }
+       }
+       
+       return $parser->columnlist;
+}
+
+#==============================================================================
+# ¥³¥é¥àÃê½ÐÍѤΥѡ¼¥µ
+#==============================================================================
+package plugin::book::ColumnListParser;
+use Wiki::HTMLParser;
+
+@ISA = qw(Wiki::HTMLParser);
+
+sub new {
+       my $class = shift;
+       my $self  = Wiki::HTMLParser->new(shift);
+       $self->{columnlist} = '';
+       return bless $self,$class;
+}
+
+sub parse {
+       my $self   = shift;
+       my $page   = shift;
+       my $source = shift;
+       $self->{pagename} = $page;
+       $self->{column} = 0;
+       $self->SUPER::parse($source);
+}
+sub columnlist {
+       my $self = shift;
+       if($self->{columnlist} eq ''){
+               return "<p>¥³¥é¥à¤Ï¤¢¤ê¤Þ¤»¤ó</p>";
+       } else {
+               return "<ul>".$self->{columnlist}."</ul>";
+       }
+}
+
+sub l_plugin{
+       my $self   = shift;
+       my $plugin = shift;
+       
+       if($plugin->{'command'} eq 'column'){
+               $self->{column}++;
+               $self->{columnlist} .= "<li>";
+               if($self->{pagename} ne ''){
+                       $self->{columnlist} .= "¡Ê".Util::escapeHTML($self->{pagename})."¡Ë";
+               }
+               $self->{columnlist} .= "<a href=\"?page=".Util::url_encode($self->{pagename}).
+                       "#c".$self->{column}."\">".Util::escapeHTML($plugin->{'args'}->[1])."</a></li>";
+       }
+       return undef;
+}
+
+1;
index afa54bb..608a9f8 100644 (file)
@@ -22,6 +22,7 @@ sub install {
        $wiki->add_inline_plugin("code" ,"plugin::book::Code" ,"HTML");
        
        $wiki->add_block_plugin("column" ,"plugin::book::Column" ,"HTML");
+       $wiki->add_paragraph_plugin("columnlist", "plugin::book::ColumnList", "HTML");
        $wiki->add_block_plugin("note" ,"plugin::book::Note" ,"HTML");
        $wiki->add_block_plugin("box" ,"plugin::book::Box" ,"HTML");