use
5.010001;
sub
new {
my
(
$class
,
%args
) =
@_
;
my
$files
=
delete
$args
{files};
die
"Missing files"
unless
$files
&&
@$files
;
my
@docs
;
my
(
%languages
,
%language_codes
);
my
(
$main_lang
,
$main_lang_code
);
foreach
my
$file
(
@$files
) {
my
$doc
= Text::Amuse->new(
file
=>
$file
);
push
@docs
,
$doc
;
my
$current_lang_code
=
$doc
->language_code;
my
$current_lang
=
$doc
->language;
$main_lang
||=
$current_lang
;
$main_lang_code
||=
$current_lang_code
;
if
(
$main_lang
ne
$current_lang
) {
$languages
{
$current_lang
}++;
$language_codes
{
$current_lang_code
}++;
}
}
my
(
%html_headers
,
%latex_headers
);
foreach
my
$k
(
keys
%args
) {
$html_headers
{
$k
} = muse_format_line(
html
=>
$args
{
$k
});
$latex_headers
{
$k
} = muse_format_line(
ltx
=>
$args
{
$k
});
}
my
$self
= {
headers
=> {
%args
},
html_headers
=> \
%html_headers
,
latex_headers
=> \
%latex_headers
,
files
=> [
@$files
],
docs
=> \
@docs
,
language
=>
$main_lang
,
language_code
=>
$main_lang_code
,
other_languages
=> \
%languages
,
other_language_codes
=> \
%language_codes
,
tt
=> Template->new,
templates
=> Text::Amuse::Compile::Templates->new,
};
bless
$self
,
$class
;
}
sub
language {
return
shift
->{language};
}
sub
language_code {
return
shift
->{language_code},
}
sub
other_language_codes {
my
$self
=
shift
;
my
%langs
= %{
$self
->{other_language_codes} };
if
(
%langs
) {
return
[
keys
%langs
];
}
else
{
return
;
}
}
sub
other_languages {
my
$self
=
shift
;
my
%langs
= %{
$self
->{other_languages} };
if
(
%langs
) {
return
[
keys
%langs
];
}
else
{
return
;
}
}
sub
as_latex {
my
$self
=
shift
;
my
@out
;
my
$current_language
=
$self
->language;
my
%lang_aliases
= (
macedonian
=>
'russian'
,
serbian
=>
'croatian'
,
);
foreach
my
$doc
(
$self
->docs) {
my
$output
=
"\n\n"
;
my
$doc_language
=
$doc
->language;
if
(
my
$alias
=
$lang_aliases
{
$doc_language
}) {
$doc_language
=
$alias
;
}
if
(
$doc_language
ne
$current_language
) {
$output
=
sprintf
(
'\selectlanguage{%s}'
,
$doc_language
) .
"\n\n"
;
$current_language
=
$doc_language
;
}
$self
->tt->process(
$self
->templates->bare_latex,
{
doc
=>
$doc
},
\
$output
) or
die
$self
->tt->error;
push
@out
,
$output
;
}
return
join
(
"\n\n"
,
@out
,
"\n"
);
}
sub
wants_toc {
return
1;
}
sub
is_deleted {
return
0;
}
sub
header_as_latex {
return
{ %{
shift
->{latex_headers} } };
}
sub
header_as_html {
return
{ %{
shift
->{html_headers} } };
}
sub
docs {
return
@{
shift
->{docs} };
}
sub
files {
return
@{
shift
->{files} };
}
sub
headers {
return
%{
shift
->{headers} };
}
sub
tt {
return
shift
->{tt};
}
sub
templates {
return
shift
->{templates};
}
1;