line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::Riotjs::Preprocessor; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
Mojolicious::Plugin::Riotjs::Preprocessor - Preprocessor for Riot tag files |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 DESCRIPTION |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
L is a preprocessor for |
10
|
|
|
|
|
|
|
L C<.tag> files. |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Riot is required for this module to work. You can install Riot with |
13
|
|
|
|
|
|
|
L: |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
$ sudo apt-get install npm |
16
|
|
|
|
|
|
|
$ npm install riot |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=cut |
19
|
|
|
|
|
|
|
|
20
|
1
|
|
|
1
|
|
978
|
use Mojo::Base 'Mojolicious::Plugin::AssetPack::Preprocessor'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
7
|
|
21
|
1
|
|
|
1
|
|
187
|
use File::Basename 'dirname'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
44
|
|
22
|
1
|
|
|
1
|
|
5
|
use File::Spec (); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
19
|
|
23
|
1
|
|
|
1
|
|
5
|
use File::Which (); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
313
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head2 executable |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
$path = $self->executable; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
Holds the path to the "riot" executable. Default to just "riot". |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=cut |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
has executable => sub { |
36
|
|
|
|
|
|
|
my $self = shift; |
37
|
|
|
|
|
|
|
my $local = File::Spec->catfile($self->cwd, 'node_modules', '.bin', 'riot'); |
38
|
|
|
|
|
|
|
return $local if -e $local; |
39
|
|
|
|
|
|
|
return File::Which::which('riot') || 'riot'; |
40
|
|
|
|
|
|
|
}; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
has _compile_cmd => sub { |
43
|
|
|
|
|
|
|
return [ |
44
|
|
|
|
|
|
|
File::Which::which('nodejs') || File::Which::which('node'), |
45
|
|
|
|
|
|
|
File::Spec->catfile(dirname(__FILE__), 'compile.js'), |
46
|
|
|
|
|
|
|
]; |
47
|
|
|
|
|
|
|
}; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head1 METHODS |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head2 can_process |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
Returns true if L points to an actual file. |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=cut |
56
|
|
|
|
|
|
|
|
57
|
1
|
50
|
|
1
|
1
|
22923
|
sub can_process { -f $_[0]->executable ? 1 : 0 } |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head2 process |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
This method use "riot" to process C<$text>. |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
See L. |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=cut |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub process { |
68
|
1
|
|
|
1
|
1
|
245958
|
my ($self, $assetpack, $text, $path) = @_; |
69
|
1
|
|
|
|
|
4
|
my $err = ''; |
70
|
|
|
|
|
|
|
|
71
|
1
|
50
|
|
|
|
3
|
local $ENV{RIOT_COMPACT} = $assetpack->minify ? 1 : 0; |
72
|
1
|
|
|
|
|
20
|
$self->_run($self->_compile_cmd, $text, $text, \$err); |
73
|
0
|
0
|
|
|
|
|
$self->_make_js_error($err, $text) if length $err; |
74
|
0
|
|
|
|
|
|
$self; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
0
|
|
|
0
|
|
|
sub _url {'https://muut.com/riotjs/'} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
Copyright (C) 2014, Jan Henning Thorsen |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
This program is free software, you can redistribute it and/or modify it under |
84
|
|
|
|
|
|
|
the terms of the Artistic License version 2.0. |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 AUTHOR |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Jan Henning Thorsen - C |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=cut |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
1; |