forked from bricoleurs/templates
-
Notifications
You must be signed in to change notification settings - Fork 1
/
word_count.mc
50 lines (33 loc) · 956 Bytes
/
word_count.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
<%doc>
=head1 NAME
word_count.mc -- Counts the number of words in a story
=head1 SYNOPSIS
<& 'word_count.mc',
elements => ['paragraph', 'pull_quote'] &>
=head1 DESCRIPTION
Counts the number of words in the given elements of the current
story.
=over 4
=item C<$elements>
An optional array reference of the key names of the data subelements to
include in the count. Only specify data elements (fields) here; container
subelements will be ignored. Currently does not support subelements...patches
welcome!
=back
=head1 AUTHOR
Marshall Roch <[email protected]>
=head1 COPYRIGHT AND LICENSE
Copyright 2004 by Marshall Roch.
This template is free software; you can redistribute it and/or modify it under
the same terms as Bricolage itself.
=cut
</%doc>
<%args>
@elements => ()
</%args>
<%init>;
my $count = 0;
$count += @{[split /\s+/, $_->get_data]} for $element->get_data_elements(@elements);
$m->print($count);
return 1;
</%init>