1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
package Mojolicious::Plugin::AssetPack::Pipe::Riotjs;
use Mojo::Base 'Mojolicious::Plugin::AssetPack::Pipe';
use Mojo::File 'path';
use Mojolicious::Plugin::AssetPack::Util qw(diag $CWD DEBUG);
has _riotjs => sub { [shift->_find_app([qw(nodejs node)]), path(__FILE__)->dirname->child('riot.js')] };
sub process {
my ($self, $assets) = @_;
my $store = $self->assetpack->store;
my $file;
$assets->each(sub {
my ($asset, $index) = @_;
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 = $store->load($attrs);
local $CWD = $self->app->home->to_string;
local $ENV{NODE_PATH} = $self->app->home->rel_file('node_modules');
$self->run([qw(riot --version)], undef, \undef) unless $self->{installed}++;
$self->run($self->_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('node_modules/.bin/riot');
return $path if -e $path;
local $CWD = $self->app->home->to_string;
$self->app->log->warn('Installing riot... Please wait. (npm install riot)');
$self->run([qw(npm install riot)]);
return $path;
}
1;
=encoding utf8
=head1 NAME
Mojolicious::Plugin::AssetPack::Pipe::Riotjs - Process Riotjs .tag files
=head1 SYNOPSIS
use Mojolicious::Lite;
plugin AssetPack => {pipes => [qw(Riotjs JavaScript)]};
Note that the above will not load the other default pipes, such as
L<Mojolicious::Plugin::AssetPack::Pipe::Css>.
=head1 DESCRIPTION
L<Mojolicious::Plugin::AssetPack::Pipe::Riotjs> will process
L<http://riotjs.com/> ".tag" files.
This module require L<https://www.npmjs.com/> to compile Riotjs tag files.
=head1 METHODS
=head2 process
See L<Mojolicious::Plugin::AssetPack::Pipe/process>.
=head1 SEE ALSO
L<Mojolicious::Plugin::AssetPack>.
=cut
|