Add __END_CONFIG__ token to remaining gavinc plugins.
[blosxom-plugins.git] / gavinc / storytags
blob1665dbf5fb11e39074cf901a0210844b4d1133a0
1 # Blosxom Plugin: storytags
2 # Author(s): Gavin Carr <gavin@openfusion.com.au>
3 # Version: 0.002000
4 # Documentation: See the bottom of this file or type: perldoc storytags
5 # Requires: tags
6 # Follows: tags
8 package storytags;
10 use strict;
12 # Uncomment next line to enable debug output (don't uncomment debug() lines)
13 #use Blosxom::Debug debug_level => 1;
15 use vars qw($taglist @taglist);
17 # --- Configuration variables -----
19 # Formatting strings
20 my $prefix = 'Tags: ';
21 my $suffix = '. ';
23 # ---------------------------------
24 # __END_CONFIG__
26 $taglist = '';
28 sub start { 1 }
30 # Set $taglist
31 sub story {
32     my ($pkg, $path, $filename, $story_ref, $title_ref, $body_ref) = @_;
34     return 1 unless $tags::tag_cache 
35              && ref $tags::tag_cache 
36              && keys %{ $tags::tag_cache };
37     return 1 unless defined $tags::tag_cache->{"$path/$filename"};
39     @taglist = ();
40     @taglist = sort { lc $a cmp lc $b } split /\s*,\s*/, 
41       $tags::tag_cache->{"$path/$filename"}->{tags}
42         if defined $tags::tag_cache->{"$path/$filename"}->{tags};
43     $taglist = _format_taglist( \@taglist );
45     return 1;
48 sub _format_taglist {
49     my ($tags) = @_;
50     return '' unless @$tags;
51     return $prefix
52            . join(', ', 
53                map { qq(<a href="$blosxom::url/tags/$_" rel="tag">$_</a>) }
54                @$tags
55            )
56            . $suffix;
61 __END__
63 =head1 NAME
65 storytags - blosxom plugin to format a per-story $storytags::taglist string
66 and @storytags::taglist array of tags
68 =head1 DESCRIPTION
70 L<storytags> is a blosxom plugin to format a per-story $storytags::taglist 
71 string, and a @storytags::taglist array of tags. The $taglist is a 
72 comma-separated list of the tags defined for the story, prefixed by 
73 $storytags::prefix, and suffixed by $storytags::suffix. If no tags are 
74 defined, then $taglist will be the empty string '' (i.e. no prefix and 
75 suffix are added). @taglist is a simple array of the tags for the story,
76 and an empty array if none are set.
78 The default values for $prefix and $suffix are 'Tags: ' and '. ' 
79 respectively, so a typical $taglist might look like:
81     Tags: dogs, cats, pets.
83 =head1 USAGE
85 L<storytags> requires the L<tags> plugin, and should be loaded AFTER
86 L<tags>. It has no other ordering dependencies.
88 =head1 ACKNOWLEDGEMENTS
90 This plugin was inspired by xtaran's excellent L<tagging> plugin,
91 which includes similar functionality.
93 =head1 SEE ALSO
95 L<tags>, L<tagcloud>, xtaran's L<tagging>.
97 Blosxom: http://blosxom.sourceforge.net/
99 =head1 AUTHOR
101 Gavin Carr <gavin@openfusion.com.au>, http://www.openfusion.net/
103 =head1 LICENSE
105 Copyright 2007, Gavin Carr.
107 This plugin is licensed under the same terms as blosxom itself i.e.
109 Permission is hereby granted, free of charge, to any person obtaining a
110 copy of this software and associated documentation files (the "Software"),
111 to deal in the Software without restriction, including without limitation
112 the rights to use, copy, modify, merge, publish, distribute, sublicense,
113 and/or sell copies of the Software, and to permit persons to whom the
114 Software is furnished to do so, subject to the following conditions:
116 The above copyright notice and this permission notice shall be included
117 in all copies or substantial portions of the Software.
119 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
120 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
121 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
122 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
123 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
124 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
125 OTHER DEALINGS IN THE SOFTWARE.
127 =cut
129 # vim:ft=perl:sw=4