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