| App-ZofCMS-Plugin-TOC documentation | Contained in the App-ZofCMS-Plugin-TOC distribution. |
App::ZofCMS::Plugin::TOC - Table of Contents building plugin for ZofCMS
In your ZofCMS template, or in your main config file (under
template_defaults or dir_defaults):
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 HTML::Template template:
<tmpl_var name="page_toc">
This plugin provides means to generate "table of contents" lists. For
example, the second example in the SYNOPSYS would replace
<tmpl_var name="page_toc"> with this:
<ul class="page_toc">
<li class="class_overview"><a href="#overview">Overview</a></li>
<li><a href="#beginning">Beginning</a></li>
<li><a href="#something_else">Something Else</a></li>
<li><a href="#conclusion">Conclusion</a></li>
</ul>
Aside from sticking TOC in your arrayref of plugins in your
ZofCMS template (plugins => [ qw/TOC/ ]) and placing
<tmpl_var name="page_toc"> in your HTML::Template template
you also need to create
a page_toc 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.
If the element is a scalar it is the same as it being an arrayref with one
element. The element which is an arrayref can contain either one, two or
three elements itself. Which represent the following:
page_toc => [
'#foo',
'#bar-baz',
],
# OR
page_toc => [
[ '#foo' ],
[ '#bar-baz' ],
],
The first (and only) element will be used in href="" attribute
of the generated link. The text of the link will be determined
automatically, in particular the '#' will be removed, first letter
will be capitalized and any dashes '-' or underscores '_' will
be replaced by a space with the letter following them capitalized. The
example above will place the following code in
<tmpl_var name="page_toc">:
<ul class="page_toc">
<li><a href="#foo">Foo</a></li>
<li><a href="#bar-baz">Bar Baz</a></li>
</ul>
page_toc => [
[ '#foo', 'Foos Lots of Foos!' ],
[ '#bar-baz', 'Bar-baz' ],
],
The first element will be used in href="" attribute
of the generated link. The second element will be used as text for the
link. The example above will generate the following code:
<ul class="page_toc">
<li><a href="#foo">Foos Lots of Foos!</a></li>
<li><a href="#bar-baz">Bar-baz</a></li>
</ul>
page_toc => [
[ '#foo', 'Foos Lots of Foos!', 'foos' ],
[ '#bar-baz', 'Bar-baz', 'bars' ],
],
The first element will be used in href="" 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 class="" attribute
on the <li> element for the corresponding entry.
The example above will generate the following code:
<ul class="page_toc">
<li class="foos"><a href="#foo">Foos Lots of Foos!</a></li>
<li class="bars"><a href="#bar-baz">Bar-baz</a></li>
</ul>
Note: the class of the <ul> element is always page_toc
Zoffix Znet, <zoffix at cpan.org>
(http://zoffix.com, http://haslayout.net)
Please report any bugs or feature requests to bug-app-zofcms-plugin-toc at rt.cpan.org, or through
the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=App-ZofCMS-Plugin-TOC. I will be notified, and then you'll
automatically be notified of progress on your bug as I make changes.
You can find documentation for this module with the perldoc command.
perldoc App::ZofCMS::Plugin::TOC
You can also look for information at:
http://rt.cpan.org/NoAuth/Bugs.html?Dist=App-ZofCMS-Plugin-TOC
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.
| App-ZofCMS-Plugin-TOC documentation | Contained in the App-ZofCMS-Plugin-TOC distribution. |
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"; <ul class="page_toc"> <tmpl_loop name="toc">\t<li<tmpl_if name="class"> class="<tmpl_var name="class">"</tmpl_if>><a href="<tmpl_var name="url">"><tmpl_var name="name"></a></li> </tmpl_loop></ul> 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__