Rails::Assets - Class for Rails Projects Assets Analysis.
Version 0.02
This module provides an object for parsing Assets directories
use Rails::Assets; my $assets = Rails::Assets->new(); my $template_directories = $assets->template_dir(); my $template_extensions = $assets->template_ext(); my $assets_directories = $assets->assets_dir(); my $assets_extensions = $assets->assets_ext(); $assets->analyse(); ...
You can find a sample script in the project github repository
The constructor takes no argument for now. It would be interesting to add additional paths and extensions in the future. This would require some validation and it could be quite tricky.
use Rails::Assets; my $assets = Rails::Assets->new();
At the current state, you can modify the defaults as follows:
#!usr/bin/perl -t use strict; use warnings; use Test::More tests => 3; use Test::Deep; use Rails::Assets; DEFAULT: { my $default_dir = [qw( app/views/ )]; is_deeply($Rails::Assets::TEMPLATE_DIR, $default_dir, '$Rails::Assets::TEMPLATE_DIR has the expected default' ); my $assets = Rails::Assets->new; is_deeply($assets->template_dir, $default_dir, 'Rails::Assets instance has default template_dir()' ); } CUSTOM: { push @$Rails::Assets::TEMPLATE_DIR, 'app/folder/'; my $expected_dir = [qw( app/views/ app/folder/ )]; my $assets = Rails::Assets->new; is_deeply($assets->template_dir, $expected_dir, 'Rails::Assets instance template_dir() changes according to $Rails::Assets::TEMPLATE_DIR'); }
Getter for template directories. It is a copy of $Rails::Assets::TEMPLATE_DIR reference
$Rails::Assets::TEMPLATE_DIR
my $template_directories = [qw( app/views/)]; is_deeply( $Rails::Assets::TEMPLATE_DIR, $template_directories); is_deeply( $assets->template_dir(), $template_directories);
Getter for template extensions. It is a copy of $Rails::Assets::TEMPLATE_EXT reference
$Rails::Assets::TEMPLATE_EXT
my $template_extensions = [qw(.haml .erb)]; is_deeply( $Rails::Assets::TEMPLATE_EXT, $template_extensions); is_deeply( $assets->template_ext(), $template_extensions);
Getter for assets directions. It is a copy of $Rails::Assets::ASSETS_DIR reference
$Rails::Assets::ASSETS_DIR
my $assets_directories = [qw( app/assets/ public/ vendor/assets/ )]; is_deeply( $Rails::Assets::ASSETS_DIR, $assets_directories); is_deeply( $assets->assets_dir(), $assets_directories);
Getter for assets extensions. It is a copy of $Rails::Assets::ASSETS_EXT reference
$Rails::Assets::ASSETS_EXT
my $assets_extensions = { fonts => [qw(.woff2 .woff .ttf .eot .otf)], images => [qw(.png .jpg .gif .svg .ico)], javascripts => [qw(.js .map)], stylesheets => [qw(.css .scss)], }; is_deeply( $Rails::Assets::ASSETS_EXT, $assets_extensions); is_deeply( $assets->assets_ext(), $assets_extensions);
undef by default. Hash reference initialized by $assets-analyse()> with keys fonts, images, javascripts, stylesheets
undef
$assets-
see assets_hash
undef by default. Array reference containing $Rails::Assets::ASSETS_DIR and their subfolders named as assets_hash keys
my $expected_paths = [qw( app/assets/fonts/ app/assets/javascripts/ app/assets/stylesheets/ app/assets/ public/ vendor/assets/fonts/ vendor/assets/javascripts/ vendor/assets/stylesheets/ vendor/assets/ )]; is_deeply($assets->assets_paths(), $expected_paths);
undef by default. Hash reference created reversing key value of $assets_hash
$assets_hash
is_deeply( [sort keys %{$assets->reversed_ext()}], [sort map {@$_} values %{$assets->assets_ext()}] );
Method that perform analysis. It populate all the references above
Mauro Berlanda, <kupta at cpan.org>
<kupta at cpan.org>
Please report any bugs or feature requests to bug-rails-assets at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Rails-Assets. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-rails-assets at rt.cpan.org
Pull Requests, Issues, Stars and Forks on the project github repository are welcome!
You can find documentation for this module with the perldoc command.
perldoc Rails::Assets
You can also look for information at:
RT: CPAN's request tracker (report bugs here)
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Rails-Assets
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Rails-Assets
CPAN Ratings
http://cpanratings.perl.org/d/Rails-Assets
Search CPAN
http://search.cpan.org/dist/Rails-Assets/
Copyright 2017 Mauro Berlanda.
This program is free software; you can redistribute it and/or modify it under the terms of the the Artistic License (2.0). You may obtain a copy of the full license at:
http://www.perlfoundation.org/artistic_license_2_0
Any use, modification, and distribution of the Standard or Modified Versions is governed by this Artistic License. By using, modifying or distributing the Package, you accept this license. Do not use, modify, or distribute the Package, if you do not accept this license.
If your Modified Version has been derived from a Modified Version made by someone other than you, you are nevertheless required to ensure that your Modified Version complies with the requirements of this license.
This license does not grant you the right to use any trademark, service mark, tradename, or logo of the Copyright Holder.
This license includes the non-exclusive, worldwide, free-of-charge patent license to make, have made, use, offer to sell, sell, import and otherwise transfer the Package with respect to any patent claims licensable by the Copyright Holder that are necessarily infringed by the Package. If you institute patent litigation (including a cross-claim or counterclaim) against any party alleging that the Package constitutes direct or contributory patent infringement, then this Artistic License to you shall terminate on the date that such litigation is filed.
Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
To install Rails::Assets, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Rails::Assets
CPAN shell
perl -MCPAN -e shell install Rails::Assets
For more information on module installation, please visit the detailed CPAN module installation guide.