Changeset 107 in bookmarks for trunk/lib/Bookmarks


Ignore:
Timestamp:
11/09/15 20:21:41 (9 years ago)
Author:
peter
Message:

Added a /tags resource that provides a drilldown inteface to the tags and bookmarks. URI pattern is /tags/{tag1}/{tag2}/{tag3...}

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Bookmarks/Controller.pm

    r106 r107  
    222222} 
    223223 
     224sub tag_tree { 
     225    my $self = shift; 
     226    my $tags = shift || []; 
     227 
     228    my $list = Bookmarks::List->new({ 
     229        bookmarks => $self->bookmarks, 
     230        search    => $self->bookmarks->search({ 
     231            tags   => $tags, 
     232        }), 
     233    }); 
     234 
     235    my @tags = map { 
     236        { 
     237            path => join('/', @$tags[0 .. $_ - 1]), 
     238            tag  => $tags->[$_ - 1], 
     239        } 
     240    } 1 .. scalar(@{ $tags }); 
     241 
     242    require Template; 
     243    require File::Basename; 
     244    my @cotags = $self->bookmarks->get_cotags({ search => $list->search }); 
     245 
     246    #TODO: get the actual request URI and makre sure it ends with a / 
     247    my $base_url = join '/', ($self->base_uri . 'tags'), @$tags; 
     248    $base_url .= '/'; 
     249    my $template = Template->new({ INCLUDE_PATH => File::Basename::dirname($INC{'Bookmarks/Controller.pm'}) }); 
     250 
     251    $template->process( 
     252        'tagtree.html', 
     253        { 
     254            base_url => $self->base_uri, 
     255            request_url => $base_url, 
     256            tags      => \@tags, 
     257            cotags    => \@cotags, 
     258            bookmarks => $list->results, 
     259        }, 
     260        \my $output, 
     261    ); 
     262 
     263 
     264    return [200, ['Content-Type' => 'text/html; charset=UTF-8'], [$output]]; 
     265} 
     266 
    2242671; 
Note: See TracChangeset for help on using the changeset viewer.