root/trunk/plagger/lib/Plagger/Plugin/Bundle/Planet.pm

Revision 1876 (checked in by miyagawa, 14 years ago)

load Filter::HTMLTidy from Bundle::Planet, if HTML::Tidy is available. Refs #334

Line 
1 package Plagger::Plugin::Bundle::Planet;
2 use strict;
3 use base qw( Plagger::Plugin );
4
5 use File::Spec;
6
7 sub register {
8     my($self, $context) = @_;
9
10     # check required configs
11     for my $directive (qw( title dir url )) {
12         unless ($self->conf->{$directive}) {
13             $context->error("Bundle::Planet: config '$directive' is missing");
14         }
15     }
16
17     $context->load_plugin({
18         module => 'Filter::StripTagsFromTitle',
19     });
20
21     eval { require HTML::Tidy };
22     unless ($@) {
23         $context->load_plugin({
24             module => 'Filter::HTMLTidy',
25         });
26     }
27
28     $context->load_plugin({
29         module => 'Filter::HTMLScrubber',
30         config => $self->conf->{scrubber} || {},
31     });
32
33     $context->load_plugin({
34         module => 'Filter::GuessTimeZoneByDomain',
35     });
36
37     my @rules;
38     my $duration = defined $self->conf->{duration}
39         ? $self->conf->{duration} : "7 days";
40     if ($duration ne '0') {
41         push @rules, {
42             module   => 'Fresh',
43             duration => $duration,
44         };
45     }
46
47     if (my $rule = $self->conf->{extra_rule}) {
48         push @rules, (ref $rule eq 'ARRAY' ? @{$rule} : ($rule));
49     }
50
51     $context->load_plugin({
52         module => 'SmartFeed::All',
53         rule => \@rules,
54         config => {
55             title => $self->conf->{title},
56             link  => $self->conf->{url},
57             description => $self->conf->{description},
58         },
59     });
60
61     my $rule = {
62         expression => q{ $args->{feed}->id eq 'smartfeed:all' },
63     };
64
65     $context->load_plugin({
66         module => 'Publish::Planet',
67         rule   => $rule,
68         config => {
69             dir  => $self->conf->{dir},
70             skin => $self->conf->{theme},
71             template => {
72                 style_url => $self->conf->{stylesheet},
73                 url => {
74                     base => $self->conf->{url},
75                     atom => $self->conf->{url} . "atom.xml",
76                     rss  => $self->conf->{url} . "rss.xml",
77                     opml => $self->conf->{url} . "subscriptions.opml",
78                     foaf => $self->conf->{url} . "foafroll.xml",
79                 },
80             },
81         },
82     });
83
84     $context->load_plugin({
85         module => 'Publish::Feed',
86         rule   => $rule,
87         config => {
88             dir => $self->conf->{dir},
89             filename => 'atom.xml',
90             format => 'Atom',
91         },
92     });
93
94     $context->load_plugin({
95         module => 'Publish::Feed',
96         rule   => $rule,
97         config => {
98             dir => $self->conf->{dir},
99             filename => 'rss.xml',
100             format => 'RSS',
101         },
102     });
103
104     $context->load_plugin({
105         module => 'Publish::OPML',
106         config => {
107             filename => File::Spec->catfile($self->conf->{dir}, 'subscriptions.opml'),
108             title => $self->conf->{title},
109         },
110     });
111
112     $context->load_plugin({
113         module => 'Publish::FOAFRoll',
114         config => {
115             filename => File::Spec->catfile($self->conf->{dir}, 'foafroll.xml'),
116             link => $self->conf->{url},
117             url  => $self->conf->{url} . "foafroll.xml",
118             title => $self->conf->{title},
119         },
120     });
121 }
122
123 1;
124
125 __END__
126
127 =head1 NAME
128
129 Plagger::Plugin::Bundle::Planet - Bundle package to create Planet site
130
131 =head1 SYNOPSIS
132
133   - module: Bundle::Planet
134     config:
135       title: Planet Foobar
136       dir: /path/to/planet
137       url: http://example.org/planet
138       theme: sixapart-std
139       stylesheet: foo.css
140       duration: 7 days
141       description: Everything about Foobar from the Web
142
143 =head1 DESCRIPTION
144
145 This plugin is a I<Bundle> plugin to load bunch of required modules to
146 create Planet site with a single Plugin setup. Using this plugin will
147 load following plugins and automatically sets up necessary
148 configurations.
149
150 =over 4
151
152 =item Filter::StripTagsFromTitle
153
154 =item Filter::HTMLTidy (if HTML::Tidy is available)
155
156 =item Filter::HTMLScrubber
157
158 =item Filter::GuessTimeZoneByDomain
159
160 =item SmartFeed::All
161
162 =item Publish::Planet
163
164 =item Publish::Feed
165
166 =item Publish::OPML
167
168 =item Publish::FOAFRoll
169
170 =back
171
172 =head1 CONFIGS
173
174 =over 4
175
176 =item title
177
178 Title of Planet site. Required.
179
180 =item dir
181
182 Directory to create HTML, Feed and CSS files in. Required.
183
184 =item url
185
186 Public URL to access the Planet site, which is used to construct Feed and CSS URLs with. Required.
187
188 =item theme
189
190 Name of I<theme> to use with Publish::Planet. Defaults to I<default>.
191
192 =item stylesheet
193
194 URL(s) of stylesheet (CSS) to use with I<sixapart-std> theme. Optional.
195
196 =item duration
197
198 Duration of feed entries to display. When you pass I<0> as a value, the Planet plugin displays
199 all the entries aggregated. Defaults to I<7 days>.
200
201 =item extra_rule
202
203 Additional rule to add to filter entries using SmartFeed::All. Optional and defaults to nothing.
204
205 =item description
206
207 Description to use in XHTML tagline and Atom/RSS feeds. Optional.
208
209 =back
210
211 =head1 AUTHOR
212
213 Tatsuhiko Miyagawa
214
215 =head1 SEE ALSO
216
217 L<Plagger>, L<Plagger::Plugin::Publish::Feed>, L<Plagger::Plugin::Publish::Planet>
218
219 =cut
Note: See TracBrowser for help on using the browser.