| MojoMojo documentation | Contained in the MojoMojo distribution. |
MojoMojo::Controller::Tag - Tags controller
Handles the following URLs /.tags/ /.list/<tag> (dispatched from Page) /.recent/<tag> (dispatched from Page)
This controller generates a tag cloud and retrieves (all or recent) pages tagged with a given tag.
This is a private action, and is dispatched from .list|MojoMojo::Controller::Page/list when supplied with a tag argument. It will list all pages tagged with the given tag.
This is a private action, and is dispatched from .recent|MojoMojo::Controller::Page/recent when supplied with a tag argument. It will list recent pages tagged with the given tag.
Marcus Ramberg <mramberg@cpan.org>
This library is free software. You can redistribute it and/or modify it under the same terms as Perl itself.
| MojoMojo documentation | Contained in the MojoMojo distribution. |
package MojoMojo::Controller::Tag; use strict; use parent 'Catalyst::Controller'; use HTML::TagCloud;
sub list : Private { my ( $self, $c, $tag ) = @_; return unless $tag; $c->stash->{template} = 'page/list.tt'; $c->stash->{activetag} = $tag; $c->stash->{pages} = [ $c->stash->{page}->tagged_descendants($tag) ]; $c->stash->{related} = [ $c->model("DBIC::Tag")->related_to($tag) ]; }
sub recent : Private { my ( $self, $c, $tag ) = @_; $c->stash->{template} = 'page/recent.tt'; return unless $tag; $c->stash->{activetag} = $tag; $c->stash->{pages} = [ $c->stash->{page}->tagged_descendants_by_date($tag) ]; }
sub tags : Global { my ( $self, $c, $tag ) = @_; my $tags = [ $c->model("DBIC::Tag")->by_page( $c->stash->{page}->id ) ]; my %tags; map { $tags{$_->tag}++; }@$tags; my $cloud = HTML::TagCloud->new(); foreach my $tag (keys %tags) { $cloud->add( $tag, $c->req->base . $c->stash->{path} . '.list/' . $tag, $tags{$tag} ); } $c->stash->{cloud} = $cloud; $c->stash->{template} = 'tag/cloud.tt'; }
1;