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 |
# OPAC themes |
11 |
my $opac_dir = 'koha-tmpl/opac-tmpl'; |
12 |
opendir ( my $dh, $opac_dir ) or die "can't opendir $opac_dir: $!"; |
13 |
for my $theme ( grep { not /^\.|lib|js|xslt/ } readdir($dh) ) { |
14 |
push @themes, "$opac_dir/$theme/en"; |
15 |
} |
16 |
close $dh; |
17 |
|
18 |
# STAFF themes |
19 |
my $staff_dir = 'koha-tmpl/intranet-tmpl'; |
20 |
opendir ( $dh, $staff_dir ) or die "can't opendir $staff_dir: $!"; |
21 |
for my $theme ( grep { not /^\.|lib|js/ } readdir($dh) ) { |
22 |
push @themes, "$staff_dir/$theme/en"; |
23 |
} |
24 |
close $dh; |
25 |
|
26 |
my @files; |
27 |
sub wanted { |
28 |
my $name = $File::Find::name; |
29 |
push @files, $name |
30 |
if $name =~ m[\.(tt)$] and -f $name; |
31 |
} |
32 |
|
33 |
find({ wanted => \&wanted, no_chdir => 1 }, @themes ); |
34 |
|
35 |
my @errors; |
36 |
for my $file ( @files ) { |
37 |
add_messages($file); |
38 |
} |
39 |
|
40 |
sub add_messages { |
41 |
my ( $file ) = @_; |
42 |
|
43 |
my $messages_include = "[% INCLUDE 'messages.inc' %]\n"; |
44 |
my @lines = read_file($file); |
45 |
my @new_lines = @lines; |
46 |
my $has_main_tag = grep { $_ =~ m|<main| } @lines; |
47 |
my $spacing = q{}; |
48 |
my ( $in_main, $line_open_main ); |
49 |
my ( $line_number, $number_replaced_mains ) = (0, 0); |
50 |
for my $line (@lines) { |
51 |
$line_number++; |
52 |
if ( $line =~ m{^(\s*)<main} ) { |
53 |
$spacing = $1 . " "; |
54 |
$in_main = 1; |
55 |
$line_open_main = $line_number; |
56 |
} elsif (!$has_main_tag && $line =~ m{(\s*)<div class="main} ) { |
57 |
$spacing = $1 . " "; |
58 |
$in_main = 1; |
59 |
$line_open_main = $line_number + 2; |
60 |
} |
61 |
if ( $in_main ) { |
62 |
splice @new_lines, $line_open_main + $number_replaced_mains, 0, $spacing . $messages_include; |
63 |
$number_replaced_mains++; |
64 |
$in_main = 0; |
65 |
} |
66 |
} |
67 |
write_file($file, @new_lines); |
68 |
} |