package App::ZofCMS::Plugin::TOC;
use warnings;
use strict;
our $VERSION = '0.0103';
use HTML::Template;
sub new { return bless {}, shift; }
sub process {
my ( $self, $template, $query, $config ) = @_;
return
unless $template->{page_toc};
my $html = <<"END_HTML";
END_HTML
my $t = HTML::Template->new_scalar_ref( \$html );
$t->param(
toc => [
map +{
url => $_->[0],
name => $_->[1],
class => $_->[2],
}, map $self->_make_entry, @{ delete $template->{page_toc} },
],
);
$template->{t}{page_toc} = $t->output;
return;
}
sub _make_entry {
if ( not ref or @$_ == 1 ) {
$_ = [ $_ ] unless ref;
my $name = $_->[0];
$name =~ s/^#//;
$name = ucfirst $name;
$name =~ s/[-_](.)/ \u$1/g;
$_->[1] = $name;
}
return $_;
}
1;
__END__
=head1 NAME
App::ZofCMS::Plugin::TOC - Table of Contents building plugin for ZofCMS
=head1 SYNOPSIS
In your ZofCMS template, or in your main config file (under
C or C):
page_toc => [
qw/
#overview
#beginning
#something_else
#conclusion
/,
],
plugins => [ qw/TOC/ ],
# OR
page_toc => [
[ qw/#overview Overview class_overview/ ],
[ qw/#beginning Beginning/ ],
qw/
#something_else
#conclusion
/,
],
plugins => [ qw/TOC/ ],
In your L template:
=head1 DESCRIPTION
This plugin provides means to generate "table of contents" lists. For
example, the second example in the SYNOPSYS would replace
C<< >> with this:
=head1 HOW TO USE
Aside from sticking C in your arrayref of plugins in your
ZofCMS template (C<< plugins => [ qw/TOC/ ] >>) and placing
C<< >> in your L template
you also need to create
a C first level key in ZofCMS template. That key's value is an
arrayref each element of which can be either an arrayref or a scalar.
B. The element which is an arrayref can contain either one, two or
three elements itself. Which represent the following:
=head2 arrayref which contains only one element
page_toc => [
'#foo',
'#bar-baz',
],
# OR
page_toc => [
[ '#foo' ],
[ '#bar-baz' ],
],
The first (and only) element will be used in C attribute
of the generated link. The text of the link will be determined
automatically, in particular the C<'#'> will be removed, first letter
will be capitalized and any dashes C<'-'> or underscores C<'_'> will
be replaced by a space with the letter following them capitalized. The
example above will place the following code in
C<< >>:
=head2 arrayref which contains two elements
page_toc => [
[ '#foo', 'Foos Lots of Foos!' ],
[ '#bar-baz', 'Bar-baz' ],
],
The first element will be used in C attribute
of the generated link. The second element will be used as text for the
link. The example above will generate the following code:
=head2 arrayref which contains three elements
page_toc => [
[ '#foo', 'Foos Lots of Foos!', 'foos' ],
[ '#bar-baz', 'Bar-baz', 'bars' ],
],
The first element will be used in C attribute
of the generated link. The second element will be used as text for the
link. The third elemenet will be used to create a C attribute
on the C<< >> element for the corresponding entry.
The example above will generate the following code:
Note: the class of the C<< >> element is always C
=head1 AUTHOR
Zoffix Znet, C<< >>
(L, L)
=head1 BUGS
Please report any bugs or feature requests to C, or through
the web interface at L. I will be notified, and then you'll
automatically be notified of progress on your bug as I make changes.
=head1 SUPPORT
You can find documentation for this module with the perldoc command.
perldoc App::ZofCMS::Plugin::TOC
You can also look for information at:
=over 4
=item * RT: CPAN's request tracker
L
=item * AnnoCPAN: Annotated CPAN documentation
L
=item * CPAN Ratings
L
=item * Search CPAN
L
=back
=head1 COPYRIGHT & LICENSE
Copyright 2008 Zoffix Znet, all rights reserved.
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
=cut