-
Notifications
You must be signed in to change notification settings - Fork 6
/
contributor_list.mc
135 lines (98 loc) · 3.24 KB
/
contributor_list.mc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<%doc>
=head1 NAME
contributor_list.mc -- Outputs a list of contributors
=head1 SYNOPSIS
<& contributor_list.mc,
asset => $story,
sep => ', ',
final => ' and ',
format => '%f% l',
default => ''
&>
=head1 DESCRIPTION
Outputs a formatted list of the contributors to a story. The supported
parameters are all optional, and are as follows:
=over 4
=item C<$asset>
The asset from which to get the list of contributors. Useful for getting the
list of contributors for a related story or media asset. Defaults to the
global C<$story> object.
=item C<$sep>
The separator to put between each name in the list, except betwee the
second-to-last and last names in the list. The default is ", ".
=item C<$final>
The separator put between the second-to-last and last names in the list. The
default is " and ".
=item C<$format>
The C<strfname> formatting string used to format each person's name. Defaults
to the value of the "Name Format" preference. See Bric::Biz::Person for
complete documentation of the C<strfname> formats.
=item C<$sort>
The property on which to sort the list of contributors. By default, the list
of contributors will be output in the order they're returned by
C<< $story->get_contributors >>, but if you need them to be output in some
other order, use this argument. The possible options for this argument are:
=over 4
=item full_name
=item lname
=item fname
=item mname
=item prefix
=item suffix
=item type
=back
=item C<$default>
The default value to display if there are no contributors associated with the
story. Defaults to an empty string ("").
=back
=head1 AUTHOR
David Wheeler <[email protected]>
Revised by Dawn Buie <[email protected]>
=head1 COPYRIGHT AND LICENSE
Copyright 2003 by Kineticode, Inc and by Mac Publishing, LLC.
This template is free software; you can redistribute it and/or modify it under
the same terms as Bricolage itself.
=cut
</%doc>
<%once>;
my $full_name_get = sub { $_[0]->get_name($_[1]) };
</%once>
<%args>
$sep => ', '
$final => ' and '
$format => '%p% f% M% l%, s'
$sort => undef
$asset => $story
$default => ''
</%args>
<%init>;
# Get the list of contributors.
my @contribs = $asset->get_contributors;
unless (@contribs) {
# If there are no contributors, just output the default and return.
#$m->print($default);
return 0;
}
if ($#contribs == 0) {
# There's just one contributor. Format and return.
my $contrib_link = $m->comp("/util/contributor_name2link.mc", name=>$contribs[0]->get_name($format));
$m->print('By '.$contrib_link);
return 1;
}
if ($sort) {
# We need to resort them.
my $get = $sort eq 'full_list' ? sub { $_[0]->get_name($format) } :
Bric::Util::Grp::Parts::Member::Contrib->my_meths->{$sort}{get_meth};
@contribs = sort { lc $get->($a) cmp lc $get->($b) } @contribs;
}
# Grab the last name in the list.
my $last = pop @contribs;
my $lastcontrib = $m->comp("/util/contributor_name2link.mc", name=>$last->get_name($format));
# Convert the contributor names to links
@contribs = map { $_->get_name($format) } @contribs;
@contribs = $m->comp("/util/contributor_name2link.mc", name=>\@contribs);
# Output the list.
$m->print('By '.join($sep, @contribs),
$final, $lastcontrib);
return 1;
</%init>