Permalink
Browse files

adding 'recent tags' widget

  • Loading branch information...
1 parent 9b20df9 commit 96c95655e7a9f1e1bbb57c6793ba34b09c40049e @yanick committed Aug 22, 2010
Showing with 65 additions and 1 deletion.
  1. +1 −0 Makefile.PL
  2. +55 −0 lib/Galuga/Widget/RecentTags.pm
  3. +1 −1 root/left_column.mason
  4. +8 −0 root/widgets/recent_tags.mason
View
@@ -9,6 +9,7 @@ use Module::Install::Catalyst; # Complain loudly if you don't have
name 'Galuga';
all_from 'lib/Galuga.pm';
+requires 'Template::Declare';
requires 'DateTime::Format::SQLite';
requires 'DateTime::Format::DateParse';
requires 'Catalyst::Runtime' => '5.80022';
@@ -0,0 +1,55 @@
+package Galuga::Widget::RecentTags;
+
+use strict;
+use warnings;
+
+use Template::Declare::Tags;
+use base 'Template::Declare';
+
+template widget => sub {
+ my $self = shift;
+ my %arg = @_;
+
+ div {
+ attr { class => 'widget tags_listing' };
+ h3 { 'Recent tags' };
+ show( 'tag', %arg, tag => $_ )
+ for sort { lc( $a->tag ) cmp lc( $b->tag ) }
+ $self->get_tags( $arg{c} );
+ }
+
+};
+
+template 'tag' => sub {
+ my ( $self, %arg ) = @_;
+
+ div {
+ a {
+ attr { href => $arg{c}->uri_for('/tag') . '/' . $arg{tag}->tag }
+ $arg{tag}->tag . ' ';
+ }
+
+ div {
+ attr { class => 'count' } '('
+ . $arg{tag}->get_column('nbr_entries') . ')';
+ }
+ }
+};
+
+sub get_tags {
+ my ( $self, $c ) = @_;
+
+ my @tags = $c->model('DB::Entries')->search({},
+ { order_by => { '-desc' => 'created' },
+ rows => 5 } )->search_related('tags',{})->all;
+
+ return $c->model('DB::Tags')->search(
+ { tag => { 'IN' => [ map { $_->tag } @tags ] }, },
+ { group_by => 'tag',
+ order_by => 'tag',
+ select => [ 'tag', { count => 'entry_path' } ],
+ as => [qw/ tag nbr_entries /],
+ } )->all;
+}
+
+1;
View
@@ -1,4 +1,4 @@
<div class="left_column">
<& /widgets/recent_entries.mason &>
- <& /widgets/tags.mason &>
+ <& /widgets/recent_tags.mason &>
</div>
@@ -0,0 +1,8 @@
+<%once>
+use Template::Declare;
+use Galuga::Widget::RecentTags;
+</%once>
+
+% Template::Declare->init( dispatch_to => [ 'Galuga::Widget::RecentTags' ] );
+<% Template::Declare->show( 'widget', c => $c ) %>
+

0 comments on commit 96c9565

Please sign in to comment.