# Blosxom Plugin: interpolate_conditional # Author(s): Rael Dornfest # Version: 2003-05-16 # Documentation: See the bottom of this file or type: # perldoc interpolate_conditional package interpolate_conditional; # --- Configurable variables ----- # -------------------------------- sub start { 1; } sub interpolate { return sub { package blosxom; my $template = shift; # defined $template =~ s#\?\{(\$\w+(?:::)?\w*) (.*?)\}#"defined $1 ? \$2 : ''"#gee; # not defined $template =~ s#\?\{!(\$\w+(?:::)?\w*) (.*?)\}#"!defined $1 ? \$2 : ''"#gee; # not equal to $template =~ s#\?\{(\$\w+(?:::)?\w*)!=(.*?) (.*?)\}#"defined $1 and $1 ne '$2' ? \$3 : ''"#gee; # equal to $template =~ s#\?\{(\$\w+(?:::)?\w*)=(.*?) (.*?)\}#"defined $1 and $1 eq '$2' ? \$3 : ''"#gee; # greater than $template =~ s#\?\{(\$\w+(?:::)?\w*)>(.*?) (.*?)\}#"defined $1 and $1 gt '$2' ? \$3 : ''"#gee; # less than $template =~ s#\?\{(\$\w+(?:::)?\w*)<(.*?) (.*?)\}#"defined $1 and $1 lt '$2' ? \$3 : ''"#gee; # unconditional (and recursive) while( $template =~ s/(\$[a-zA-Z]\w+(?:::)?\w*)/"defined $1 ? $1 : ''"/gee ) { } return $template; }; } 1; __END__ =head1 NAME Blosxom Plug-in: interpolate_conditional =head1 SYNOPSIS Include bits of text and template variable values in templates based on one or more of the following conditions: * Unconditionally (and recursively), just as with the Blosxom default e.g. include a link to the story's path using various template variables. $path * The template variable has a value (i.e. is defined) e.g. include a hyperlink to the story's path if it has a path (i.e. $path is defined). ?{$path $path} * The template variable doesn't have a value (i.e. is NOT defined) e.g. include a hyperlink to home if path is undefined. ?{!$path /} * The template variable is equal (=) to a particular value e.g. include "1 writeback" (singular) if the value of writeback count is 1 ?{$writeback::count=1 $writeback::count writeback} * The template variable is not equal (!=) to a particular value e.g. include "x writebacks" (plural) if the value of writeback count (x) is not 1 ?{$writeback::count!=1 $writeback::count writebacks} * The template variable is less than (<) a particular value e.g. include "no writebacks" if the value of writeback count is < 1 ?{$writeback::count<1 no writebacks} * The template variable is greater than (>) a particular value e.g. include "oodles of writebacks" if the value of writeback count is > 50 ?{$writeback::count>50 oodles of writebacks} Overrides Blosxom's default interpolate() subroutine. =head1 INSTALLATION Drop the interpolate_conditional plug-in into your Blosxom plugins folder. =head1 VERSION 2003-05-16 =head1 AUTHOR Rael Dornfest , http://www.raelity.org/ =head1 ACKNOWLEDGEMENTS Eric David Sherman, for < and > =head1 SEE ALSO Blosxom Home/Docs/Licensing: http://www.raelity.org/apps/blosxom/ Blosxom Plugin Docs: http://www.raelity.org/apps/blosxom/plugin.shtml =head1 BUGS Address bug reports and comments to the Blosxom mailing list [http://www.yahoogroups.com/group/blosxom]. =head1 LICENSE Blosxom and this Blosxom Plug-in Copyright 2003, Rael Dornfest Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.