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