| 1 | package Mojolicious::Plugin::AssetPack::Pipe::Combine; | ||||||||||||||
| 2 | 9 | ▶ | use Mojo::Base 'Mojolicious::Plugin::AssetPack::Pipe'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 3 | |||||||||||||||
| 4 | 9 | ▶ | use Mojolicious::Plugin::AssetPack::Util qw(checksum diag DEBUG); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | |||||||||||||||
| 6 | 9 | ▶ | has enabled => sub { shift->assetpack->minify }; | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | |||||||||||||||
| 8 | 13 | ▶ | sub process { | ||||||||||||
|
Subroutine
process: called CC=6 SCAR=18.3
Pod
documented
| |||||||||||||||
| 9 | 13 | my ($self, $assets) = @_; | |||||||||||||
| 10 | 13 | my $combine = Mojo::Collection->new; | |||||||||||||
| 11 | 13 | my @other; | |||||||||||||
| 12 | |||||||||||||||
| 13 | 13 | ▶ | return unless $self->enabled; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 14 | |||||||||||||||
| 15 | 7 | for my $asset (@$assets) { | |||||||||||||
| 16 | 13 | ▶ | if ($asset->isa('Mojolicious::Plugin::AssetPack::Asset::Null')) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 17 | 0 | next; | |||||||||||||
| 18 | } | ||||||||||||||
| 19 | 26 | elsif (grep { $asset->format eq $_ } qw(css js)) { | |||||||||||||
| 20 | 13 | push @$combine, $asset; | |||||||||||||
| 21 | } | ||||||||||||||
| 22 | else { | ||||||||||||||
| 23 | 0 | push @other, $asset; | |||||||||||||
| 24 | } | ||||||||||||||
| 25 | } | ||||||||||||||
| 26 | |||||||||||||||
| 27 | # preserve assets such as images and font files | ||||||||||||||
| 28 | 7 | @$assets = @other; | |||||||||||||
| 29 | |||||||||||||||
| 30 | 7 | ▶ | if (@$combine) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 31 | 7 | my $checksum = checksum $combine->map('checksum')->join(':'); | |||||||||||||
| 32 | 7 | ▶ | my $content = $combine->map('content')->map(sub { /\n$/ ? $_ : "$_\n" })->join; | ||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||
| 33 | 7 | diag 'Combining assets into "%s" with checksum %s.', $self->topic, $checksum if DEBUG; | |||||||||||||
| 34 | 7 | push @$assets, | |||||||||||||
| 35 | Mojolicious::Plugin::AssetPack::Asset->new(url => $self->topic)->checksum($checksum)->minified(1) | ||||||||||||||
| 36 | ->content($content); | ||||||||||||||
| 37 | } | ||||||||||||||
| 38 | } | ||||||||||||||
| 39 | |||||||||||||||
| 40 | 9 | 1; | |||||||||||||
| 41 | |||||||||||||||
| 42 | =encoding utf8 | ||||||||||||||
| 43 | |||||||||||||||
| 44 | =head1 NAME | ||||||||||||||
| 45 | |||||||||||||||
| 46 | Mojolicious::Plugin::AssetPack::Pipe::Combine - Combine multiple assets to one | ||||||||||||||
| 47 | |||||||||||||||
| 48 | =head1 DESCRIPTION | ||||||||||||||
| 49 | |||||||||||||||
| 50 | L<Mojolicious::Plugin::AssetPack::Pipe::Combine> will take a list of | ||||||||||||||
| 51 | assets and turn them into a single asset. | ||||||||||||||
| 52 | |||||||||||||||
| 53 | =head1 ATTRIBUTES | ||||||||||||||
| 54 | |||||||||||||||
| 55 | $bool = $self->enabled; | ||||||||||||||
| 56 | |||||||||||||||
| 57 | Set this to false to disable combining assets into a single file. The default | ||||||||||||||
| 58 | value will be L<Mojolicious::Plugin::AssetPack/minify>. | ||||||||||||||
| 59 | |||||||||||||||
| 60 | =head1 METHODS | ||||||||||||||
| 61 | |||||||||||||||
| 62 | =head2 process | ||||||||||||||
| 63 | |||||||||||||||
| 64 | See L<Mojolicious::Plugin::AssetPack::Pipe/process>. | ||||||||||||||
| 65 | |||||||||||||||
| 66 | =head1 SEE ALSO | ||||||||||||||
| 67 | |||||||||||||||
| 68 | L<Mojolicious::Plugin::AssetPack>. | ||||||||||||||
| 69 | |||||||||||||||
| 70 | =cut | ||||||||||||||