The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

App::Followme::Common - Common functions to different packages =head1 SYNOPSIS

    use App::Followme::Common qw(update_page);
    $page = update_page($prototype, $page, $decorated, $prototype_path);

DESCRIPTION

App::Followme::Common exports functions common to more than one package. Packages directly invoked by followme are modules, but there is enough commonality between them to want to factor out some functions into this package.

FUNCTIONS

my $date = build_date($filename);

The variables calculated from the modification time are: weekday, month, monthnum, day, year, hour24, hour, ampm, minute, and second.

my $title = build_title($filename);

The title of the page is derived from the file name by removing the filename extension, removing any leading digits,replacing dashes with spaces, and capitalizing the first character of each word.

$url = build_url($filename, $web_extension, $relative_to);

Build the url that of a web page from its filename. Web extension is a string containing the extension html pages have. Relative_to is an optional filename that the url is relative_to. If it is unset, the url is absolute.

my $sub = compile_template($template, $variable);

Compile_template compiles a template contained in a string into a subroutine. Then the subroutine can be called with one argument, a hash containing the data to be interpolated into the subroutine. The output is a page containing the template with the interpolated data. The data supplied to the subroutine should be a hash reference. fields in the hash are substituted into variables in the template. Variables in the template are surrounded by double braces, so that a link would look like:

    <li><a href="{{url}}">{{title}}</a></li>

The string which indicates a variable is passed as an optional second argument to compile_template. If not present or blank,double braces are used. If present, the string should contain an asterisk to indicate where the variable name is placed.

The data hash may contain a list of hashes, which should be named loop. Text in between loop comments will be repeated for each hash in the list and each hash will be interpolated into the text. Loop comments look like

    <!-- loop -->
    <!-- endloop -->

There should be only one pair of loop comments in the template.

$flag = exclude_file($exclude_files, $filename);

Return true if filename is in a list of excluded files

$blocks = parse_page($page, $decorated);

Extract blocks from a web page. Page is a string containing the web page. Decorates is a flag indicating if the block is surrounded by the block tags.

$str = read_page($filename);

Read a fie into a string. An the entire file is read from a string, there is no line at a time IO. This is because files are typically small and the parsing done is not line oriented.

$data = set_variables($filename, $web_extension, $relative_to);

Create title, url, and date variables from the filename and the modification date of the file.

@filenames = sort_by_date(@filenames);

Sort filenames by modification date, placing the least recently modified file first. If two files have the same date, they are sorted by name.

@filenames = sort_by_depth(@filenames);

Sort filenames by directory depth, with least deep files first. If two files have the same depth, they are sorted by name.

@filenames = sort_by_name(@filenames);

Sort files by name, except the index file is placed first.

($dir, $file) = split_filename($filename);

Split a filename into directory and bare filename.

$top_directory = top_directory($directory);

Get and optionally set the top directory of the website

$page = update_page($prototype, $page, $decorated, $prototype_path);

This function combines the contents of a prototype and page to create a new page. Update_page updates the constant portions of a web page from a prototype. Each html page has sections that are different from other pages and other sections that are the same. The sections that differ are enclosed in html comments that look like

    <!-- section name-->
    <!-- endsection name -->

and indicate where the section begins and ends. A page is updated by substituting all its named blocks into corresponding block in the prototype. The effect is that all the text outside the named blocks are updated to be same as the text in the prototype.

Updates to the named block can also be made conditional by adding an in after the section name. If the folder name after the "in" is included in the prototype_path hash, then the block tags are ignored, it is as if the block does not exist. The block is considered as part of the constant portion of the prototype. If the folder is not in the prototype_path, the block is treated as any other block and varies from page to page.

    <!-- section name in folder -->
    <!-- endsection name -->

Text in conditional blocks can be used for navigation or other sections of the page that are constant, but not constant across the entire site.

Both prototype and page are strings, not filenames. The argument decorated controls whether the section comment tags are copied from the prototype or page. If decorated is true, the section tags are treated as part of the block and are copied from the page. If decorated is false, the section tags are copied from the prototype. Template_path is a hash containing the directories from the base directory of the web site down to the directory containing the prototype. The hash is treated as a set, that is, the directory names are the keys and the values of the keys are one/

$flag = unchanged_prototype($prototype, $page, $decorated, $prototype_path);

Update_prototype return true if running update_page would leave the page unchanged, false if it would change the page. The arguments are the same as update_page.

write_page($filename, $str);

Write a file from a string. An the entire file is read to or written from a string, there is no line at a time IO. This is because files are typically small and the parsing done is not line oriented.

LICENSE

Copyright (C) Bernie Simon.

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

AUTHOR

Bernie Simon <bernie.simon@gmail.com>