File Coverage

blib/lib/Catalyst/View/CSS/Squish.pm
Criterion Covered Total %
statement 21 29 72.4
branch 0 4 0.0
condition 0 3 0.0
subroutine 7 8 87.5
pod 0 1 0.0
total 28 45 62.2


line stmt bran cond sub pod time code
1             package Catalyst::View::CSS::Squish;
2              
3 1     1   1040 use strict;
  1         2  
  1         46  
4 1     1   7 use warnings;
  1         1  
  1         41  
5              
6 1     1   16 use base qw/Catalyst::View/;
  1         3  
  1         808  
7              
8             our $VERSION='0.02';
9              
10 1     1   6 use Carp qw/croak/;
  1         2  
  1         72  
11 1     1   973 use CSS::Squish;
  1         21984  
  1         48  
12 1     1   718757 use Data::Dump qw/dump/;
  1         6431  
  1         87  
13 1     1   1040 use Path::Class::File;
  1         1621965  
  1         196  
14              
15             sub process {
16 0     0 0   my ($self,$c) = @_;
17 0 0         croak 'No CSS files specified in $c->stash->{template}'
18             unless defined $c->stash->{template};
19 0           my (@files) = ( ref $c->stash->{template} eq 'ARRAY' ?
20 0 0         @{ $c->stash->{template} } :
21             split /\s+/, $c->stash->{template} );
22             # map files to INCLUDE_PATH
23 0   0       my $home=$self->config->{INCLUDE_PATH} || $c->path_to('root');
24 0           @files = map {
25 0           Path::Class::File->new( $home, $_);
26             } @files;
27             # feed them to CSS::Squish and set the body.
28 0           $c->res->body( CSS::Squish->concatenate(@files) );
29             }
30              
31             =head1 NAME
32              
33             Catalyst::View::CSS::Squish - Concenate your CSS files.
34              
35             =head1 SYNOPSIS
36              
37             ./script/myapp_create.pl view Squish CSS::Squish
38              
39             sub css : Local {
40             my ($self,$c) = @_;
41             $c->stash->{template} = [ qw|/css/small.css /css/big.css| ];
42             # or "/css/small.css /css/big.css"
43             $c->forward($c->view('Squish'));
44             }
45              
46             =head1 DESCRIPTION
47              
48             Take a set of CSS files and integrate them into one big file using
49             L<CSS::Squish>. The files are read from the 'template' stash variable,
50             and can be provided as a hashref or a space separated scalar.
51              
52             =head1 CONFIG
53              
54             =head2 INCLUDE_PATH
55              
56             The path where we should look for CSS files. Will default to the project
57             'root' dir under the home directory.
58              
59             =head1 SEE ALSO
60              
61             L<Catalyst> , L<Catalyst::View>, L<CSS::Squish>
62              
63             =head1 AUTHOR
64              
65             Marcus Ramberg C<mramberg@cpan.org>.
66              
67             =head1 THANKS
68              
69             To Jesse Vincent for pointing me towards this module.
70              
71             =head1 LICENSE
72              
73             This program is free software, you can redistribute it and/or modify
74             it under the same terms as Perl itself.
75              
76             =cut
77              
78             1;