line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::LiquidTidy; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
101988
|
use strict; |
|
1
|
|
|
|
|
10
|
|
|
1
|
|
|
|
|
30
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
5
|
1
|
|
|
1
|
|
487
|
use experimental 'signatures'; |
|
1
|
|
|
|
|
3511
|
|
|
1
|
|
|
|
|
5
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
700
|
use Template::LiquidX::Tidy; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
53
|
|
10
|
1
|
|
|
1
|
|
7
|
use Template::Liquid; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
20
|
|
11
|
1
|
|
|
1
|
|
426
|
use Template::LiquidX::Tidy::Tag::include; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
4
|
|
12
|
1
|
|
|
1
|
|
481
|
use Template::LiquidX::Tidy::Tag::post_url; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
13
|
|
|
|
|
|
|
|
14
|
1
|
|
|
1
|
1
|
1438
|
sub new ($class, $args) { |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
2
|
|
15
|
1
|
|
|
|
|
3
|
bless $args => $class |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
1
|
|
|
1
|
1
|
1197
|
sub run ($self) { |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
2
|
|
19
|
1
|
50
|
|
|
|
6
|
die "No file name specified\n" unless $self->{file}; |
20
|
1
|
|
|
|
|
4
|
my $fh; |
21
|
1
|
50
|
|
|
|
5
|
if ($self->{file} eq '-') { |
22
|
0
|
|
|
|
|
0
|
$fh = *STDIN; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
else { |
25
|
1
|
50
|
|
|
|
49
|
open $fh, '<', $self->{file} or die "Error opening $self->{file}: $!\n"; |
26
|
|
|
|
|
|
|
} |
27
|
1
|
|
|
|
|
3
|
my $content = do { local $/; <$fh>; }; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
30
|
|
28
|
|
|
|
|
|
|
|
29
|
1
|
|
|
|
|
10
|
my $sol = Template::Liquid->parse($content); |
30
|
|
|
|
|
|
|
|
31
|
1
|
|
|
|
|
79
|
my $liquid_tidy; |
32
|
1
|
|
|
|
|
4
|
my %opts = ( |
33
|
|
|
|
|
|
|
force_nl => 1, |
34
|
|
|
|
|
|
|
); |
35
|
1
|
50
|
33
|
|
|
15
|
if ($self->{file} =~ /\.markdown/ || $self->{file} =~ /\.md/ || $self->{file} =~ /\.txt/) { |
|
|
|
33
|
|
|
|
|
36
|
0
|
|
|
|
|
0
|
$opts{html} = 0; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
1
|
|
|
|
|
6
|
%opts = (%opts, %$self); |
40
|
1
|
|
|
|
|
5
|
$liquid_tidy = $sol->{document}->tidy(\%opts); |
41
|
1
|
|
|
|
|
62
|
print $liquid_tidy; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# print Dumper $sol->{document}; |
45
|
|
|
|
|
|
|
# print $sol->{document}->dump(); |
46
|
|
|
|
|
|
|
# print $sol->{document}->tidy({force_nl => 1}); |
47
|
|
|
|
|
|
|
# my $liquid_tidy = $sol->{document}->tidy(); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# sub test_html_tidy ($source) { |
50
|
|
|
|
|
|
|
# my ($trans, $map) = Template::Liquid->parse($sol)->{document}->transform(); |
51
|
|
|
|
|
|
|
# print $trans; |
52
|
|
|
|
|
|
|
# my @cmd = (qw(tidy |
53
|
|
|
|
|
|
|
# --indent auto |
54
|
|
|
|
|
|
|
# --indent-spaces 4 |
55
|
|
|
|
|
|
|
# --show-body-only auto |
56
|
|
|
|
|
|
|
# --fix-uri no |
57
|
|
|
|
|
|
|
# --literal-attributes yes |
58
|
|
|
|
|
|
|
# --preserve-entities yes |
59
|
|
|
|
|
|
|
# --new-pre-tags body |
60
|
|
|
|
|
|
|
# --quiet |
61
|
|
|
|
|
|
|
# )); |
62
|
|
|
|
|
|
|
# my ($out, $err); |
63
|
|
|
|
|
|
|
# IPC::Run::run \@cmd, \$trans, \$out, \$err; warn "tidy: $?"; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# print transform_back($out, $map); |
66
|
|
|
|
|
|
|
# } |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# sub dump_map ($map) { |
69
|
|
|
|
|
|
|
# for (sort { $a <=> $b } grep !/^__/, keys $map->%*) { |
70
|
|
|
|
|
|
|
# my $i = $map->{$_}; |
71
|
|
|
|
|
|
|
# print $_, "\t", (defined $i->{markup} ? $i->{markup} =~ s/\n\K/\t/gr : ''), "\n"; |
72
|
|
|
|
|
|
|
# print "\t", $i->{markup_2} =~ s/\n\K/\t/gr, "\n" |
73
|
|
|
|
|
|
|
# if defined $i->{markup_2}; |
74
|
|
|
|
|
|
|
# print "\n"; |
75
|
|
|
|
|
|
|
# } |
76
|
|
|
|
|
|
|
# } |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
1; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 NAME |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
App::LiquidTidy - Implementation for liquid_tidy script |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head1 SYNOPSIS |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
use App::LiquidTidy; |
87
|
|
|
|
|
|
|
my $app = App::LiquidTidy->new(%options); |
88
|
|
|
|
|
|
|
$app->run; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 DESCRIPTION |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
See L for the command line tool documentation. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 METHODS |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head2 new(%options) |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Create a new app. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
It will parse the file specified by C<$options{file}> |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
Other C<%options> are passed to Template::LiquidX::Tidy |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head2 run |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Print the formatted file to standard output. |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=cut |
109
|
|
|
|
|
|
|
|