ave an asset to disk. C<%attr> are usually the same as
L<Mojolicious::Plugin::AssetPack::Asset/TO_JSON> and used to document metadata
about the C<$asset> so it can be looked up using L</load>.
=head2
y $asset (@$assets) {
@import "<%= $asset->url_for($c) %>";
% }
@@ fallback.js.ep
% use Mojo::JSON 'to_json';
(function(w,d,a,b){
var c=function(){
var t=d.createElement("script");
t.src=b.shift();
if
(b.length) t.addEventListener("load",c);
a.parentNode.insertBefore(t,a);
};
c();
})(window,document,document.getElementsByTagName("script")[0],<%= to_json([map { $_->url_for($c) } @$assets]) %>);
my $attrs = $asset->TO_JSON;
$attrs->{key} = 'ts';
$attrs->{format} = 'js';
return unless $asset->format eq 'ts';
return $asset->content($file)->FROM_JSON($attrs) if $file = $stor
f->_typescript, \$asset->content, \my $js);
$asset->content($store->save(\$js, $attrs))->FROM_JSON($attrs);
});
}
sub _install_typescript {
my $self = shift;
# TODO: This is a bit fragile,
ck->minify;
return $assets->each(sub {
my ($asset, $index) = @_;
my $attrs = $asset->TO_JSON;
$attrs->{key} = 'js-min';
$attrs->{minified} = 1;
return if $asset->format ne '
my $file;
return $assets->each(sub {
my ($asset, $index) = @_;
my $attrs = $asset->TO_JSON;
$attrs->{key} = sprintf '%s-min', $self->app;
$attrs->{minified} = 1;
return if
rs->{checksum} if DEBUG;
$asset->content($store->save($self->_run_app($asset), $attrs))->FROM_JSON($attrs);
});
}
sub _install_optipng {
my $self = shift;
my $class = ref $self;
my $app
:Base 'Mojolicious::Plugin::AssetPack::Pipe';
use Mojo::File qw(path tempfile);
use Mojo::JSON qw(encode_json false true);
use Mojo::Loader;
use Mojolicious::Plugin::AssetPack::Util qw(diag $CWD DEBU
f '%s(%s)', $func, defined $args ? encode_json $args : '';
}
$bin =~ s!__EXTERNAL__!{encode_json $self->external}!e;
$bin =~ s!__GLOBALS__!{encode_json $self->globals}!e;
$bin =~ s!__SOURCEMA
s _rollupjs_src);
$assets->each(sub {
my ($asset, $index) = @_;
my $attrs = $asset->TO_JSON;
return unless $asset->format eq 'js';
return unless $asset->path and -r $asset->path;
ck->minify;
return $assets->each(sub {
my ($asset, $index) = @_;
my $attrs = $asset->TO_JSON;
$attrs->{key} = 'css-min';
$attrs->{minified} = 1;
return if $asset->format ne
;
use File::Temp ();
use IPC::Run3 ();
use List::Util 'first';
use Mojo::File 'path';
use Mojo::JSON;
use Mojolicious::Plugin::AssetPack::Asset;
use Mojolicious::Plugin::AssetPack::Util qw(diag has_
ind_app([qw(nodejs node)]), $REQUIRE_JS, @modules], \undef, \my $status);
$status = Mojo::JSON::decode_json($status);
for my $plugin (@modules) {
next unless $status->{$plugin};
$self->ap
# Change $attr if this pipe will modify $asset attributes
my $attr = $asset->TO_JSON;
my $content = $asset->content;
# Private name to load/save meta data under
::Pipe::Favicon;
use Mojo::Base 'Mojolicious::Plugin::AssetPack::Pipe';
use Mojo::DOM;
use Mojo::JSON qw(false true);
use Mojo::Template;
use Mojo::Util;
use Mojolicious::Plugin::AssetPack::Util 'che
sign => sub { shift->_build_design };
has settings => sub { +{error_on_image_too_small => Mojo::JSON->true} };
sub process {
my ($self, $assets) = @_;
return unless $self->topic =~ m!^favicon(\
my $asset = $assets->first;
my $attrs = $asset->TO_JSON;
my ($urls, $markup, %sub_assets);
$attrs->{key} = checksum(Mojo::JSON::encode_json($self->design))
or die '[AssetPack] Invalid pipe
$asset->format ne 'less';
my $attrs = $asset->TO_JSON;
@$attrs{qw(format key)} = qw(css less);
return $asset->content($file)->FROM_JSON($attrs) if $file = $store->load($attrs);
diag 'P
;
$self->run(\@args, undef, \my $css);
$asset->content($store->save(\$css, $attrs))->FROM_JSON($attrs);
});
}
sub _install_lessc {
my $self = shift;
my $bin = $self->app->home->rel_fil
my $file;
return $assets->each(sub {
my ($asset, $index) = @_;
my $attrs = $asset->TO_JSON;
$attrs->{key} = sprintf '%s-min', $self->app;
$attrs->{minified} = 1;
return if
rs->{checksum} if DEBUG;
$asset->content($store->save($self->_run_app($asset), $attrs))->FROM_JSON($attrs);
});
}
sub _install_jpegoptim {
my $self = shift;
my $class = ref $self;
die "$
my $attrs = $asset->TO_JSON;
$attrs->{key} = 'riot';
$attrs->{format} = 'js';
return unless $asset->format eq 'tag';
return $asset->content($file)->FROM_JSON($attrs) if $file = $st
>_riotjs, \$asset->content, \my $js);
$asset->content($store->save(\$js, $attrs))->FROM_JSON($attrs);
});
}
sub _install_riot {
my $self = shift;
my $path = $self->app->home->rel_file
ssetPack::Util qw(checksum diag dumper load_module DEBUG);
use Mojo::File;
use Mojo::JSON qw(decode_json encode_json);
use Mojo::Util;
my $FORMAT_RE = qr{^s[ac]ss$};
my $IMPORT_RE
index) = @_;
return if $asset->format !~ $FORMAT_RE;
my ($attrs, $content) = ($asset->TO_JSON, $asset->content);
local $self->{checksum_for_file} = {};
local $opts{include_paths}[0] =
elf->_checksum(\$content, $asset, $opts{include_paths});
return $asset->content($file)->FROM_JSON($attrs) if $file = $store->load($attrs);
return if $asset->isa('Mojolicious::Plugin::AssetPac
elf->assetpack->process($related->name, $related);
my $path = $route->render($related->TO_JSON);
$path =~ s!^/!!;
my $up = join '', map {'../'} $path =~ m!\/!g;
$relate
sset->format ne 'coffee';
my $attrs = $asset->TO_JSON;
@$attrs{qw(format key)} = qw(js coffee);
return $asset->content($file)->FROM_JSON($attrs) if $file = $store->load($attrs);
diag '
pile --stdio)], \$asset->content, \my $js);
$asset->content($store->save(\$js, $attrs))->FROM_JSON($attrs);
});
}
sub _install_coffee {
my $self = shift;
my $path = $self->app->home->rel_fi
n undef;
}
sub size { $_[0]->_asset->size }
sub url_for { $_[1]->url_for(assetpack => $_[0]->TO_JSON); }
sub _default_tag_for {
my ($asset, $c, $args, @attrs) = @_;
my $url = $asset->url_f
rl"), @attrs);
}
sub FROM_JSON {
my ($self, $attrs) = @_;
$self->$_($attrs->{$_}) for grep { defined $attrs->{$_} } qw(checksum format minified);
$self;
}
sub TO_JSON {
return {map { ($_ =>
OM_JSON
$self = $self->FROM_JSON($hash_ref);
The opposite of L</TO_JSON>. Will set the read/write L</ATTRIBUTES> from the
values in C<$hash_ref>.
=head2 TO_JSON
$hash_ref = $self->FROM_JSON;