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);
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.
The variables calculated from the modification time are:
monthnum, day, year, hour24, hour, ampm, minute, and
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.
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.
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:
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.
Return true if filename is in a list of excluded files
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.
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.
Create title, url, and date variables from the filename and the modification date of the file.
Sort filenames by modification date, placing the least recently modified file first. If two files have the same date, they are sorted by name.
Sort filenames by directory depth, with least deep files first. If two files have the same depth, they are sorted by name.
Sort files by name, except the index file is placed first.
Split a filename into directory and bare filename.
Get and optionally set the top directory of the website
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/
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 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.
Copyright (C) Bernie Simon.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Bernie Simon <email@example.com>