EPScript to limit authors in citation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
package EPrints::Script::Compiled; | |
use strict; | |
sub run_wrro_people_limited | |
{ | |
my( $self, $state, $value, $limit ) = @_; | |
my $session = $state->{session}; | |
my $r = $state->{session}->make_doc_fragment; | |
my $creators = $value->[0]; | |
if( defined $limit ){ | |
if( $limit->[1] ne "INTEGER" ) | |
{ | |
EPrints::abort( "Usage: wrro_people_limited( PERSON_FIELD, max )" ); | |
} | |
$limit = $limit->[0]; | |
} | |
if( defined $limit && $limit > 0 ){ | |
$limit--; | |
} | |
if( !defined $limit || $limit > $#$creators ){ | |
$limit = $#$creators; | |
} | |
foreach my $i (0..$limit){ | |
my $creator = @$creators[$i]; | |
if( $i > 0 ){ | |
#not first item (or only one item) | |
if( $i == $#$creators ){ | |
#last item | |
$r->appendChild( $session->make_text( " and " ) ); | |
} else { | |
$r->appendChild( $session->make_text( ", " ) ); | |
} | |
} | |
my $person_span = $session->make_element( "span", "class" => "person" ); | |
$person_span->appendChild( $session->render_name( $creator->{name} ) ); | |
$r->appendChild( $person_span ); | |
} | |
if( $limit < $#$creators ){ | |
my $more_authors = $#$creators - $limit; | |
my $s = ( $more_authors > 1 ? 's' : '' ); | |
$r->appendChild( $session->make_text( " et al. ($more_authors more author$s)" ) ); | |
} | |
return [ $r, "XHTML" ]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment