X-Git-Url: https://git.stderr.nl/gitweb?p=matthijs%2Fupstream%2Fblosxom-plugins.git;a=blobdiff_plain;f=gavinc%2Fstorytags;fp=gavinc%2Fstorytags;h=148a48f5c2d70dc24d048efec69b527231c334f1;hp=0000000000000000000000000000000000000000;hb=e1adedc9d0a948a755ac648befbf5a3415072e5a;hpb=caaf09e3ed3f4f9ddba8b709d47f90c2578db8a5 diff --git a/gavinc/storytags b/gavinc/storytags new file mode 100644 index 0000000..148a48f --- /dev/null +++ b/gavinc/storytags @@ -0,0 +1,124 @@ +# Blosxom Plugin: storytags +# Author(s): Gavin Carr +# Version: 0.001000 +# Documentation: See the bottom of this file or type: perldoc storytags +# Requires: tags +# Follows: tags + +package storytags; + +use strict; + +# Uncomment next line to enable debug output (don't uncomment debug() lines) +#use Blosxom::Debug debug_level => 1; + +use vars qw($taglist); + +# --- Configuration variables ----- + +# Formatting strings +my $prefix = 'Tags: '; +my $suffix = '. '; + +# --------------------------------- + +$taglist = ''; + +sub start { 1 } + +# Set $taglist +sub story { + my ($pkg, $path, $filename, $story_ref, $title_ref, $body_ref) = @_; + + return 1 unless $tags::tag_cache + && ref $tags::tag_cache + && keys %{ $tags::tag_cache }; + return 1 unless defined $tags::tag_cache->{"$path/$filename"}; + + $taglist = _format_taglist($tags::tag_cache->{"$path/$filename"}->{tags}); + + return 1; +} + +sub _format_taglist { + my ($tags) = @_; + $tags = '' unless defined $tags; + my @tags = sort { lc $a cmp lc $b } split /\s*,\s*/, $tags; + return '' unless @tags; + return $prefix + . join(', ', + map { qq() } + @tags + ) + . $suffix; +} + +1; + +__END__ + +=head1 NAME + +storytags - blosxom plugin to format a per-story $storytags::taglist string + +=head1 DESCRIPTION + +L is a blosxom plugin to format a per-story $storytags::taglist +string. The string is a comma-separated list of the tags defined for the +story, prefixed by $storytags::prefix, and suffixed by $storytags::suffix. +If no tags are defined, then $taglist will be the empty string '' (i.e. no +prefix and suffix are added). + +The default values for $prefix and $suffix are 'Tags: ' and '. ' +respectively, so a typical $taglist might look like: + + Tags: dogs, cats, pets. + +=head1 USAGE + +L requires the L plugin, and should be loaded AFTER +L. It has no other ordering dependencies. + +=head1 ACKNOWLEDGEMENTS + +This plugin was inspired by xtaran's excellent L plugin, +which includes similar functionality. + +=head1 SEE ALSO + +L, L, xtaran's L. + +Blosxom: http://blosxom.sourceforge.net/ + +=head1 AUTHOR + +Gavin Carr , http://www.openfusion.net/ + +=head1 LICENSE + +Copyright 2007, Gavin Carr. + +This plugin is licensed under the same terms as blosxom itself i.e. + +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. + +=cut + +# vim:ft=perl:sw=4 +