View | Details | Raw Unified | Return to bug 34862
Collapse All | Expand All

(-)a/add_blocking_errors.pl (-1 / +60 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
use Modern::Perl;
4
use File::Find;
5
use File::Slurp;
6
use Data::Dumper;
7
8
my @themes;
9
10
# STAFF themes
11
my $staff_dir = 'koha-tmpl/intranet-tmpl';
12
opendir ( my $dh, $staff_dir ) or die "can't opendir $staff_dir: $!";
13
for my $theme ( grep { not /^\.|lib|js/ } readdir($dh) ) {
14
    push @themes, "$staff_dir/$theme/en";
15
}
16
close $dh;
17
18
my @files;
19
sub wanted {
20
    my $name = $File::Find::name;
21
    push @files, $name
22
        if $name =~ m[\.(tt)$] and -f $name;
23
}
24
25
find({ wanted => \&wanted, no_chdir => 1 }, @themes );
26
27
my @errors;
28
for my $file ( @files ) {
29
    add_messages($file);
30
}
31
32
sub add_messages {
33
    my ( $file ) = @_;
34
35
    my $messages_include = "[% INCLUDE 'messages.inc' %]\n";
36
    my @lines = read_file($file);
37
    my @new_lines = @lines;
38
    my $has_main_tag = grep { $_ =~ m|<main| } @lines;
39
    my $spacing = q{};
40
    my ( $in_main, $line_open_main );
41
    my ( $line_number, $number_replaced_mains ) = (0, 0);
42
    for my $line (@lines) {
43
        $line_number++;
44
        if ( $line =~ m{^(\s*)<main} ) {
45
            $spacing = $1 . "    ";
46
            $in_main = 1;
47
            $line_open_main = $line_number;
48
        } elsif (!$has_main_tag && $line =~ m{(\s*)<div class="main} ) {
49
            $spacing = $1 . "            ";
50
            $in_main = 1;
51
            $line_open_main = $line_number + 2;
52
        }
53
        if ( $in_main ) {
54
            splice @new_lines, $line_open_main + $number_replaced_mains, 0, $spacing . $messages_include;
55
            $number_replaced_mains++;
56
            $in_main = 0;
57
        }
58
    }
59
    write_file($file, @new_lines);
60
}

Return to bug 34862