Changeset 66 in bookmarks


Ignore:
Timestamp:
02/04/14 15:21:17 (11 years ago)
Author:
peter
Message:
  • the bookmark.tt template takes a hash or object named bookmark as its only variable
  • moved the calculation of a human-readable timestamp and the ISO timestamps for the WayBack machine from the BookmarkController class into the Bookmark class as methods (created, updated, created_iso, and updated_iso
  • moved the exists flag into the Bookmark class as an attribute
Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Bookmark.pm

    r46 r66  
    22 
    33use Moose; 
     4use HTTP::Date qw{time2isoz}; 
    45 
    56has id    => ( is => 'ro' ); 
     
    1516has tags  => ( is => 'rw' ); 
    1617has bookmark_uri => ( is => 'rw' ); 
     18has exists => ( is => 'ro' ); 
     19 
     20sub created { scalar localtime $_[0]->ctime } 
     21sub updated { scalar localtime $_[0]->mtime } 
     22sub created_iso { (my $iso = time2isoz($_[0]->ctime)) =~ s/\D//g; return $iso; } 
     23sub updated_iso { (my $iso = time2isoz($_[0]->ctime)) =~ s/\D//g; return $iso; } 
    1724 
    1825sub BUILD { 
  • trunk/BookmarkController.pm

    r64 r66  
    119119        $template->process( 
    120120            'bookmark.tt', 
    121             { 
    122                 uri   => $self->request->param('uri'), 
    123                 title => $self->request->param('title') || '', 
     121            {  
     122                bookmark => { 
     123                    uri   => $self->request->param('uri'), 
     124                    title => $self->request->param('title') || '', 
     125                }, 
    124126            }, 
    125127            \my $output, 
     
    337339        } else { 
    338340            # display the bookmark form for this bookmark 
    339             # TODO: these should probably be methods on the Bookmark class 
    340             $bookmark->{exists} = 1; 
    341             $bookmark->{created} = localtime($bookmark->ctime); 
    342             $bookmark->{updated} = localtime($bookmark->mtime); 
    343             ($bookmark->{created_iso} = time2isoz($bookmark->ctime)) =~ s/\D//g; 
    344             ($bookmark->{updated_iso} = time2isoz($bookmark->mtime)) =~ s/\D//g; 
    345341            my $template = Template->new; 
    346342            $template->process( 
    347343                'bookmark.tt', 
    348                 $bookmark, 
     344                { bookmark => $bookmark }, 
    349345                \my $output, 
    350346            ); 
  • trunk/Bookmarks.pm

    r57 r66  
    6363    return Bookmark->new({ 
    6464        %$bookmark, 
     65        exists   => 1, 
    6566        tags     => [ $self->get_tags({ uri => $bookmark->{uri} }) ], 
    6667        base_uri => $self->base_uri, 
  • trunk/bookmark.tt

    r64 r66  
    11<html> 
    22  <head> 
    3     <title>Bookmark: [% title or uri %]</title> 
     3    <title>Bookmark: [% bookmark.title or bookmark.uri %]</title> 
    44    <style type="text/css"> 
    55body, th, td { 
     
    2121    <div> 
    2222      <h1> 
    23       [% UNLESS exists %] 
     23      [% UNLESS bookmark.exists %] 
    2424        <strong>New bookmark:</strong> 
    2525      [% END %] 
    26       <a href="[% uri | html %]" target="_blank">[% title or uri %]</a> 
     26      <a href="[% bookmark.uri | html %]" target="_blank">[% bookmark.title or bookmark.uri %]</a> 
    2727      </h1> 
    28       [% IF exists %] 
     28      [% IF bookmark.exists %] 
    2929        <p class="timestamps"> 
    30           Bookmark created <a href="http://web.archive.org/web/[% created_iso %]/[% uri %]" title="Nearest Wayback Machine Link" target="_blank">[% created %]</a>[% IF mtime != ctime %]; updated 
    31           <a href="http://web.archive.org/web/[% updated_iso %]/[% uri %]" title="Nearest Wayback Machine Link" target="_blank">[% updated %]</a>[% END %] 
     30          Bookmark created <a href="http://web.archive.org/web/[% bookmark.created_iso %]/[% bookmark.uri %]" title="Nearest Wayback Machine Link" target="_blank">[% bookmark.created %]</a>[% IF bookmark.mtime != bookmark.ctime %]; updated 
     31          <a href="http://web.archive.org/web/[% bookmark.updated_iso %]/[% bookmark.uri %]" title="Nearest Wayback Machine Link" target="_blank">[% bookmark.updated %]</a>[% END %] 
    3232        </p> 
    33         [% IF tags.size %] 
     33        [% IF bookmark.tags.size %] 
    3434          <p class="tags">Tagged as: 
    35             [% FOREACH tag IN tags %] 
     35            [% FOREACH tag IN bookmark.tags %] 
    3636              <a href=".?tag=[% tag %]" class="tag" target="_blank" onclick="if (opener && !opener.closed) { opener.location = this.href; return false; }">[% tag %]</a> 
    3737            [% END %] 
     
    4444            <th>URI:</th> 
    4545            <td> 
    46               <input type="text" name="uri" value="[% uri | html %]" size="80"/> 
     46              <input type="text" name="uri" value="[% bookmark.uri | html %]" size="80"/> 
    4747            </td> 
    4848          </tr> 
     
    5050            <th>Title:</th> 
    5151            <td> 
    52               <input type="text" name="title" value="[% title | html %]" size="80"/> 
     52              <input type="text" name="title" value="[% bookmark.title | html %]" size="80"/> 
    5353            </td> 
    5454          </tr> 
     
    5656            <th>Tags:</th> 
    5757            <td> 
    58               <input type="text" name="tags" value="[% tags.join(' ') | html %]" size="80"/> 
     58              <input type="text" name="tags" value="[% bookmark.tags.join(' ') | html %]" size="80"/> 
    5959            </td> 
    6060          </tr> 
Note: See TracChangeset for help on using the changeset viewer.