Skip to content

Instantly share code, notes, and snippets.

@jesusbagpuss
Created May 16, 2019 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jesusbagpuss/fbec13d9986fba8e93b56ae5ba34c164 to your computer and use it in GitHub Desktop.
Save jesusbagpuss/fbec13d9986fba8e93b56ae5ba34c164 to your computer and use it in GitHub Desktop.
EPScript to limit authors in citation
{
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