Updates to README and MANIFEST files.
[blosxom-plugins.git] / xtaran / dept
blob27f53ff327077a83268da1bf2a12cd0205e17ac9
1 # -*- perl -*-
2 # Blosxom Plugin: dept
3 # Author(s): Axel Beckert <blosxom@deuxchevaux.org>, http://noone.org/blog
4 # Version: 0.01
5 # Licensing: GPL v2 or newer, http://www.gnu.org/licenses/gpl.txt
6 # Dept plugin web page: http://noone.org/blog?-tags=dept
7 # Dept plugin download: http://noone.org/blosxom/dept
8 # Blosxom web page: http://blosxom.ookee.com/
10 ### Documentation:
12 # This is a plugin for blosxom.
14 # Installation:
16 #  Just drop it into your blosxoms plugin directory and it should start
17 #  working. If you want, change some of the configuration variables
18 #  below.
19
20 # What it does:
22 #  It allows you to decorate Blosxom postings with "From the XYZ
23 #  dept." like on Slashdot and other Slashsites.
25 # Configuration:
27 #  You can configure different texts based on regular expressions
28 #  matched on the path. By default it looks if the path starts with
29 #  and indicator for German or English language and uses and
30 #  apropriate text in that language.
32 # How to use it:
34 #  Add an additional line after the title, starting with "Dept: ".
35 #  Between this Dept line and the body text there should be a blank
36 #  line. (This is in conformance with other Plugins, e.g. the one for
37 #  meta tags, which work the same way.) After this keyword, the tags
38 #  should be listed and separated by commata.
40 # Example:
42 #  The follwing two examples have the same effect.
44 #  | Story Headline
45 #  | Dept: Slashdot Fan Club
46 #  |
47 #  | Story Body [...]
49 # Including the dept line into templates:
51 #  Use $dept::deptline in your templates.
53 # Known bugs and other ugly obstacles:
55 #  + None yet. :-)
57 # Version History:
59 #  0.01:   Initial release, losely based on my tagging plugin.
62 package dept;
64 ###
65 ### Config
66 ###
68 # Texts by path
70 my %path2text = (
71                 '^/(Deutsch|de)($|/)' => 'Aus der <b>%s</b> Abteilung',
72                 '^/(English|en)($|/)' => 'from the <b>%s</b> dept.',
73                 '*' => 'From the <b>%s</b> dept.', # Default value. Keep it!
74                 );
76 # Regular expression
78 my $dept_re = qr/Dept:/i;
80 # Joining white space with:
81 my $joinchar = '-';
83 # Texts for tags
85 my $dept_prefix = '<div class="dept">';
86 my $dept_suffix = '</div>';
88 # End of configuration.
90 # Global variables
92 $deptline = '';
93 $dept = '';
95 # Code
97 sub start {
98     1;
101 sub story {
102     my($pkg, $path, $filename, $story_ref, $title_ref, $body_ref) = @_;
103     my %localtags = ();
104     my $body = '';
105     my $in_header = 1;
107     $deptline = '';
108     $dept = '';
110     foreach (split /\n/, $$body_ref) {
111         $dept .= 'x';
112         if (/^\s*$/) {
113             $in_header = 0;
114             $body .= "$_\n";
115             next;
116         }
118         if ($in_header) {
119             if (/^$dept_re\s*(.+?)\s*$/) {
120                 $dept = $1;
121                 $dept =~ s/\s/$joinchar/gs;
122                 my $fmtstr = $path2text{'*'};
123                 foreach my $re (sort keys %path2text) {
124                     next if $re eq '*';
125                     if ($path =~ /$re/) {
126                         $fmtstr = $path2text{$re};
127                         last;
128                     }
129                 }
130                 $deptline = 
131                     $dept_prefix.
132                     sprintf($fmtstr, $dept).
133                     $dept_suffix;
134                 $in_header = 0;
135                 next;
136             }
137         }
139         $body .= "$_\n";
140     }
141     $$body_ref = $body;
143     return 1;