Add a bunch of Rael plugins.
[matthijs/upstream/blosxom-plugins.git] / general / flavourdir
1 # Blosxom Plugin: flavourdir
2 # Author(s): Rael Dornfest <rael@oreilly.com> 
3 # Version: 2003-03-13
4 # Documentation: See the bottom of this file or type: perldoc flavourdir
5
6 package flavourdir;
7
8 # --- Configurable variables -----
9
10 # Where might I find your flavours?
11 my $flavour_dir = "$blosxom::datadir/flavours";
12
13 # Should I fall back to looking in your Blosxom datadir before using the 
14 # default built-in templates?
15 # 0 = no; 1 = yes
16 my $fallback_to_datadir = 0;
17
18 # --------------------------------
19
20 use FileHandle;
21 my $fh = new FileHandle;
22
23 sub start {
24   1;
25 }
26
27 sub template {
28   return sub {
29     my ($path, $chunk, $flavour) = @_;
30     
31     $path =~ s!^/*!!; $path = "/$path";
32
33     my $p = $path;
34     do {
35       return join '', <$fh> if $fh->open("< $flavour_dir/$p/$chunk.$flavour");
36     } while ($p =~ s/(\/*[^\/]*)$// and $1);
37
38     $p = $path;
39     $fallback_to_datadir and do {
40       return join '', <$fh> if $fh->open("< $blosxom::datadir/$p/$chunk.$flavour");
41     } while ($p =~ s/(\/*[^\/]*)$// and $1);
42
43     return join '', ($blosxom::template{$flavour}{$chunk} || $blosxom::template{error}{$chunk} || '');
44   };
45 }
46   
47 1;
48
49 __END__
50
51 =head1 NAME
52
53 Blosxom Plug-in: flavourdir
54
55 =head1 SYNOPSIS
56
57 Keep your flavours in a separate flavour directory rather than alongside all of your weblog entries.  Optionally falls back to the default of looking in your Blosxom datadir.
58
59 Overrides Blosxom's default template() subroutine.
60
61 Respects the Blosxom concept of finding flavours along specific paths, expecting to find these paths echoed in your flavour directory.
62
63 =head1 INSTALLATION AND CONFIGURATION
64
65 Drop the flavourdir plug-in into your Blosxom plugins folder.
66
67 The plug-in is preconfigured to assume a flavour directory beneath your Blosxom data directory.  Alter the $flavour_dir configurable variable to move it elsewhere.
68
69 If you'd like the plug-in to fall back to looking in your Blosxom data directory if it doesn't find the appropriate flavour in your flavour directory, set the $fallback_to_datadir configurable variable to 1.  Note: This results in additional processing and isn't a particularly efficient use of a plug-in's time.
70
71 =head1 VERSION
72
73 2003-03-13
74
75 =head1 AUTHOR
76
77 Rael Dornfest  <rael@oreilly.com>, http://www.raelity.org/
78
79 =head1 SEE ALSO
80
81 Blosxom Home/Docs/Licensing: http://www.raelity.org/apps/blosxom/
82
83 Blosxom Plugin Docs: http://www.raelity.org/apps/blosxom/plugin.shtml
84
85 =head1 BUGS
86
87 Address bug reports and comments to the Blosxom mailing list 
88 [http://www.yahoogroups.com/group/blosxom].
89
90 =head1 LICENSE
91
92 Blosxom and this Blosxom Plug-in
93 Copyright 2003, Rael Dornfest 
94
95 Permission is hereby granted, free of charge, to any person obtaining a
96 copy of this software and associated documentation files (the "Software"),
97 to deal in the Software without restriction, including without limitation
98 the rights to use, copy, modify, merge, publish, distribute, sublicense,
99 and/or sell copies of the Software, and to permit persons to whom the
100 Software is furnished to do so, subject to the following conditions:
101
102 The above copyright notice and this permission notice shall be included
103 in all copies or substantial portions of the Software.
104
105 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
106 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
107 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
108 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
109 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
110 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
111 OTHER DEALINGS IN THE SOFTWARE.