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 This plugin is now maintained by the Blosxom Sourceforge Team,
122 <blosxom-devel@lists.sourceforge.net>.
124 =head1 ACKNOWLEDGEMENTS
126 Eric David Sherman, for < and >
130 Blosxom Home/Docs/Licensing: http://blosxom.sourceforge.net/
132 Blosxom Plugin Docs: http://blosxom.sourceforge.net/documentation/users/plugins.html
136 None known; please send bug reports and feedback to the Blosxom
137 development mailing list <blosxom-devel@lists.sourceforge.net>.
141 Blosxom and this Blosxom Plug-in
142 Copyright 2003, Rael Dornfest
144 Permission is hereby granted, free of charge, to any person obtaining a
145 copy of this software and associated documentation files (the "Software"),
146 to deal in the Software without restriction, including without limitation
147 the rights to use, copy, modify, merge, publish, distribute, sublicense,
148 and/or sell copies of the Software, and to permit persons to whom the
149 Software is furnished to do so, subject to the following conditions:
151 The above copyright notice and this permission notice shall be included
152 in all copies or substantial portions of the Software.
154 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
155 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
156 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
157 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
158 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
159 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
160 OTHER DEALINGS IN THE SOFTWARE.