NAME

HTML::EasyTemplate::DirMenu - HTML menus of directories.

DESCRIPTION

Provide an easy means of creating from a directory a representative block of HTML suitable for use as a substitution item in an HTML::Easytemplate, or as freestanding mark-up.

SYNOPSIS

Print a simple menu of HTML files in current working directory:

use HTML::EasyTemplate;
my $m = new HTML::EasyTemplate::DirMenu (
	'START'			=> 'E:/www/leegoddard_com',
	'URL_ROOT'		=> 'http://leegoddard_com',
	'MODE'			=> 'files',
	'TITLE_FROM'	=> 'title',
	'LIST_START'	=> '<DIV class="menu-layer">',
	'LIST_END'		=> '</DIV>',
	'ARTICLE_START'	=> '<DIV class="menu-item">',
	'ARTICLE_END'	=> '</DIV>',
	'DIR_START'		=> '<DIV class="dir-name>',
	'DIR_END'		=> '</DIV>',
);
print $m->{HTML};

Add the following lines to the above for a menu in an HTML::EasyTemplate, as TEMPLATEITEM name='menu1' (based on the example provided in HTML::EasyTemplate):

use HTML::EasyTemplate::DirMenu;
my %items = (
	'articleTitle'=> 'An Example Article',
	'articleText' => 'This is boring sample text: hello world...',
	'menu'		  => $m->{HTML},
);
my $TEMPLATE = new HTML::EasyTemplate('E:/WWW/leegoddard_com/FL/_templates/Template_Blank.html') or die "Couldn't make template!";
$TEMPLATE->title("Latka Lover");
$TEMPLATE -> process('fill',\%items);
$TEMPLATE -> save( 'E:/WWW/leegoddard_com/FL/','new2.html');
print "Saved the new document as <$TEMPLATE->{ARTICLE_PATH}>\n";
__END__

DEPENDENCIES and PRAGMA

EasyTemplate;
cwd;
HTML::TokeParser;
strict;

Constructor method (new)

The method expects a package/class referemnce as it's first parameter. Following that, arguments should be passed in the form of an anonymous hash or as name/value pairs:

my $m = new HTML::EasyTemplate::DirMenu (
		'arg1'=>'val1','arg2'=>'val2',
);

or:

my $m = new HTML::EasyTemplate::DirMenu (
		{'arg1'=>'val1','arg2'=>'val2',}
);

Arguments

MODE

Must be set to one of either 'all', 'dirs', 'files'.

START

The directory to menu, or at which to start menuing.

EXTENSIONS

Filter - a regular expression fragment applied to the filenames within a directory: insensitive to case, is bracketed, and matches after a dot, and is tied to the the end of the string:

m/\.($HERE)$/i

Deafults to .*\.html?.

PRINTEXTENSIONS

True or false to request that filename extensions, defined in the object's EXTENSIONS slot above, be included or excluded in the printing of a filename. Defaults to exclude.

EXC_DIRS, EXC_FILES

A regular expression to be applied against directories/files to decide exclusion.

TITLE_FROM

An HTML element within the doc, the first occurance of which will be accessed to get the text for the menu link. If it fails or is not supplied, will use the doc's filename.

LIST_START, LIST_END

HTML to put at the top and bottom of the menu output.

ARTICLE_START, ARTICLE_END

HTML to put at before and after each menu item.

HTMLDEFAULT

HTML to use when no files are found in a directory. Defaults to [No content].

TOPDIRTEXT

Text will be used as top-level directory title.

ARTICLE_ROOT

The directory in which to begin work; defaults to the same value as the START slot detailed above.

The ARTICLE_ROOT is stripped from filepaths when creating HTML A href elements, and replaced with...

URL_ROOT

This slot is used as the BASE for created hyperlinks to files, instead of ARTICLE_ROOT, above.

URL_ROOT_TEXT

Text to use in a link that refers to URL_ROOT. =head2 Other Slots

HTML

It is in this slot that a single scalar representing the composed HTML menu will be found.

OUTPUT

Defaults to LIST, which produces HTML output using the options and defaults above. Could be used to call another processing sub (in &new) to output maybe a drop-down menu.

METHOD collect_this_dir

Collects content info of a directory, the path to which it accepts as it's sole argument.

Returns undef on failure.

METHOD create_html

Fills the calling object's HTML slot detailed in the constructor method's documentation.

Incidentaly returns that HTML.

CAVEATS

  • Does not list directories empty of files mathcing the search pattern.

  • If called with RECURSE='false'>, directories will displayed as if they were files. This may change.

  • Whilst this has been fully tested on non-recursive functions, more time needs to be spent on RECURSE method before we get to version 1.0.

TODO

  • Sort listings alphabetically.

SEE ALSO

HTML::TokeParser
HTML::EasyTemplate
HTML::EasyTemplate::PageMenu
HTML::EasyTemplate::BuildMySite

AUTHOR

Lee Goddard (LGoddard@CPAN.org)

COPYRIGHT

Copyright 2000-2001 Lee Goddard.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

6 POD Errors

The following errors were encountered while parsing the POD:

Around line 76:

'=item' outside of any '=over'

Around line 197:

You forgot a '=back' before '=head1'

Around line 367:

'=item' outside of any '=over'

Around line 379:

You forgot a '=back' before '=head1'

Around line 381:

'=item' outside of any '=over'

Around line 385:

You forgot a '=back' before '=head1'