| blib/lib/Text/Livedoor/Wiki/Plugin/Block/Toggle.pm | |||
|---|---|---|---|
| Criterion | Covered | Total | % |
| statement | 81 | 81 | 100.0 |
| branch | 24 | 24 | 100.0 |
| condition | 21 | 25 | 84.0 |
| subroutine | 6 | 6 | 100.0 |
| pod | 3 | 3 | 100.0 |
| total | 135 | 139 | 97.1 |
| line | stmt | bran | cond | sub | pod | time | code |
|---|---|---|---|---|---|---|---|
| 1 | package Text::Livedoor::Wiki::Plugin::Block::Toggle; | ||||||
| 2 | |||||||
| 3 | 5 | 5 | 31 | use warnings; | |||
| 5 | 12 | ||||||
| 5 | 151 | ||||||
| 4 | 5 | 5 | 28 | use strict; | |||
| 5 | 9 | ||||||
| 5 | 173 | ||||||
| 5 | 5 | 5 | 27 | use base qw(Text::Livedoor::Wiki::Plugin::Block); | |||
| 5 | 11 | ||||||
| 5 | 2434 | ||||||
| 6 | |||||||
| 7 | __PACKAGE__->trigger({ start=> '^\[(\+|-)\]' , end => '^\[END\]$' }); | ||||||
| 8 | |||||||
| 9 | sub check { | ||||||
| 10 | 245 | 245 | 1 | 383 | my $class = shift; | ||
| 11 | 245 | 338 | my $line = shift; | ||||
| 12 | 245 | 323 | my $args = shift; | ||||
| 13 | 245 | 395 | my $on_next = $args->{on_next}; | ||||
| 14 | 245 | 446 | my $id = $args->{id}; | ||||
| 15 | 245 | 332 | my $inline = $args->{inline}; | ||||
| 16 | 245 | 329 | my $scratchpad = $Text::Livedoor::Wiki::scratchpad; | ||||
| 17 | 245 | 301 | my $row; | ||||
| 18 | my $option_str; | ||||||
| 19 | 245 | 495 | my $processing = $scratchpad->{block}{$id}{processing}; | ||||
| 20 | |||||||
| 21 | |||||||
| 22 | # rule | ||||||
| 23 | # 1. [+]~ or [-]~ | ||||||
| 24 | # 2. not starting. | ||||||
| 25 | # 3. this line | ||||||
| 26 | # 4. no child found | ||||||
| 27 | 245 | 100 | 100 | 2459 | if ((my ( $mark ) = $line =~ /^\[(\+|-)\]/) && !$processing && !$on_next && !$class->get_child($id) ){ | ||
| 100 | 66 | ||||||
| 100 | 66 | ||||||
| 100 | 100 | ||||||
| 100 | |||||||
| 66 | |||||||
| 100 | |||||||
| 28 | #XXX | ||||||
| 29 | 22 | 67 | $Text::Livedoor::Wiki::scratchpad->{skip_ajust_block_break} = '1'; | ||||
| 30 | |||||||
| 31 | 22 | 70 | $scratchpad->{block}{$id}{processing} = 1 ; | ||||
| 32 | 22 | 100 | 72 | my $toggle = $mark eq '+' ? 'close' : 'open'; | |||
| 33 | |||||||
| 34 | 22 | 111 | my ( $dummy , $title ) = $line =~ /^\[(\+|-)\](.+)/; | ||||
| 35 | 22 | 100 | 67 | $title = '' unless defined $title; | |||
| 36 | 22 | 163 | return { id => $id , title => $title , toggle => $toggle }; | ||||
| 37 | } | ||||||
| 38 | # end box | ||||||
| 39 | elsif( !$on_next && $class->trigger_check($id,$line) && $line =~ /^\[END\]$/ && $processing ) { | ||||||
| 40 | 13 | 38 | $scratchpad->{block}{$id}{processing} = 0; | ||||
| 41 | 13 | 84 | return { line => "\n" }; | ||||
| 42 | } | ||||||
| 43 | # finnalize | ||||||
| 44 | elsif( $on_next && !$processing ) { | ||||||
| 45 | 2 | 16 | return; | ||||
| 46 | } | ||||||
| 47 | # processing | ||||||
| 48 | elsif( $processing ) { | ||||||
| 49 | 123 | 728 | return { line => $line }; | ||||
| 50 | } | ||||||
| 51 | 85 | 504 | return; | ||||
| 52 | |||||||
| 53 | } | ||||||
| 54 | |||||||
| 55 | sub get { | ||||||
| 56 | 15 | 15 | 1 | 28 | my $class = shift; | ||
| 57 | 15 | 29 | my $block = shift; | ||||
| 58 | 15 | 17 | my $inline = shift; | ||||
| 59 | 15 | 24 | my $items = shift; | ||||
| 60 | 15 | 37 | my $meta = shift @{$items}; | ||||
| 15 | 5338 | ||||||
| 61 | 15 | 47 | my $box = $meta->{box}; | ||||
| 62 | 15 | 42 | my $class_name = $meta->{class_name}; | ||||
| 63 | 15 | 29 | my $id = $meta->{id}; | ||||
| 64 | 15 | 30 | my $title = $meta->{title}; | ||||
| 65 | 15 | 83 | $title = $inline->parse($title); | ||||
| 66 | |||||||
| 67 | # END LINE | ||||||
| 68 | 15 | 100 | 54 | if ( scalar @$items ) { # in case there is no line in $items | |||
| 69 | 12 | 100 | 49 | pop @$items if $items->[-1]{line} eq "\n"; | |||
| 70 | } | ||||||
| 71 | |||||||
| 72 | 15 | 35 | my $html = ''; | ||||
| 73 | 15 | 85 | $html .= $_->{line} . "\n" for @$items; | ||||
| 74 | 15 | 79 | $html =~ s/\n$//; | ||||
| 75 | 15 | 100 | 78 | my $save_skip_catalog = $Text::Livedoor::Wiki::opts->{skip_catalog} || 0 ; | |||
| 76 | 15 | 42 | $Text::Livedoor::Wiki::opts->{skip_catalog} = 1; | ||||
| 77 | 15 | 86 | $html = $block->parse( $html , 1) ; | ||||
| 78 | 15 | 40 | $Text::Livedoor::Wiki::opts->{skip_catalog} = $save_skip_catalog ; | ||||
| 79 | |||||||
| 80 | 15 | 95 | my $spacer_image = $class->opts->{storage} . '/images/common/spacer.gif'; | ||||
| 81 | |||||||
| 82 | |||||||
| 83 | #return qq| |
||||||
| 84 | 15 | 40 | my $id_inside = "$id-inside"; | ||||
| 85 | 15 | 31 | my $id_label = "$id-label"; | ||||
| 86 | 15 | 100 | 92 | my $label_class = $meta->{toggle} eq 'open' ? 'toggle-link-close': 'toggle-link-open'; | |||
| 87 | 15 | 74 | my $js = qq|if( document.getElementById('$id_inside').style.display =='none' ) { document.getElementById('$id_inside').style.display ='block' ; document.getElementById('$id_label').className = 'toggle-link-close'; } else { document.getElementById('$id_inside').style.display ='none';document.getElementById('$id_label').className = 'toggle-link-open'; } ;|; | ||||
| 88 | 15 | 193 | my $button = qq|\n|; | ||||
| 89 | |||||||
| 90 | 15 | 100 | 39 | if( $meta->{toggle} eq 'open' ){ | |||
| 91 | 4 | 19 | $html= qq|$button \n$html \n|; |
||||
| 92 | } | ||||||
| 93 | else { | ||||||
| 94 | 11 | 73 | $html= qq|$button\n|; | ||||
| 95 | } | ||||||
| 96 | |||||||
| 97 | 15 | 144 | return qq| \n$html \n|; |
||||
| 98 | } | ||||||
| 99 | |||||||
| 100 | sub mobile { | ||||||
| 101 | 7 | 7 | 1 | 13 | my $class = shift; | ||
| 102 | 7 | 11 | my $block = shift; | ||||
| 103 | 7 | 10 | my $inline = shift; | ||||
| 104 | 7 | 10 | my $items = shift; | ||||
| 105 | 7 | 12 | my $meta = shift @{$items}; | ||||
| 7 | 11 | ||||||
| 106 | 7 | 17 | my $box = $meta->{box}; | ||||
| 107 | 7 | 12 | my $class_name = $meta->{class_name}; | ||||
| 108 | 7 | 12 | my $id = $meta->{id}; | ||||
| 109 | 7 | 13 | my $title = $meta->{title}; | ||||
| 110 | 7 | 33 | $title = $inline->parse($title); | ||||
| 111 | |||||||
| 112 | # END LINE | ||||||
| 113 | 7 | 100 | 22 | if ( scalar @$items ) { | |||
| 114 | 5 | 100 | 22 | pop @$items if $items->[-1]{line} eq "\n"; | |||
| 115 | } | ||||||
| 116 | |||||||
| 117 | 7 | 11 | my $html = ''; | ||||
| 118 | 7 | 29 | $html .= $_->{line} . "\n" for @$items; | ||||
| 119 | 7 | 22 | $html =~ s/\n$//; | ||||
| 120 | 7 | 50 | 37 | my $save_skip_catalog = $Text::Livedoor::Wiki::opts->{skip_catalog} || 0 ; | |||
| 121 | 7 | 14 | $Text::Livedoor::Wiki::opts->{skip_catalog} = 1; | ||||
| 122 | 7 | 33 | $html = $block->parse( $html , 1) ; | ||||
| 123 | 7 | 15 | $Text::Livedoor::Wiki::opts->{skip_catalog} = $save_skip_catalog ; | ||||
| 124 | |||||||
| 125 | 7 | 47 | return qq| \n$title \n|; \n$html |
||||
| 126 | } | ||||||
| 127 | |||||||
| 128 | 1; | ||||||
| 129 | |||||||
| 130 | =head1 NAME | ||||||
| 131 | |||||||
| 132 | Text::Livedoor::Wiki::Plugin::Block::Toggle - Toggle Block Plugin | ||||||
| 133 | |||||||
| 134 | =head1 DESCRIPTION | ||||||
| 135 | |||||||
| 136 | you can open and close block with this. | ||||||
| 137 | |||||||
| 138 | =head1 SYNOPSIS | ||||||
| 139 | |||||||
| 140 | [+]''you can open me!'' | ||||||
| 141 | - item | ||||||
| 142 | - item | ||||||
| 143 | [END] | ||||||
| 144 | [-]''you can close me!'' | ||||||
| 145 | * title | ||||||
| 146 | hoge hoge | ||||||
| 147 | hoge hoge | ||||||
| 148 | [END] | ||||||
| 149 | |||||||
| 150 | =head1 FUNCTION | ||||||
| 151 | |||||||
| 152 | =head2 check | ||||||
| 153 | |||||||
| 154 | =head2 get | ||||||
| 155 | |||||||
| 156 | =head2 mobile | ||||||
| 157 | |||||||
| 158 | =head1 AUTHOR | ||||||
| 159 | |||||||
| 160 | polocky | ||||||
| 161 | |||||||
| 162 | =cut |