-
Notifications
You must be signed in to change notification settings - Fork 6
/
keyword_list.mc
124 lines (95 loc) · 3.21 KB
/
keyword_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
<%doc>
=head1 NAME
keyword_list.mc - Get list of keywords
=head1 SYNOPSIS
my @kw = $m->comp( '/util/keyword_list.mc',
which => 'total' );
=head1 DESCRIPTION
Outputs a list or anonymous array of keyword objects. The C<which> parameter
tells F<keyword_list.mc> which keywords to return. The possible values are:
=over 4
=item total
Return all of the keywords for the story, all of its categories, and all of
the parents of those categories.
=item context
Return all of the keywords for the story, for the current category (the one to
which the story is being burned), and for all of its parent categories.
=item cats
Return all of the keywords for the story and all of its categories.
=item local
Return all of the keywords for the story and for the current category (the one
to which the story is being burned).
=item story
Return only the story's keywords.
=back
The default is "cats". The keywords will be returned sorted by their
C<sort_name> properites.
=head1 AUTHOR
David Wheeler <[email protected]>
=head1 COPYRIGHT AND LICENSE
Copyright (c) 2003 by Kineticode, Inc and by Mac Publishing, LLC.
This library is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free
Software Foundation, version 2.1 of the License.
This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
details.
You should have received a copy of the GNU Lesser General Public License along
with this library (see the the license.txt file); if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA.
=cut
</%doc>
<%args>
$which => 'cats'
</%args>
<%once>;
my %subs =
( total => sub {
my %kw = map { $_->get_id => $_ } $story->get_keywords;
foreach my $cat ($story->get_categories) {
foreach my $k ($cat->keywords) {
$kw{$k->get_id} = $k;
}
while ($cat = $cat->get_parent) {
foreach my $k ($cat->keywords) {
$kw{$k->get_id} = $k;
}
}
}
return sort { lc $a->get_sort_name cmp lc $b->get_sort_name }
values %kw;
},
context => sub {
my $cat = $burner->get_cat;
my %kw = map { $_->get_id => $_ } $story->get_keywords, $cat->keywords;
while ($cat = $cat->get_parent) {
foreach my $k ($cat->keywords) {
$kw{$k->get_id} = $k;
}
}
return
map { $_->[0] }
sort { $a->[1] cmp $b->[1] }
map { [ $_ => lc $_->get_sort_name] }
values %kw;
},
cats => sub {
$story->get_all_keywords
},
local => sub {
my %kw = map { $_->get_id => $_ } $story->get_keywords,
$burner->get_cat->keywords;
return sort { lc $a->get_sort_name cmp lc $b->get_sort_name }
values %kw;
},
story => sub {
$story->get_keywords
}
);
</%once>
<%init>;
my $code = $subs{$which} or die "No such which parameter '$which'";
return wantarray ? $code->() : [$code->()];
</%init>