From a0f57776275f49aaf7afe0cd70ed06d066e697a0 Mon Sep 17 00:00:00 2001 From: Jeff Godin Date: Wed, 25 Jul 2012 09:35:07 -0400 Subject: [PATCH] Display 245$a as Title Case in TPAC Using Lingua::EN::Titlecase, perform a "Title Case" case transform on the 245$a value as displayed in TPAC. TODO: Make this configurable, allow it to fail gracefully when Lingua::EN::Titlecase is not present. Signed-off-by: Jeff Godin --- Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb.pm | 3 ++- Open-ILS/src/templates/opac/parts/misc_util.tt2 | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb.pm index 71a520ce28..76287937be 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb.pm @@ -5,6 +5,7 @@ use XML::Simple; use XML::LibXML; use File::stat; use Encode; +use Lingua::EN::Titlecase; use Apache2::Const -compile => qw(OK DECLINED HTTP_INTERNAL_SERVER_ERROR); use Apache2::Log; use OpenSRF::EX qw(:try); @@ -61,7 +62,7 @@ sub handler { $ctx->{encode_utf8} = sub {return encode_utf8(shift())}; - unless($tt->process($template, {ctx => $ctx, ENV => \%ENV, l => $text_handler})) { + unless($tt->process($template, {ctx => $ctx, ENV => \%ENV, l => $text_handler, tc => Lingua::EN::Titlecase->new()})) { $r->log->warn('egweb: template error: ' . $tt->error); return Apache2::Const::HTTP_INTERNAL_SERVER_ERROR; } diff --git a/Open-ILS/src/templates/opac/parts/misc_util.tt2 b/Open-ILS/src/templates/opac/parts/misc_util.tt2 index d7e93d0901..39b9c710a5 100644 --- a/Open-ILS/src/templates/opac/parts/misc_util.tt2 +++ b/Open-ILS/src/templates/opac/parts/misc_util.tt2 @@ -36,7 +36,13 @@ # Include subfields 'abnp' to generate a more comprehensive title display in search results titresults = xml.findnodes('//*[@tag="245"]/*[@code="a" or @code="b" or @code="n" or @code="p"]'); titresults_content = []; - FOR sub IN titresults; titresults_content.push(sub.textContent); END; + FOR sub IN titresults; + IF sub.getAttribute('code') == 'a'; + titresults_content.push(tc.title(sub.textContent)); + ELSE; + titresults_content.push(sub.textContent); + END; + END; args.title = titresults_content.join(" "); # Avoid ugly trailing syntax on brief titles args.title = args.title | replace('[:;/]$', ''); @@ -44,7 +50,13 @@ # Provide correct spacing between the subfields titsubs = xml.findnodes('//*[@tag="245"]/*[@code]'); titsubs_content = []; - FOR sub IN titsubs; titsubs_content.push(sub.textContent); END; + FOR sub IN titsubs; + IF sub.getAttribute('code') == 'a'; + titsubs_content.push(tc.title(sub.textContent)); + ELSE; + titsubs_content.push(sub.textContent); + END; + END; args.title_extended = titsubs_content.join(" "); args.publishers = []; -- 2.11.0