| 1 | 5 | package Rails::Assets::Formatter { | |
| 2 | |||
| 3 | 5 | ▶ | use 5.006; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 5 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 5 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | |||
| 7 | 5 | our $VERSION = '0.02'; | |
| 8 | 5 | ▶ | use Exporter qw(import); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | 5 | our @EXPORT = qw( | |
| 10 | format_asset_elem | ||
| 11 | format_referral_elem | ||
| 12 | format_template_elem | ||
| 13 | ); | ||
| 14 | |||
| 15 | 27 | ▶ | sub format_asset_elem { |
|
Subroutine
format_asset_elem: called CC=2 SCAR=6.9
Pod
documented
| |||
| 16 | 27 | my ($asset_file, $ext, $assets_paths) = @_; | |
| 17 | 27 | my $asset_name = $asset_file; | |
| 18 | 27 | $asset_name =~ s/$_// foreach (@$assets_paths); | |
| 19 | return { | ||
| 20 | 27 | name => $asset_name, | |
| 21 | full_path => $asset_file, | ||
| 22 | ext => $ext, | ||
| 23 | }; | ||
| 24 | } | ||
| 25 | |||
| 26 | 21 | ▶ | sub format_referral_elem { |
|
Subroutine
format_referral_elem: called CC=1 SCAR=0.0
Pod
documented
| |||
| 27 | 21 | my ($asset_name, $ext, $referral) = @_; | |
| 28 | return { | ||
| 29 | 21 | name => $asset_name, | |
| 30 | referral => $referral, | ||
| 31 | ext => $ext, | ||
| 32 | }; | ||
| 33 | } | ||
| 34 | |||
| 35 | 22 | ▶ | sub format_template_elem { |
|
Subroutine
format_template_elem: called CC=1 SCAR=0.0
Pod
documented
| |||
| 36 | 22 | my ($template_file, $asset_name) = @_; | |
| 37 | return { | ||
| 38 | 22 | name => $asset_name, | |
| 39 | full_path => $template_file, | ||
| 40 | } | ||
| 41 | } | ||
| 42 | } | ||
| 43 | |||
| 44 | =head1 NAME | ||
| 45 | |||
| 46 | Rails::Assets::Formatter - Formatting Functions for Rails::Assets. | ||
| 47 | |||
| 48 | =head1 VERSION | ||
| 49 | |||
| 50 | Version 0.02 | ||
| 51 | |||
| 52 | =head1 SYNOPSIS | ||
| 53 | |||
| 54 | This module provide some utility functions for formatting data structures while parsing assets. | ||
| 55 | |||
| 56 | use Rails::Assets::Formatter; | ||
| 57 | |||
| 58 | my $a = format_asset_elem($asset_file, $ext, $assets_paths); | ||
| 59 | my $b = format_referral_elem($asset_file, $ext, $referral); | ||
| 60 | my $c = format_template_elem($template_file, $asset_name); | ||
| 61 | ... | ||
| 62 | |||
| 63 | =head1 EXPORT | ||
| 64 | |||
| 65 | =head2 format_asset_elem | ||
| 66 | |||
| 67 | Takes C<($asset_file, $ext, $assets_paths)> as arguments where : | ||
| 68 | |||
| 69 | =over 3 | ||
| 70 | |||
| 71 | =item * C<$asset_file> is the file name (scalar) | ||
| 72 | |||
| 73 | =item * C<$ext> is the file extension (scalar) | ||
| 74 | |||
| 75 | =item * C<$assets_paths> is Array reference containing C<$Rails::Assets::ASSETS_DIR> and their subfolders named as C<$assets> keys | ||
| 76 | |||
| 77 | =back | ||
| 78 | |||
| 79 | Returns the following data structure: | ||
| 80 | |||
| 81 | my $output = { | ||
| 82 | name => $asset_name, | ||
| 83 | full_path => $asset_file, | ||
| 84 | ext => $ext, | ||
| 85 | }; | ||
| 86 | |||
| 87 | =head2 format_referral_elem | ||
| 88 | |||
| 89 | Takes three strings C<($asset_file, $ext, $referral)> as arguments and returns the following data structure: | ||
| 90 | |||
| 91 | my $output = { | ||
| 92 | name => $asset_name, | ||
| 93 | referral => $referral, | ||
| 94 | ext => $ext, | ||
| 95 | }; | ||
| 96 | |||
| 97 | =head2 format_template_elem | ||
| 98 | |||
| 99 | Takes two strings C<($template_file, $asset_name)> as arguments and returns the following data structure: | ||
| 100 | |||
| 101 | my $output = { | ||
| 102 | name => $asset_name, | ||
| 103 | full_path => $template_file, | ||
| 104 | }; | ||
| 105 | |||
| 106 | =head1 SUBROUTINES/METHODS | ||
| 107 | |||
| 108 | =head1 AUTHOR | ||
| 109 | |||
| 110 | Mauro Berlanda, C<< <kupta at cpan.org> >> | ||
| 111 | |||
| 112 | =head1 BUGS | ||
| 113 | |||
| 114 | Please report any bugs or feature requests to C<bug-rails-assets at rt.cpan.org>, or through | ||
| 115 | the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Rails-Assets>. I will be notified, and then you'll | ||
| 116 | automatically be notified of progress on your bug as I make changes. | ||
| 117 | |||
| 118 | Pull Requests, Issues, Stars and Forks on the project L<github repository|https://github.com/mberlanda/rails-assets-coverage> are welcome! | ||
| 119 | |||
| 120 | =head1 SUPPORT | ||
| 121 | |||
| 122 | You can find documentation for this module with the perldoc command. | ||
| 123 | |||
| 124 | perldoc Rails::Assets::Formatter | ||
| 125 | |||
| 126 | You can also look for information at: | ||
| 127 | |||
| 128 | =over 4 | ||
| 129 | |||
| 130 | =item * RT: CPAN's request tracker (report bugs here) | ||
| 131 | |||
| 132 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=.> | ||
| 133 | |||
| 134 | =item * AnnoCPAN: Annotated CPAN documentation | ||
| 135 | |||
| 136 | L<http://annocpan.org/dist/.> | ||
| 137 | |||
| 138 | =item * CPAN Ratings | ||
| 139 | |||
| 140 | L<http://cpanratings.perl.org/d/.> | ||
| 141 | |||
| 142 | =item * Search CPAN | ||
| 143 | |||
| 144 | L<http://search.cpan.org/dist/./> | ||
| 145 | |||
| 146 | =back | ||
| 147 | |||
| 148 | =head1 ACKNOWLEDGEMENTS | ||
| 149 | |||
| 150 | =head1 LICENSE AND COPYRIGHT | ||
| 151 | |||
| 152 | Copyright 2017 Mauro Berlanda. | ||
| 153 | |||
| 154 | This program is free software; you can redistribute it and/or modify it | ||
| 155 | under the terms of the the Artistic License (2.0). You may obtain a | ||
| 156 | copy of the full license at: | ||
| 157 | |||
| 158 | L<http://www.perlfoundation.org/artistic_license_2_0> | ||
| 159 | |||
| 160 | Any use, modification, and distribution of the Standard or Modified | ||
| 161 | Versions is governed by this Artistic License. By using, modifying or | ||
| 162 | distributing the Package, you accept this license. Do not use, modify, | ||
| 163 | or distribute the Package, if you do not accept this license. | ||
| 164 | |||
| 165 | If your Modified Version has been derived from a Modified Version made | ||
| 166 | by someone other than you, you are nevertheless required to ensure that | ||
| 167 | your Modified Version complies with the requirements of this license. | ||
| 168 | |||
| 169 | This license does not grant you the right to use any trademark, service | ||
| 170 | mark, tradename, or logo of the Copyright Holder. | ||
| 171 | |||
| 172 | This license includes the non-exclusive, worldwide, free-of-charge | ||
| 173 | patent license to make, have made, use, offer to sell, sell, import and | ||
| 174 | otherwise transfer the Package with respect to any patent claims | ||
| 175 | licensable by the Copyright Holder that are necessarily infringed by the | ||
| 176 | Package. If you institute patent litigation (including a cross-claim or | ||
| 177 | counterclaim) against any party alleging that the Package constitutes | ||
| 178 | direct or contributory patent infringement, then this Artistic License | ||
| 179 | to you shall terminate on the date that such litigation is filed. | ||
| 180 | |||
| 181 | Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER | ||
| 182 | AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. | ||
| 183 | THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR | ||
| 184 | PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY | ||
| 185 | YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR | ||
| 186 | CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR | ||
| 187 | CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, | ||
| 188 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 189 | |||
| 190 | =cut | ||
| 191 | |||
| 192 | 5 | 1; # End of Rails::Assets::Formatter | |