1 # Blosxom Plugin: interpolate_conditional
2 # Author(s): Rael Dornfest <rael@oreilly.com>
4 # Documentation: See the bottom of this file or type:
5 # perldoc interpolate_conditional
7 package interpolate_conditional;
9 # --- Configurable variables -----
11 # --------------------------------
25 $template =~ s#\?\{(\$\w+(?:::)?\w*) (.*?)\}#"defined $1 ? \$2 : ''"#gee;
28 $template =~ s#\?\{!(\$\w+(?:::)?\w*) (.*?)\}#"!defined $1 ? \$2 : ''"#gee;
31 $template =~ s#\?\{(\$\w+(?:::)?\w*)!=(.*?) (.*?)\}#"defined $1 and $1 ne '$2' ? \$3 : ''"#gee;
34 $template =~ s#\?\{(\$\w+(?:::)?\w*)=(.*?) (.*?)\}#"defined $1 and $1 eq '$2' ? \$3 : ''"#gee;
37 $template =~ s#\?\{(\$\w+(?:::)?\w*)>(.*?) (.*?)\}#"defined $1 and $1 gt '$2' ? \$3 : ''"#gee;
40 $template =~ s#\?\{(\$\w+(?:::)?\w*)<(.*?) (.*?)\}#"defined $1 and $1 lt '$2' ? \$3 : ''"#gee;
42 # unconditional (and recursive)
43 while( $template =~ s/(\$[a-zA-Z]\w+(?:::)?\w*)/"defined $1 ? $1 : ''"/gee ) { }
56 Blosxom Plug-in: interpolate_conditional
60 Include bits of text and template variable values in templates based on
61 one or more of the following conditions:
63 * Unconditionally (and recursively), just as with the Blosxom default
65 e.g. include a link to the story's path using various template variables.
67 <a href="$url$path">$path</a>
69 * The template variable has a value (i.e. is defined)
71 e.g. include a hyperlink to the story's path if it has a path (i.e.
74 ?{$path <a href="$url$path">$path</a>}
76 * The template variable doesn't have a value (i.e. is NOT defined)
78 e.g. include a hyperlink to home if path is undefined.
80 ?{!$path <a href="$url">/</a>}
82 * The template variable is equal (=) to a particular value
84 e.g. include "1 writeback" (singular) if the value of writeback count is 1
86 ?{$writeback::count=1 $writeback::count writeback}
88 * The template variable is not equal (!=) to a particular value
90 e.g. include "x writebacks" (plural) if the value of writeback
93 ?{$writeback::count!=1 $writeback::count writebacks}
95 * The template variable is less than (<) a particular value
97 e.g. include "no writebacks" if the value of writeback count is < 1
99 ?{$writeback::count<1 no writebacks}
101 * The template variable is greater than (>) a particular value
103 e.g. include "oodles of writebacks" if the value of writeback count is > 50
105 ?{$writeback::count>50 oodles of writebacks}
107 Overrides Blosxom's default interpolate() subroutine.
111 Drop the interpolate_conditional plug-in into your Blosxom plugins folder.
119 Rael Dornfest <rael@oreilly.com>, http://www.raelity.org/
121 =head1 ACKNOWLEDGEMENTS
123 Eric David Sherman, for < and >
127 Blosxom Home/Docs/Licensing: http://www.raelity.org/apps/blosxom/
129 Blosxom Plugin Docs: http://www.raelity.org/apps/blosxom/plugin.shtml
133 Address bug reports and comments to the Blosxom mailing list
134 [http://www.yahoogroups.com/group/blosxom].
138 Blosxom and this Blosxom Plug-in
139 Copyright 2003, Rael Dornfest
141 Permission is hereby granted, free of charge, to any person obtaining a
142 copy of this software and associated documentation files (the "Software"),
143 to deal in the Software without restriction, including without limitation
144 the rights to use, copy, modify, merge, publish, distribute, sublicense,
145 and/or sell copies of the Software, and to permit persons to whom the
146 Software is furnished to do so, subject to the following conditions:
148 The above copyright notice and this permission notice shall be included
149 in all copies or substantial portions of the Software.
151 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
152 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
153 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
154 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
155 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
156 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
157 OTHER DEALINGS IN THE SOFTWARE.