add files
|
1 |
package Mojolicious::Command::inflate; |
2 |
use Mojo::Base 'Mojolicious::Command'; |
|
3 | ||
4 |
use Mojo::Loader; |
|
5 |
use Mojo::Util 'encode'; |
|
6 | ||
7 |
has description => "Inflate embedded files to real files.\n"; |
|
8 |
has usage => "usage: $0 inflate\n"; |
|
9 | ||
10 |
sub run { |
|
11 |
my $self = shift; |
|
12 | ||
13 |
# Find all embedded files |
|
14 |
my %all; |
|
15 |
my $app = $self->app; |
|
16 |
my $loader = Mojo::Loader->new; |
|
17 |
for my $class (@{$app->renderer->classes}, @{$app->static->classes}) { |
|
18 |
for my $name (keys %{$loader->data($class)}) { |
|
19 |
my $data = $loader->data($class, $name); |
|
20 |
$all{$name} |
|
21 |
= $loader->is_binary($class, $name) ? $data : encode('UTF-8', $data); |
|
22 |
} |
|
23 |
} |
|
24 | ||
25 |
# Turn them into real files |
|
26 |
for my $name (keys %all) { |
|
27 |
my $prefix = $name =~ /\.\w+\.\w+$/ ? 'templates' : 'public'; |
|
28 |
$self->write_file($self->rel_file("$prefix/$name"), $all{$name}); |
|
29 |
} |
|
30 |
} |
|
31 | ||
32 |
1; |
|
33 | ||
34 |
=encoding utf8 |
|
35 | ||
36 |
=head1 NAME |
|
37 | ||
38 |
Mojolicious::Command::inflate - Inflate command |
|
39 | ||
40 |
=head1 SYNOPSIS |
|
41 | ||
42 |
use Mojolicious::Command::inflate; |
|
43 | ||
44 |
my $inflate = Mojolicious::Command::inflate->new; |
|
45 |
$inflate->run(@ARGV); |
|
46 | ||
47 |
=head1 DESCRIPTION |
|
48 | ||
49 |
L<Mojolicious::Command::inflate> turns templates and static files embedded in |
|
50 |
the C<DATA> sections of your application into real files. |
|
51 | ||
52 |
This is a core command, that means it is always enabled and its code a good |
|
53 |
example for learning to build new commands, you're welcome to fork it. |
|
54 | ||
55 |
=head1 ATTRIBUTES |
|
56 | ||
57 |
L<Mojolicious::Command::inflate> inherits all attributes from |
|
58 |
L<Mojolicious::Command> and implements the following new ones. |
|
59 | ||
60 |
=head2 description |
|
61 | ||
62 |
my $description = $inflate->description; |
|
63 |
$inflate = $inflate->description('Foo!'); |
|
64 | ||
65 |
Short description of this command, used for the command list. |
|
66 | ||
67 |
=head2 usage |
|
68 | ||
69 |
my $usage = $inflate->usage; |
|
70 |
$inflate = $inflate->usage('Foo!'); |
|
71 | ||
72 |
Usage information for this command, used for the help screen. |
|
73 | ||
74 |
=head1 METHODS |
|
75 | ||
76 |
L<Mojolicious::Command::inflate> inherits all methods from |
|
77 |
L<Mojolicious::Command> and implements the following new ones. |
|
78 | ||
79 |
=head2 run |
|
80 | ||
81 |
$inflate->run(@ARGV); |
|
82 | ||
83 |
Run this command. |
|
84 | ||
85 |
=head1 SEE ALSO |
|
86 | ||
87 |
L<Mojolicious>, L<Mojolicious::Guides>, L<http://mojolicio.us>. |
|
88 | ||
89 |
=cut |