Changeset 969

Show
Ignore:
Timestamp:
08/20/08 03:24:22 (3 months ago)
Author:
breese
Message:

adding lolcats template tag modifier example

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/examples/Example2/plugins/Example/config.yaml

    r967 r969  
    66version: 1.0 
    77tags: 
    8     function: 
    9         'SaySomething': $Example::Example::Plugin::SaySomething 
    10         'SayWhatever': $Example::Example::Plugin::SayWhatever 
    11     block: 
    12         'LoopTenTimes': $Example::Example::Plugin::LoopTenTimes 
    13         'IfOdd?': $Example::Example::Plugin::IfOdd 
     8    tags: 
     9        modifier: 
     10            'lolcats': $Example::Example::Plugin::lolcats 
    1411 
  • trunk/examples/Example2/plugins/Example/lib/Example/Plugin.pm

    r967 r969  
    99 
    1010############################################################# 
    11 =head2 SaySomething 
     11=head2 lolcats 
    1212 
    13 This tag outputs the word "Something." 
     13A template tag modifer that appends "LOL - CAN I HAZ" to the  
     14contents of the associated tag. 
    1415 
    1516=cut 
    16 sub SaySomething { 
    17     my ($ctx, $args) = @_; 
    18     return "Something""; 
    19 
    20  
    21 ############################################################# 
    22 =head2 SayWhatever 
    23  
    24 This tag takes as input a string that is then echo'ed back. 
    25  
    26 =over 4 
    27  
    28 =item * say 
    29  
    30 Whatever you want to tag to echo. 
    31  
    32 =back  
    33  
    34 B<Example:> 
    35  
    36     <mt:SayWhatever say="Hello World!"> 
    37  
    38 =cut 
    39 sub SayWhatever { 
    40     my ($ctx, $args) = @_; 
    41     # What the person passed in through the argument 'say' 
    42     my $input = $args->{'say'}; 
    43     return $input; 
    44 
    45  
    46 sub LoopTenTimes { 
    47     my ($ctx, $args, $cond) = @_; 
    48     my $out = ""; 
    49     my $builder = $ctx->stash('builder'); 
    50     my $tokens = $ctx->stash('tokens'); 
    51     for (my $i = 1; $i <= 10; $i++) { 
    52         $ctx->stash("current_loop_number",$i); 
    53         $out .= "$i - " . $builder->build($ctx,$tokens,$cond); 
    54     } 
    55     return $out; 
    56 
    57  
    58 sub IfOdd { 
    59     my ($ctx, $args, $cond) = @_; 
    60     my $num = $ctx->stash('current_loop_number'); 
    61     if ($num % 2 == 0) { 
    62         return 0; 
    63     } else { 
    64         return 1; 
    65     } 
     17sub lolcats { 
     18    my ($str, $val, $ctx) = @_; 
     19    return "LOL - CAN I HAZ $str"; 
    6620} 
    6721