- Timestamp:
- 05/27/13 15:21:58 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/BookmarkApp.pm
r37 r38 10 10 use JSON; 11 11 use Bookmarks; 12 13 12 use URI; 14 13 … … 44 43 sub _bookmarks { $_[0]->param('bookmarks') } 45 44 45 sub _get_list_links { 46 my $self = shift; 47 my ($self_type, $tags) = @_; 48 my @links = ( 49 { 50 text => 'HTML', 51 type => 'text/html', 52 query => { 53 tag => $tags, 54 }, 55 }, 56 { 57 text => 'JSON', 58 type => 'application/json', 59 query => { 60 tag => $tags, 61 format => 'json', 62 }, 63 }, 64 { 65 text => 'XBEL', 66 type => 'application/xml', 67 query => { 68 tag => $tags, 69 format => 'xbel', 70 }, 71 }, 72 { 73 text => 'Atom', 74 type => 'application/atom+xml', 75 path => 'feed', 76 query => { 77 tag => $tags, 78 }, 79 }, 80 { 81 text => 'URI List', 82 type => 'text/uri-list', 83 query => { 84 tag => $tags, 85 }, 86 } 87 ); 88 89 for my $link (@links) { 90 $link->{rel} = $link->{type} eq $self_type ? 'self' : 'alternate'; 91 $link->{href} = URI->new_abs($link->{path} || '', $self->param('base_uri')); 92 $link->{href}->query_form($link->{query}); 93 } 94 95 return @links; 96 } 97 46 98 sub list { 47 99 my $self = shift; … … 155 207 $base_url .= '/' if $base_url =~ m{/bookmarks$}; 156 208 157 my @links = (158 {159 text => 'Link',160 type => 'text/html',161 rel => 'self',162 query => {163 tag => \@tags,164 },165 },166 {167 text => 'JSON',168 type => 'application/json',169 rel => 'alternate',170 query => {171 tag => \@tags,172 format => 'json',173 },174 },175 {176 text => 'XBEL',177 type => 'application/xml',178 rel => 'alternate',179 query => {180 tag => \@tags,181 format => 'xbel',182 },183 },184 {185 text => 'Atom',186 type => 'application/atom+xml',187 rel => 'alternate',188 path => 'feed',189 query => {190 tag => \@tags,191 },192 },193 );194 for my $link (@links) {195 $link->{href} = URI->new_abs($link->{path} || '', $self->param('base_uri'));196 $link->{href}->query_form($link->{query});197 }198 199 209 return $self->tt_process( 200 210 'list.tt', … … 204 214 selected_tag => $tags[0], 205 215 search_tags => \@tags, 206 links => \@links,216 links => [ $self->_get_list_links('text/html', \@tags) ], 207 217 all_tags => \@all_tags, 208 218 cotags => \@cotags, … … 234 244 $feed->id($feed_uri->canonical); 235 245 236 my $self_link = XML::Atom::Link->new; 237 $self_link->type('application/atom+xml'); 238 $self_link->rel('self'); 239 $self_link->href($feed_uri->canonical); 240 $feed->add_link($self_link); 241 242 my $html_link = XML::Atom::Link->new; 243 $html_link->type('text/html'); 244 $html_link->rel('alternate'); 245 my $html_uri = $self->param('base_uri')->clone; 246 $html_uri->query_form(tag => \@tags); 247 $html_link->href($html_uri->canonical); 248 $feed->add_link($html_link); 246 for my $link ($self->_get_list_links('application/atom+xml', \@tags)) { 247 my $atom_link = XML::Atom::Link->new; 248 $atom_link->type($link->{type}); 249 $atom_link->rel($link->{rel}); 250 $atom_link->href($link->{href}->canonical); 251 $feed->add_link($atom_link); 252 } 249 253 250 254 # construct a feed from the most recent 12 bookmarks
Note: See TracChangeset
for help on using the changeset viewer.