Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New expansion hierarchy #4123

Merged
merged 3 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions standalone/tools/epubgen2/Ehoras.setup
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ $noflexa='0';;
bbtbbtcccccccnnbbbbb

[general]
$expand='psalms';;
$expand='psalteria';;
$version='Rubrics 1960 - 1960';;
$lang2='English';;
$accented='plain';;
Expand All @@ -32,7 +32,7 @@ $accented='plain';;
oooo

[generalc]
$expand='psalms';;
$expand='psalteria';;
$version1='Divino Afflatu';;
$version2='Rubrics 1960';;
$lang2='English';;
Expand Down
36 changes: 33 additions & 3 deletions web/cgi-bin/DivinumOfficium/LanguageTextTools.pm
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ BEGIN {
require Exporter;
our $VERSION = 1.00;
our @ISA = qw(Exporter);
our @EXPORT_OK = qw(prayer translate load_languages_data
our @EXPORT_OK = qw(prayer rubric prex translate load_languages_data
omit_regexp suppress_alleluia process_inline_alleluias
alleluia_ant ensure_single_alleluia ensure_double_alleluia);
}
Expand All @@ -17,6 +17,8 @@ BEGIN {
#
my %_translate;
my %_prayers;
my %_preces;
my %_rubrics;
my $alleluia_regexp;
my $omit_regexp;

Expand Down Expand Up @@ -124,17 +126,45 @@ sub prayer {
|| $name;
}

#*** rubric($name)
# return the prayer
sub rubric {
my $name = shift;
my $lang = shift;
my $version = $main::version;

$_rubrics{"$lang$version"}{$name}
|| $_rubrics{"English$version"}{$name}
|| $_rubrics{"Latin$version"}{$name}
|| $name;
}

#*** prex($name)
# return the prayer
sub prex {
my $name = shift;
my $lang = shift;
my $version = $main::version;

$_preces{"$lang$version"}{$name}
|| $_preces{"English$version"}{$name}
|| $_preces{"Latin$version"}{$name}
|| $name;
}

#*** load_languages_data($lang1, $lang2, $missaf)
sub load_languages_data {
my ($lang1, $lang2, $version, $missaf) = @_;
my @langs = qw/Latin English/;
push(@langs, $lang1) unless $lang1 =~ /(?:Latin|English)$/;
push(@langs, $lang2) unless $lang2 =~ /(?:Latin|English)$/;
my $dir = $missaf ? 'Ordo' : 'Psalterium';
my $dir = $missaf ? 'Ordo' : 'Psalterium/Common';

foreach my $lang (@langs) {
$_prayers{"$lang$version"} = main::setupstring($lang, "$dir/Prayers.txt");
$_translate{$lang} = main::setupstring($lang, "Psalterium/Translate.txt");
$_rubrics{"$lang$version"} = main::setupstring($lang, "Psalterium/Common/Rubricae.txt");
$_preces{"$lang$version"} = main::setupstring($lang, "Psalterium/Special/Preces.txt");
$_translate{$lang} = main::setupstring($lang, "Psalterium/Common/Translate.txt");
}

my $alleluias = join('|', map { lc(alleluia($_)) } @langs);
Expand Down
72 changes: 63 additions & 9 deletions web/cgi-bin/horas/horas.pl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use lib "$Bin/..";

use DivinumOfficium::LanguageTextTools
qw(prayer translate omit_regexp suppress_alleluia process_inline_alleluias alleluia_ant ensure_single_alleluia ensure_double_alleluia);
qw(prayer rubric prex translate omit_regexp suppress_alleluia process_inline_alleluias alleluia_ant ensure_single_alleluia ensure_double_alleluia);
use DivinumOfficium::Date qw(date_to_days days_to_date);

my $precesferiales;
Expand Down Expand Up @@ -66,7 +66,7 @@ sub resolve_refs {
my @t = split("\n", $t);

#handles expanding for skeleton
if ($expand =~ /skeleton/ && $expandind != $expandnum) {
if ($expand eq 'lineamenta' && $expandind != $expandnum) {
if ($t[0] =~ /\#/) {
return setlink($t[0], $expandind, $lang);
} else {
Expand Down Expand Up @@ -136,7 +136,7 @@ sub resolve_refs {
my $suffix = '';
if ($l =~ s/(\{[^:].*?\})//) { $suffix = setfont($smallblack, $1); }
$line = setfont($largefont, $l) . " $suffix\n";
if ($expand =~ /skeleton/i) { $line .= linkcode1(); }
if ($expand eq 'lineamenta') { $line .= linkcode1(); }
}

#red line
Expand Down Expand Up @@ -420,9 +420,63 @@ sub setlink {

# Get index into translation table for the short text.
$name = get_link_name($name);
$name = translate($name, $lang) unless ($name =~ /^\#/);
$name .= $suffix;
$name =~ s/[\#\$\&]//g;

if ($name =~ /^\&(psalm|lectio)(?:[(](.*)[)])?$/) {
my ($function_name, $arg_string) = ($1, $2);
$arg_string =~ /\-?(\d+)/;
my $num = $1;

if ($function_name eq 'psalm' && $num <= 150) {
$arg_string =~ /\,\'?([0-9a-z]+)\'?\,?\'?([0-9a-z]+)\'?/;
$name = translate('Psalmus', $lang) . " $num";
$name .= $2 ? ":$1\&thinsp;\&ndash;\&thinsp;$2\&thinsp;" : '';
} else {
my @args = (parse_script_arguments($arg_string), $lang);
my @fulltext = split("\n", dispatch_script_function($function_name, @args));

if ($function_name eq 'psalm') {

# Canticles
$fulltext[0] =~ s/.*?I\>([\w\s]+?)\<.*/$1/u; # remove formatting
$fulltext[1] =~ s/\!(.*)$/ \($1\)/; # reformat Biblica source
$name = $fulltext[0] . $fulltext[1];
} else {

# Lectios
my ($incipit, $source, $verbum);

if ($fulltext[3] =~ /\<I\>([\w\s]+?)\<\/I\>/) {

# Commemoratio
$source = $1;
} elsif ($fulltext[3] =~ /^\!(.*)/) {

# No Lesson title but Source
$source = $1;
} elsif ($fulltext[4] =~ /^\!(.*)/ || $fulltext[4] =~ /(\_)/) {

# Lesson title and potentially Source
$source = $1;
$incipit = $fulltext[3];
$incipit =~ s/^v\. //i;
} else {

# Pure reading
$verbum = $fulltext[3];
$verbum =~ s/^v\. (\w+).*/$1 …/i;
}
$source =~ s/\!(.*)$/ \($1\)/; # reformat source
$name = $incipit ? $source ne '_' ? "$incipit ($source)" : $incipit : $source;
$name ||= $verbum;
}

#$error .= dispatch_script_function($function_name, @args);
}
} else {
$name = translate($name, $lang) unless ($name =~ /^\#/);
$name .= $suffix;
$name =~ s/[\#\$\&]//g;
}
my $after = '';

if ($name =~ /(.*?)(<input.*)/i) {
Expand All @@ -434,7 +488,7 @@ sub setlink {
return $name;
} elsif ($disabled || $smallflag) {
$name = setfont($smallblack, $name);
} elsif ($expand =~ /skeleton/i) {
} elsif ($expand eq 'lineamenta') {
$name = setfont($largefont, substr($name, 0, 1)) . setfont($redfont, substr($name, 1));
} else {
$name = setfont($largefont, uc(substr($name, 0, 1))) . substr($name, 1);
Expand Down Expand Up @@ -479,7 +533,7 @@ sub ant123_special {
my $ant, $duplexf;

if ($month == 12 && ($day > 16 && $day < 24) && $winner =~ /tempora/i) {
my %specials = %{setupstring($lang, 'Psalterium/Major Special.txt')};
my %specials = %{setupstring($lang, 'Psalterium/Special/Major Special.txt')};

if ($hora eq 'Laudes' && ($day == 21 || $day == 23)) {
$ant = $specials{"Adv Ant $day" . 'L'};
Expand Down Expand Up @@ -528,7 +582,7 @@ sub canticum {
setbuild1($ite, 'special');
($ant, $ant2) = split("\n", $w);
} else {
my %a = %{setupstring($lang, 'Psalterium/Minor Special.txt')};
my %a = %{setupstring($lang, 'Psalterium/Special/Minor Special.txt')};
my $name;
$name = gettempora('Nunc dimittis') if $version =~ /^Ordo Praedicatorum/;
$ant = $a{"Ant 4$name"};
Expand Down
42 changes: 0 additions & 42 deletions web/cgi-bin/horas/horascommon.pl
Original file line number Diff line number Diff line change
Expand Up @@ -1864,48 +1864,6 @@ ($)
return $papalcommon{'Ant 3 summi Pontificis'};
}

#*** sub expand($line, $lang, $antline)
# for & references calls the sub
# $ references are filled from Psalterium/Prayers file
# antline to handle redding the beginning of psalm is same as antiphona
# returns the expanded text or the link
sub expand {
use strict;
my ($line, $lang, $antline) = @_;
$line =~ s/^\s+//;
$line =~ s/\s+$//;

# Extract and remove the sigil indicating the required expansion type.
# TODO: Fail more drastically when the sigil is invalid.
$line =~ s/^([&\$])// or return $line;
my $sigil = $1;
our ($expand, $missa);
local $expand = $missa ? 'all' : $expand;

# Make popup link if we shouldn't expand.
if ($expand =~ /none/i
|| ($expand !~ /all|skeleton/i && ($line =~ /^(?:[A-Z](?!men)|pater_noster)/)))
{
setlink($sigil . $line, 0, $lang);
} elsif ($sigil eq '&') {

# Actual expansion for & references.
# Get function name and any parameters.
my ($function_name, $arg_string) = ($line =~ /(.*?)(?:[(](.*)[)])?$/);
my @args = (parse_script_arguments($arg_string), $lang);

# If we have an antiphon, pass it on to the script function.
if ($antline) {
$antline =~ s/^\s*Ant\. //i;
push @args, $antline;
}
dispatch_script_function($function_name, @args);
} else # Sigil is $, so simply look up the prayer.
{
prayer($line, $lang);
}
}

#*** sub gettempora($caller)
# return $name of tempora
# depending on caller
Expand Down
Loading