Permalink
Browse files

enter Template::Declare

  • Loading branch information...
1 parent 6195f72 commit 9b20df9bbdc3c7aa5687d36786effe0f7df76c20 @yanick committed Aug 22, 2010
Showing with 59 additions and 29 deletions.
  1. +0 −12 lib/Galuga/Controller/Entry.pm
  2. +51 −0 lib/Galuga/Widget/Tags.pm
  3. +0 −1 root/entry/index.mason
  4. +1 −4 root/left_column.mason
  5. +0 −1 root/page.mason
  6. +7 −11 root/widgets/tags.mason
@@ -51,18 +51,6 @@ sub index :Chained('base') :PathPart('') :Args(0) {
my $url = $c->stash->{url};
- my $tags = $c->model('DB::Tags')->search({}, {
- group_by => 'tag',
- select => [
- 'tag',
- { count => 'entry_path' }
- ],
- as => [ qw/ tag nbr_entries / ],
- } );
-
- $c->stash->{tags} = [ $tags->all ];
-
-
my $rs = $c->stash->{entry};
my $body = $rs->body;
View
@@ -0,0 +1,51 @@
+package Galuga::Widget::Tags;
+
+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 { '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 ) = @_;
+
+ return $c->model('DB::Tags')->search(
+ {},
+ { group_by => 'tag',
+ order_by => 'tag',
+ select => [ 'tag', { count => 'entry_path' } ],
+ as => [qw/ tag nbr_entries /],
+ } )->all;
+}
+
+1;
View
@@ -1,6 +1,5 @@
<%args>
$entry
-@tags
$body
@syntax_highlight => ()
</%args>
View
@@ -1,7 +1,4 @@
-<%args>
-@tags
-</%args>
<div class="left_column">
<& /widgets/recent_entries.mason &>
- <& /widgets/tags.mason, tags => \@tags &>
+ <& /widgets/tags.mason &>
</div>
View
@@ -1,5 +1,4 @@
<%args>
-@tags
@syntax_highlight => ()
</%args>
% my $content = $m->content;
View
@@ -1,12 +1,8 @@
-<%args>
-@tags
-</%args>
-<div class="widget tags_listing">
-<h3>Tags</h3>
-% for my $t ( sort { lc($a->tag) cmp lc($b->tag) } @tags ) {
-<div>
-<a href="<% $c->uri_for( '/tag' ) %>/<% $t->tag | u %>"><% $t->tag %> </a>
+<%once>
+use Template::Declare;
+use Galuga::Widget::Tags;
+</%once>
+
+% Template::Declare->init( dispatch_to => [ 'Galuga::Widget::Tags' ] );
+<% Template::Declare->show( 'widget', c => $c ) %>
-<div class="count">(<% $t->get_column('nbr_entries') %>)</div></div>
-% }
-</div>

0 comments on commit 9b20df9

Please sign in to comment.