#!/usr/bin/perl # Name: Flav 2 Theme Conversion tool # Author: Jonah Chanticleer (jonahc@theblankline.net) # Purpose: convert Blosxom flavours into themes # Version: 2005-4-07 # search current directory for all story.flavour files, store in array @flavours = ; # using old syntax for globbing # traverse array for $flavour(@flavours) { &setVars; # create/initialize the variables # all we want are flavour names, so get rid of all but file extensions $startat = rindex($flavour, ".") + 1; $totallength = length($flavour); $flavour = substr($flavour, $startat , $totallength-$startat); # next step, make one folder for each flavour we found mkdir $flavour, 0755 or die "ERROR: Cannot make $flavour directory: $!"; # start reading in data from the flavour files &readFlavours; # write results to page file in the flavour folder &writeResults; } sub setVars { $content_type = "\n"; $date = "\n"; $story = "\n"; $foot = "\n"; } sub readFlavours { # read content_type file and append to content_type variable open FLAVOUR, "content_type.$flavour" or warn "WARNING: Could not open and read content_type.$flavour: $!"; $content_type .= ; chomp($content_type); $content_type .= " -->\n"; close FLAVOUR; # read head file and append to head variable open FLAVOUR, "head.$flavour" or warn "WARNING: Could not open and read head.$flavour: $!"; while () { $head .= ; } close FLAVOUR; # read date file and append to date variable open FLAVOUR, "date.$flavour" or warn "WARNING: Could not open and read date.$flavour: $!"; $date .= ; # assumes date file is single line. Risky? close FLAVOUR; # read story file and append to story variable open FLAVOUR, "story.$flavour" or warn "WARNING: Could not open and read story.$flavour: $!"; while () { $story .= ; } close FLAVOUR; # read foot file and append to foot variable open FLAVOUR, "foot.$flavour" or warn "WARNING: Could not open and read foot.$flavour: $!"; while () { $foot .= ; } close FLAVOUR; } sub writeResults { open PAGE, "> $flavour/page" or die "ERROR: Could not open $flavour/page for writing theme output: $!"; print PAGE $content_type; print PAGE "\n"; print PAGE $head; print PAGE "\n"; print PAGE $date; print PAGE "\n"; print PAGE $story; print PAGE "\n"; print PAGE $foot; print PAGE "\n"; close PAGE; } __END__ =head1 NAME Flav2Theme =head1 SYNOPSIS Flav2Theme (Flavour To Theme) is a Perl script that you run from the command line that quickly and easily converts Blosxom flavour files into Blosxom theme files. There's no GUI or command line parameters; just type flav2theme and the script will scan the current directory for all the flavour files it can find and convert them into theme folders. No command line parameters to worry about-- just invoke the script and let it batch convert all the flavour files it can find. =head1 INSTALLATION Flav2Theme is NOT a Blosxom plugin, so do not try to put it in your Blosxom's plugin directory or very BAD THINGS may happen! This script is meant to be used as an external stand-alone tool, so put it in your scripts folder or whatever place you use to keep such tools handy. Also, make sure that the first line of the script accurately points to your installation of Perl and that you use chmod to make the script executable. =head1 USAGE Flav2Theme is very easy to use. Just put all the flavour files (content_type.*, head.*, date.*, story.*, foot.*) that you want to convert into themes in one directory. No command line parameters are needed. The script scans the current working directory for all story.* files (can't have a flavour without a story.* file, right?) and generates an array of theme folders-- one for each flavour. Inside of each theme folder is the unique page file for that theme. =head1 VERSION 2005-4-4 =head1 AUTHOR Jonah Chanticleer (jonahc@theblankline.net) =head1 BUGS AND LIMITATIONS I'm not a Perl coding expert. If you find a glitch or bug, please let me know via email at my email address. Even better, if you know how to fix it and make it better and more solid, please feel free to do so. If you do modify the code, please keep me in the loop so I have some idea of what is going on with the tool. There are some features I would like to add in a future version, but my Perl skills are not up to the challenge right now. I'd like for this script to automagically export any style tag information into an external CSS file. =head1 ACKNOWLEDGEMENTS AND MISC. ITEMS Douglas Nerad for turning me on to Blosxom themes. Randal Schwartz and Tom Phoenix for writing Learning Perl. For those who might not have access to Perl and a shell account, a Javascript prototype of this tool can be found at: http://www.theblankline.net/flav2theme.html. I should mention that the Javascript version is not nearly as powerful or scalable as this Perl script because you have to manually copy and paste each flavour file into a web browser text box, but for converting a single flavour file it is adequate.