Template::Plugin::WikiFormat - TT wrapper for Text::WikiFormat


Template-Plugin-WikiFormat documentation Contained in the Template-Plugin-WikiFormat distribution.

Index


Code Index:

NAME

Top

Template::Plugin::WikiFormat - TT wrapper for Text::WikiFormat

SYNOPSIS

Top

  [% USE WikiFormat %]
  [% FILTER $WikiFormat %]
  ...
  [% END %]

DESCRIPTION

Top

This is a plugin used for wiki rendering inside Template Toolkit.

Parameters may be passed in through the USE directive, e.g.

  [% USE WikiFormat prefix = "http://www.mysite.com/?page=" %]

This provides the 4 options supported by Text::WikiFormat, i.e. prefix, extended, implicit_links, absolute_links, and the special option global_replace, which takes an array of arrays of from and to strings. The output from Text::WikiFormat is post processed by replacing each from regexp with the to regexp. Anything else passed in is interpreted as a tag (see the Gory Details section).

filter

Accepts the wiki text to be rendered, and context. The tags and options are passed in through the context. See Template::Plugin::Filter.

SEE ALSO

Top

Text::WikiFormat

BUGS, PATCHES & FIXES

Top

There are no known bugs at the time of this release. However, if you spot a bug or are experiencing difficulties that are not explained within the POD documentation, please send an email to barbie@cpan.org or submit a bug to the RT system (see link below). However, it would help greatly if you are able to pinpoint problems or even supply a patch.

http://rt.cpan.org/Public/Dist/Display.html?Name=Template-Plugin-WikiFormat

Fixes are dependant upon their severity and my availablity. Should a fix not be forthcoming, please feel free to (politely) remind me.

AUTHOR

Top

  Original Author: Ivor Williams (RIP)          2008-2009
  Current Maintainer: Barbie <barbie@cpan.org>  2009

COPYRIGHT AND LICENSE

Top


Template-Plugin-WikiFormat documentation Contained in the Template-Plugin-WikiFormat distribution.
package Template::Plugin::WikiFormat;
use strict;
use warnings;

our $VERSION = '0.04';

#----------------------------------------------------------------------------

#----------------------------------------------------------------------------

#############################################################################
#Library Modules															#
#############################################################################

use base 'Template::Plugin::Filter';
use Text::WikiFormat;

#----------------------------------------------------------------------------

#############################################################################
#Interface Methods   														#
#############################################################################

sub filter {
    my ( $self, $text ) = @_;

    my $conf = $self->{_CONFIG};
    $conf ||= {};
    my %tags = %$conf;
    my %opts;
    my %default = (
        prefix         => '',
        extended       => 0,
        implicit_links => 1,
        absolute_links => 0,
    );
    for ( keys %default ) {
        $opts{$_} = $tags{$_} || $default{$_};
        delete $tags{$_};
    }
    my $replace;
    if ( exists $tags{global_replace} ) {
        $replace = $tags{global_replace};
        delete $tags{global_replace};
    }

    my $output = Text::WikiFormat::format( $text, \%tags, \%opts );

    for my $rep (@$replace) {
        my ( $from, $to ) = @$rep;
        eval("\$output =~ s($from)($to)sg");
    }
    return $output;
}

1;

__END__

#----------------------------------------------------------------------------