Display 245$a as Title Case in TPAC user/jeff/tpac_title_case
authorJeff Godin <jgodin@tadl.org>
Wed, 25 Jul 2012 13:35:07 +0000 (09:35 -0400)
committerJeff Godin <jgodin@tadl.org>
Wed, 25 Jul 2012 13:35:07 +0000 (09:35 -0400)
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 <jgodin@tadl.org>
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb.pm
Open-ILS/src/templates/opac/parts/misc_util.tt2

index 66fb47e..ab18d52 100644 (file)
@@ -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;
     }
index d7e93d0..39b9c71 100644 (file)
         # 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('[:;/]$', '');
         # 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 = [];