subtitle handling, prettified dates. bugfixes and better errors
[scpubgit/SCS.git] / lib / SCSite / Filter.pm
1 package SCSite::Filter;
2
3 use Moo::Role;
4
5 requires '_filter_stream';
6
7 sub new_from_site { shift->new }
8
9 sub callback_for {
10   my ($self, @args) = @_;
11   sub {
12     my ($stream) = @_;
13     my $config = $self->_parse_config($stream->peek);
14     $self->_filter_stream($stream, $config, @args)
15   }
16 }
17
18 sub _parse_config {
19   my ($self, $evt) = @_;
20   my %config = ( # adapted from CSS::Tiny, extracts -scs- prefix.
21     map {        # converts -scs-foo-bar: to foo_bar
22       /^\s*-scs-([\w._-]+)\s*:\s*(.*?)\s*$/;
23       (join('_', split '-', $1), $2);
24     }
25       grep { /\S/ } split /\;/, ($evt->{attrs}{style}||'')
26   );
27   s/^'(.*)'$/$1/ for values %config;
28   \%config;
29 }
30
31 1;