File Coverage

blib/lib/Rails/Assets.pm
Criterion Covered Total %
statement 55 55 100.0
branch n/a
condition n/a
subroutine 18 18 100.0
pod 12 12 100.0
total 85 85 100.0


line stmt bran cond sub pod time code
1             package Rails::Assets {
2 3     3   167567   use 5.006;
  3         9  
3 3     3   14   use strict;
  3         4  
  3         53  
4 3     3   11   use warnings;
  3         8  
  3         64  
5              
6 3     3   696   use Rails::Assets::Base;
  3         6  
  3         131  
7 3     3   720   use Rails::Assets::Processor;
  3         6  
  3         149  
8 3     3   648   use Clone qw(clone);
  3         4964  
  3         1510  
9              
10               our $VERSION = '0.01';
11               our $TEMPLATE_DIR = [qw( app/views/)];
12               our $TEMPLATE_EXT = [qw(.haml .erb)];
13               our $ASSETS_DIR = [qw( app/assets/ public/ vendor/assets/ )];
14               our $ASSETS_EXT = {
15                 fonts => [qw(.woff2 .woff .ttf .eot .otf)],
16                 images => [qw(.png .jpg .gif .svg .ico)],
17                 javascripts => [qw(.js .map)],
18                 stylesheets => [qw(.css .scss)],
19               };
20              
21               sub new {
22 2     2 1 10640     my $class = shift;
23 2         30     my $self = {
24                   TEMPLATE_DIR => [@$Rails::Assets::TEMPLATE_DIR],
25                   TEMPLATE_EXT => [@$Rails::Assets::TEMPLATE_EXT],
26                   ASSETS_DIR => [@$Rails::Assets::ASSETS_DIR],
27                   ASSETS_EXT => {%$Rails::Assets::ASSETS_EXT},
28                 };
29 2         12     bless $self, $class;
30               }
31              
32 4     4 1 29   sub template_dir { $_[0]->{TEMPLATE_DIR} }
33 8     8 1 25   sub template_ext { $_[0]->{TEMPLATE_EXT} }
34 3     3 1 27   sub assets_dir { $_[0]->{ASSETS_DIR} }
35 3     3 1 20   sub assets_ext { $_[0]->{ASSETS_EXT} }
36 2     2 1 650   sub assets_hash { $_[0]->{ASSETS_HASH} }
37 2     2 1 19   sub template_hash { $_[0]->{TEMPLATE_HASH} }
38 2     2 1 17   sub scss_hash { $_[0]->{SCSS_HASH} }
39 2     2 1 19   sub map_hash { $_[0]->{MAP_HASH} }
40 2     2 1 12   sub assets_paths { $_[0]->{ASSETS_PATHS} }
41 2     2 1 19   sub reversed_ext { $_[0]->{REVERSED_EXT} }
42              
43               sub analyse {
44 1     1 1 3     my $self = shift;
45 1         4     my ($assets_hash, $assets_paths, $reversed_ext) =
46                   prepare_assets_refs($self->assets_dir, $self->assets_ext);
47              
48 1         16     $self->{ASSETS_HASH} = clone($assets_hash);
49 1         12     $self->{TEMPLATE_HASH} = clone($assets_hash);
50 1         11     $self->{SCSS_HASH} = clone($assets_hash);
51 1         11     $self->{MAP_HASH} = clone($assets_hash);
52 1         3     $self->{ASSETS_PATHS} = $assets_paths;
53 1         9     $self->{REVERSED_EXT} = {%$reversed_ext};
54              
55                 process_asset_file($_, $self->{REVERSED_EXT}, $self->{ASSETS_HASH}, $self->{ASSETS_PATHS})
56 1         3       foreach @{find_files($self->assets_dir())};
  1         3  
57                 process_template_file($_, $self->{TEMPLATE_HASH}, $self->template_ext())
58 1         4       foreach @{find_files($self->template_dir())};
  1         3  
59              
60 1         3     my $scss_files = [grep { $_->{ext} eq '.scss' } @{$self->{ASSETS_HASH}->{stylesheets}}];
  3         7  
  1         3  
61 1         2     my $js_files = [grep { $_->{ext} eq '.js' } @{$self->{ASSETS_HASH}->{javascripts}}];
  2         4  
  1         3  
62              
63 1         2     process_scss_file($_, $self->{REVERSED_EXT}, $self->{SCSS_HASH}) foreach map {$_->{full_path}} @{$scss_files};
  1         9  
  1         2  
64 1         2     process_map_file($_, , $self->{REVERSED_EXT}, $self->{MAP_HASH}) foreach map {$_->{full_path}} @{$js_files};
  2         7  
  1         6  
65 1         6     $self;
66               }
67              
68             }
69             =head1 NAME
70            
71             Rails::Assets - provides some utilities functions for Assets detection in a Rails project.
72            
73             =head1 VERSION
74            
75             Version 0.02
76            
77             =head1 SYNOPSIS
78            
79             This module an object for parsing Assets directories
80            
81             use Rails::Assets;
82            
83             my $assets = Rails::Assets->new();
84            
85             my $template_directories = $assets->template_dir();
86             my $template_extensions = $assets->template_ext();
87             my $assets_directories = $assets->assets_dir();
88             my $assets_extensions = $assets->assets_ext();
89            
90             $assets->analyse();
91             ...
92            
93             =head1 EXPORT
94            
95             A list of functions that can be exported. You can delete this section
96             if you don't export anything, such as for a purely object-oriented module.
97            
98             =head1 SUBROUTINES/METHODS
99            
100             =head2 new
101             The constructor takes no argument for now. Later it would be interesting to add additional paths
102             and extensions. This would require some validation and it might have some side effects
103            
104             =head2 template_dir
105             =head2 template_ext
106             =head2 assets_dir
107             =head2 assets_ext
108             =head2 assets_hash
109             =head2 template_hash
110             =head2 scss_hash
111             =head2 map_hash
112             =head2 assets_paths
113             =head2 reversed_ext
114             =head2 analyse
115            
116             =head1 AUTHOR
117            
118             Mauro Berlanda, C<< <kupta at cpan.org> >>
119            
120             =head1 BUGS
121            
122             Please report any bugs or feature requests to C<bug-rails-assets at rt.cpan.org>, or through
123             the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Rails-Assets>. I will be notified, and then you'll
124             automatically be notified of progress on your bug as I make changes.
125            
126             =head1 SUPPORT
127            
128             You can find documentation for this module with the perldoc command.
129            
130             perldoc Rails::Assets
131            
132             You can also look for information at:
133            
134             =over 4
135            
136             =item * RT: CPAN's request tracker (report bugs here)
137            
138             L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Rails-Assets>
139            
140             =item * AnnoCPAN: Annotated CPAN documentation
141            
142             L<http://annocpan.org/dist/Rails-Assets>
143            
144             =item * CPAN Ratings
145            
146             L<http://cpanratings.perl.org/d/Rails-Assets>
147            
148             =item * Search CPAN
149            
150             L<http://search.cpan.org/dist/Rails-Assets/>
151            
152             =back
153            
154             =head1 ACKNOWLEDGEMENTS
155            
156             =head1 LICENSE AND COPYRIGHT
157            
158             Copyright 2017 Mauro Berlanda.
159            
160             This program is free software; you can redistribute it and/or modify it
161             under the terms of the the Artistic License (2.0). You may obtain a
162             copy of the full license at:
163            
164             L<http://www.perlfoundation.org/artistic_license_2_0>
165            
166             Any use, modification, and distribution of the Standard or Modified
167             Versions is governed by this Artistic License. By using, modifying or
168             distributing the Package, you accept this license. Do not use, modify,
169             or distribute the Package, if you do not accept this license.
170            
171             If your Modified Version has been derived from a Modified Version made
172             by someone other than you, you are nevertheless required to ensure that
173             your Modified Version complies with the requirements of this license.
174            
175             This license does not grant you the right to use any trademark, service
176             mark, tradename, or logo of the Copyright Holder.
177            
178             This license includes the non-exclusive, worldwide, free-of-charge
179             patent license to make, have made, use, offer to sell, sell, import and
180             otherwise transfer the Package with respect to any patent claims
181             licensable by the Copyright Holder that are necessarily infringed by the
182             Package. If you institute patent litigation (including a cross-claim or
183             counterclaim) against any party alleging that the Package constitutes
184             direct or contributory patent infringement, then this Artistic License
185             to you shall terminate on the date that such litigation is filed.
186            
187             Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER
188             AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
189             THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
190             PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY
191             YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
192             CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
193             CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
194             EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
195            
196             =cut
197              
198             1; # End of Rails::Assets
199