| 1 | 4 | package Rails::Assets::Processor { | |||||||||||
| 2 | |||||||||||||
| 3 | 4 | ▶ | use 5.006; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 4 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 4 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | |||||||||||||
| 7 | 4 | our $VERSION = '0.02'; | |||||||||||
| 8 | |||||||||||||
| 9 | 4 | ▶ | use Exporter qw(import); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | 4 | our @EXPORT = qw( | |||||||||||
| 11 | process_asset_file | ||||||||||||
| 12 | process_template_file | ||||||||||||
| 13 | process_scss_file | ||||||||||||
| 14 | process_map_file | ||||||||||||
| 15 | ); | ||||||||||||
| 16 | |||||||||||||
| 17 | 4 | ▶ | use Rails::Assets::Formatter qw( | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 18 | format_asset_elem | ||||||||||||
| 19 | format_referral_elem | ||||||||||||
| 20 | format_template_elem | ||||||||||||
| 21 | 4 | ); | |||||||||||
| 22 | |||||||||||||
| 23 | 30 | ▶ | sub process_asset_file { | ||||||||||
|
Subroutine
process_asset_file: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||
| 24 | 30 | my ($filename, $reversed_ext, $assets_hash, $assets_paths) = @_; | |||||||||||
| 25 | 30 | my ($ext) = $filename =~ /(\.[a-zA-Z0-9]+)$/; | |||||||||||
| 26 | 30 | ▶ | my $type = $reversed_ext->{$ext} || 'unknown'; | ||||||||||
|
Condition100%2/2
$reversed_ext->{$ext} || 'unknown'
MC/DC100%1/1
$reversed_ext->{$ext} || 'unknown'
$reversed_ext->{$ext}
Truth table100%2/2
A
A= $reversed_ext->{$ext}
| |||||||||||||
| 27 | |||||||||||||
| 28 | 30 | ▶ | if ($type ne 'unknown'){ | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 29 | 26 | my $elem = format_asset_elem($filename, $ext, $assets_paths); | |||||||||||
| 30 | 26 | push @{$assets_hash->{$type}}, $elem; | |||||||||||
| 31 | } else { | ||||||||||||
| 32 | 4 | ▶ | print "Found unknown type: $ext ($filename)" . "\n" if $ENV{VERBOSE}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 33 | } | ||||||||||||
| 34 | } | ||||||||||||
| 35 | |||||||||||||
| 36 | 12 | ▶ | sub process_template_file { | ||||||||||
|
Subroutine
process_template_file: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||
| 37 | 12 | my ($filename, $template_hash, $template_extensions) = @_; | |||||||||||
| 38 | 12 | my ($ext) = $filename =~ /(\.[a-zA-Z0-9]+)$/; | |||||||||||
| 39 | 12 | ▶ | if (grep /$ext/, @$template_extensions){ | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 40 | |||||||||||||
| 41 | 9 | open FILE, $_; | |||||||||||
| 42 | 9 | ▶ | while (my $line=<FILE>){ | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 43 | 66 | my @stylesheet_tags = $line =~ /stylesheet_link_tag\s*\(*\s*['"](.+?)['"]\s*\)*/g; | |||||||||||
| 44 | 66 | my @javascript_tags = $line =~ /javascript_include_tag\s*\(*\s*['"](.+)['"]\s*\)*/g; | |||||||||||
| 45 | 66 | my @image_tags = $line =~ /asset_path\s*\(*\s*['"](.+?)['"]\s*\)*/g; | |||||||||||
| 46 | |||||||||||||
| 47 | 66 | push @{$template_hash->{stylesheets}}, $_ foreach (map {format_template_elem($filename, $_)} @stylesheet_tags); | |||||||||||
| 48 | 66 | push @{$template_hash->{javascripts}}, $_ foreach (map {format_template_elem($filename, $_)} @javascript_tags); | |||||||||||
| 49 | 66 | push @{$template_hash->{images}}, $_ foreach (map {format_template_elem($filename, $_)} @image_tags); | |||||||||||
| 50 | } | ||||||||||||
| 51 | } else { | ||||||||||||
| 52 | 3 | ▶ | print "Found unknown type: $ext ($filename)" . "\n" if $ENV{VERBOSE}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 53 | } | ||||||||||||
| 54 | } | ||||||||||||
| 55 | |||||||||||||
| 56 | 3 | ▶ | sub process_scss_file { | ||||||||||
|
Subroutine
process_scss_file: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||
| 57 | 3 | my ($filename, $reversed_ext, $scss_hash) = @_; | |||||||||||
| 58 | 3 | open FILE, $filename; | |||||||||||
| 59 | 3 | ▶ | while (my $line=<FILE>){ | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 60 | 24 | my @assets_tags = $line =~ /asset\-url\s*\(*\s*['"](.+?)['"]\s*\)*/g; | |||||||||||
| 61 | 24 | foreach my $asset (@assets_tags){ | |||||||||||
| 62 | 21 | my $clean_name = $asset; | |||||||||||
| 63 | 21 | $clean_name =~ s/([\?#].*)//; | |||||||||||
| 64 | 21 | my ($ext) = $clean_name =~ /(\.[a-zA-Z0-9]+)$/; | |||||||||||
| 65 | 21 | ▶ | my $type = $reversed_ext->{$ext} || 'unknown'; | ||||||||||
|
Condition100%2/2
$reversed_ext->{$ext} || 'unknown'
MC/DC100%1/1
$reversed_ext->{$ext} || 'unknown'
$reversed_ext->{$ext}
Truth table100%2/2
A
A= $reversed_ext->{$ext}
| |||||||||||||
| 66 | 21 | ▶ | if ($type ne 'unknown'){ | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 67 | 18 | my $elem = format_referral_elem($clean_name, $ext, $filename); | |||||||||||
| 68 | 18 | push @{$scss_hash->{$type}}, $elem; | |||||||||||
| 69 | } else { | ||||||||||||
| 70 | 3 | ▶ | print "Found unknown type: $ext ($filename)" . "\n" if $ENV{VERBOSE}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 71 | } | ||||||||||||
| 72 | }; | ||||||||||||
| 73 | } | ||||||||||||
| 74 | } | ||||||||||||
| 75 | |||||||||||||
| 76 | 8 | ▶ | sub process_map_file { | ||||||||||
|
Subroutine
process_map_file: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||
| 77 | 8 | my ($filename, $reversed_ext, $map_hash) = @_; | |||||||||||
| 78 | 8 | open FILE, $_; | |||||||||||
| 79 | 8 | ▶ | while (my $line=<FILE>){ | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 80 | 4 | my @assets_tags = $line =~ /sourceMappingURL=(.+\.map?)/; | |||||||||||
| 81 | 4 | foreach my $asset (@assets_tags){ | |||||||||||
| 82 | 4 | my $clean_name = $asset; | |||||||||||
| 83 | 4 | $clean_name =~ s/([\?#].*)//; | |||||||||||
| 84 | 4 | my ($ext) = $clean_name =~ /(\.[a-zA-Z0-9]+)$/; | |||||||||||
| 85 | 4 | ▶ | my $type = $reversed_ext->{$ext} || 'unknown'; | ||||||||||
|
Condition100%2/2
$reversed_ext->{$ext} || 'unknown'
MC/DC100%1/1
$reversed_ext->{$ext} || 'unknown'
$reversed_ext->{$ext}
Truth table100%2/2
A
A= $reversed_ext->{$ext}
| |||||||||||||
| 86 | 4 | ▶ | if ($type ne 'unknown'){ | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 87 | 2 | my $elem = format_referral_elem($clean_name, $ext, $filename); | |||||||||||
| 88 | 2 | push @{$map_hash->{$type}}, $elem; | |||||||||||
| 89 | } else { | ||||||||||||
| 90 | 2 | ▶ | print "Found unknown type: $ext ($filename)" . "\n" if $ENV{VERBOSE}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 91 | } | ||||||||||||
| 92 | }; | ||||||||||||
| 93 | } | ||||||||||||
| 94 | } | ||||||||||||
| 95 | } | ||||||||||||
| 96 | |||||||||||||
| 97 | =head1 NAME | ||||||||||||
| 98 | |||||||||||||
| 99 | Rails::Assets::Processor - Processing Functions for Rails::Assets | ||||||||||||
| 100 | |||||||||||||
| 101 | =head1 VERSION | ||||||||||||
| 102 | |||||||||||||
| 103 | Version 0.02 | ||||||||||||
| 104 | |||||||||||||
| 105 | =head1 SYNOPSIS | ||||||||||||
| 106 | |||||||||||||
| 107 | This module contains some functions for processing data references. | ||||||||||||
| 108 | |||||||||||||
| 109 | use Rails::Assets::Processor; | ||||||||||||
| 110 | |||||||||||||
| 111 | process_template_file($_, $template_hash, $template_extensions) foreach @{find_files($template_directories)}; | ||||||||||||
| 112 | process_asset_file($_, $reversed_ext, $assets_hash, $assets_paths) foreach @{find_files($assets_directories)}; | ||||||||||||
| 113 | |||||||||||||
| 114 | my $scss_files = [grep { $_->{ext} eq '.scss' } @{$assets_hash->{stylesheets}}]; | ||||||||||||
| 115 | my $js_files = [grep { $_->{ext} eq '.js' } @{$assets_hash->{javascripts}}]; | ||||||||||||
| 116 | |||||||||||||
| 117 | process_scss_file($_, $reversed_ext, $scss_hash) foreach map {$_->{full_path}} @{$scss_files}; | ||||||||||||
| 118 | process_map_file($_, , $reversed_ext, $map_hash) foreach map {$_->{full_path}} @{$js_files}; | ||||||||||||
| 119 | ... | ||||||||||||
| 120 | |||||||||||||
| 121 | =head1 EXPORT | ||||||||||||
| 122 | |||||||||||||
| 123 | =head2 process_asset_file | ||||||||||||
| 124 | |||||||||||||
| 125 | This function find the file extension, assign a file type based on C<$reversed_ext> and pushed a formatted element into C<<< @{$assets_hash->{$type}} >>> | ||||||||||||
| 126 | |||||||||||||
| 127 | =head2 process_template_file | ||||||||||||
| 128 | |||||||||||||
| 129 | This function parse template files, extract the references to assets, find the file extension, assign a file type based on C<$reversed_ext> and pushed a formatted element into C<<< @{$template_hash->{$type}} >>> | ||||||||||||
| 130 | |||||||||||||
| 131 | =head2 process_scss_file | ||||||||||||
| 132 | |||||||||||||
| 133 | This function parse scss files, extract the references to assets, find the file extension, assign a file type based on C<$reversed_ext> and pushed a formatted element into C<<< @{$scss_hash->{$type}} >>> | ||||||||||||
| 134 | |||||||||||||
| 135 | =head2 process_map_file | ||||||||||||
| 136 | |||||||||||||
| 137 | This function parse javascript files, extract the references to .js.map files, assign a file type based on C<$reversed_ext> and pushed a formatted element into C<<< @{$map_hash->{$type}} >>> | ||||||||||||
| 138 | |||||||||||||
| 139 | |||||||||||||
| 140 | =head1 SUBROUTINES/METHODS | ||||||||||||
| 141 | |||||||||||||
| 142 | =head1 AUTHOR | ||||||||||||
| 143 | |||||||||||||
| 144 | Mauro Berlanda, C<< <kupta at cpan.org> >> | ||||||||||||
| 145 | |||||||||||||
| 146 | =head1 BUGS | ||||||||||||
| 147 | |||||||||||||
| 148 | Please report any bugs or feature requests to C<bug-rails-assets at rt.cpan.org>, or through | ||||||||||||
| 149 | the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Rails-Assets>. I will be notified, and then you'll | ||||||||||||
| 150 | automatically be notified of progress on your bug as I make changes. | ||||||||||||
| 151 | |||||||||||||
| 152 | Pull Requests, Issues, Stars and Forks on the project L<github repository|https://github.com/mberlanda/rails-assets-coverage> are welcome! | ||||||||||||
| 153 | |||||||||||||
| 154 | |||||||||||||
| 155 | =head1 SUPPORT | ||||||||||||
| 156 | |||||||||||||
| 157 | You can find documentation for this module with the perldoc command. | ||||||||||||
| 158 | |||||||||||||
| 159 | perldoc Rails::Assets::Processor | ||||||||||||
| 160 | |||||||||||||
| 161 | You can also look for information at: | ||||||||||||
| 162 | |||||||||||||
| 163 | =over 4 | ||||||||||||
| 164 | |||||||||||||
| 165 | =item * RT: CPAN's request tracker (report bugs here) | ||||||||||||
| 166 | |||||||||||||
| 167 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=.> | ||||||||||||
| 168 | |||||||||||||
| 169 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||||
| 170 | |||||||||||||
| 171 | L<http://annocpan.org/dist/.> | ||||||||||||
| 172 | |||||||||||||
| 173 | =item * CPAN Ratings | ||||||||||||
| 174 | |||||||||||||
| 175 | L<http://cpanratings.perl.org/d/.> | ||||||||||||
| 176 | |||||||||||||
| 177 | =item * Search CPAN | ||||||||||||
| 178 | |||||||||||||
| 179 | L<http://search.cpan.org/dist/./> | ||||||||||||
| 180 | |||||||||||||
| 181 | =back | ||||||||||||
| 182 | |||||||||||||
| 183 | =head1 ACKNOWLEDGEMENTS | ||||||||||||
| 184 | |||||||||||||
| 185 | =head1 LICENSE AND COPYRIGHT | ||||||||||||
| 186 | |||||||||||||
| 187 | Copyright 2017 Mauro Berlanda. | ||||||||||||
| 188 | |||||||||||||
| 189 | This program is free software; you can redistribute it and/or modify it | ||||||||||||
| 190 | under the terms of the the Artistic License (2.0). You may obtain a | ||||||||||||
| 191 | copy of the full license at: | ||||||||||||
| 192 | |||||||||||||
| 193 | L<http://www.perlfoundation.org/artistic_license_2_0> | ||||||||||||
| 194 | |||||||||||||
| 195 | Any use, modification, and distribution of the Standard or Modified | ||||||||||||
| 196 | Versions is governed by this Artistic License. By using, modifying or | ||||||||||||
| 197 | distributing the Package, you accept this license. Do not use, modify, | ||||||||||||
| 198 | or distribute the Package, if you do not accept this license. | ||||||||||||
| 199 | |||||||||||||
| 200 | If your Modified Version has been derived from a Modified Version made | ||||||||||||
| 201 | by someone other than you, you are nevertheless required to ensure that | ||||||||||||
| 202 | your Modified Version complies with the requirements of this license. | ||||||||||||
| 203 | |||||||||||||
| 204 | This license does not grant you the right to use any trademark, service | ||||||||||||
| 205 | mark, tradename, or logo of the Copyright Holder. | ||||||||||||
| 206 | |||||||||||||
| 207 | This license includes the non-exclusive, worldwide, free-of-charge | ||||||||||||
| 208 | patent license to make, have made, use, offer to sell, sell, import and | ||||||||||||
| 209 | otherwise transfer the Package with respect to any patent claims | ||||||||||||
| 210 | licensable by the Copyright Holder that are necessarily infringed by the | ||||||||||||
| 211 | Package. If you institute patent litigation (including a cross-claim or | ||||||||||||
| 212 | counterclaim) against any party alleging that the Package constitutes | ||||||||||||
| 213 | direct or contributory patent infringement, then this Artistic License | ||||||||||||
| 214 | to you shall terminate on the date that such litigation is filed. | ||||||||||||
| 215 | |||||||||||||
| 216 | Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER | ||||||||||||
| 217 | AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. | ||||||||||||
| 218 | THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR | ||||||||||||
| 219 | PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY | ||||||||||||
| 220 | YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR | ||||||||||||
| 221 | CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR | ||||||||||||
| 222 | CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, | ||||||||||||
| 223 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||||||||||||
| 224 | |||||||||||||
| 225 | =cut | ||||||||||||
| 226 | |||||||||||||
| 227 | 4 | 1; # End of Rails::Assets::Processor | |||||||||||