App-ZofCMS
view release on metacpan or search on metacpan
lib/App/ZofCMS/Plugin/TagCloud.pm view on Meta::CPAN
map +{
tag => $_->[0],
href => $conf{uri_prefix} . $_->[1],
class => do {
my $x = $conf{class} . $_->[2];
$x =~ s/[^\w-]/_/g;
$x;
},
}, @tags
],
);
$template->{t}{tag_cloud} = $t->output;
$template->{t}{tag_cloud_css} = $self->_make_css( \@tags, \%conf );
}
sub _make_css {
my ( $self, $tags, $conf ) = @_;
my @sizes = sort { $a <=> $b } map $_->[2], @$tags;
my $t = $self->_css_template;
$t->param(
tags => [
map +{
class => $conf->{class},
class_num => do { my $x = $_; $x =~ s/[^\w-]/_/g; $x; },
num => $_,
unit => $conf->{unit},
}, @sizes
],
map +( $_ => $conf->{ $_ } ),
qw/id fg bg fg_hover bg_hover fg_visited bg_visited/,
);
return $t->output;
}
sub _css_template {
return HTML::Template->new_scalar_ref( \ <<'END'
#<tmpl_var name="id"> li {
display: inline;
}
#<tmpl_var name="id"> a {
color: <tmpl_var name="fg">;
background: <tmpl_var name="bg">;
}
#<tmpl_var name="id"> a:visited {
color: <tmpl_var name="fg_visited">;
background: <tmpl_var name="bg_visited">;
}
#<tmpl_var name="id"> a:hover {
color: <tmpl_var name="fg_hover">;
background: <tmpl_var name="bg_hover">;
}
<tmpl_loop name="tags">.<tmpl_var name="class"><tmpl_var name="class_num"> { font-size: <tmpl_var name="num"><tmpl_var name="unit">; }
</tmpl_loop>
END
);
}
sub _tag_template {
return HTML::Template->new_scalar_ref( \ <<'END'
<ul id="<tmpl_var escape="html" name="id">"><tmpl_loop name="tags">
<li class="<tmpl_var escape="html" name="class">"><a href="<tmpl_var escape="html" name="href">"><tmpl_var escape="html" name="tag"></a></li></tmpl_loop>
</ul>
END
);
}
1;
__END__
=encoding utf8
=head1 NAME
App::ZofCMS::Plugin::TagCloud - generate "tag clouds"
=head1 SYNOPSIS
In your ZofCMS template or main config file:
plug_tag_cloud => {
unit => 'em',
tags => [ qw(
foo /foo 2
bar /bar 1
ber /ber 3
)
],
}
In your L<HTML::Template> template:
<style type="text/css">
<tmpl_var name="tag_cloud_css">
</style>
<tmpl_var name="tag_cloud">
=head1 DESCRIPTION
The module is a plugin for L<App::ZofCMS>; it generates "tag clouds" (bunch of different-sized
links).
This documentation assumes you have read L<App::ZofCMS>,
L<App::ZofCMS::Config> and L<App::ZofCMS::Template>
=head1 ZofCMS TEMPLATE/MAIN CONFIG FILE KEYS
plug_tag_cloud => {
id => 'tag_cloud_container',
class => 'tag_cloud_tag',
unit => 'em',
shuffle => 1,
uri_prefix => 'http://site.com/',
fg => '#00d',
bg => 'transparent',
fg_hover => '#66f',
bg_hover => 'transparent',
fg_visited => '#333',
bg_visited => 'transparent',
tags => [ qw(
foo /foo 2
( run in 0.765 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )