diff options
author | dakkar <dakkar@luxion> | 2005-11-08 13:15:46 +0000 |
---|---|---|
committer | dakkar <dakkar@luxion> | 2005-11-08 13:15:46 +0000 |
commit | 78ba357af675bfc0ac7c6bfc23353565d94fd786 (patch) | |
tree | 09d863884b12fa0d7d9e7c2b0e835155e2d23fcc | |
parent | form di aggiunta bookmark funzionante (diff) | |
download | Bookmarks-78ba357af675bfc0ac7c6bfc23353565d94fd786.tar.gz Bookmarks-78ba357af675bfc0ac7c6bfc23353565d94fd786.tar.bz2 Bookmarks-78ba357af675bfc0ac7c6bfc23353565d94fd786.zip |
ora il BookmarksManager gestisce per bene i tag multipli, e i template sono fatti meglio
-rw-r--r-- | lib/Bookmarks.pm | 13 | ||||
-rw-r--r-- | lib/Bookmarks/C/Main.pm | 82 | ||||
-rw-r--r-- | lib/Bookmarks/V/TT.pm | 12 | ||||
-rw-r--r-- | root/add_form | 5 | ||||
-rw-r--r-- | root/links | 91 | ||||
-rw-r--r-- | root/tags | 5 |
6 files changed, 167 insertions, 41 deletions
diff --git a/lib/Bookmarks.pm b/lib/Bookmarks.pm index 56e098c..fb88958 100644 --- a/lib/Bookmarks.pm +++ b/lib/Bookmarks.pm @@ -5,7 +5,12 @@ use Catalyst qw/-Debug Prototype DefaultEnd/; our $VERSION = '0.01'; -Bookmarks->config( name => 'Bookmarks' ); +Bookmarks->config( + name => 'Bookmarks', + 'Bookmarks::View::TT' => { + TIMER => 0, + }, +); Bookmarks->setup; @@ -34,6 +39,12 @@ sub default : Private { $c->res->redirect($c->req->base.'tags'); } +sub favicon : Path('favicon.ico') { + my ( $self, $c ) = @_; + $c->res->status(404); + $c->res->body('nonce'); +} + =back =head1 AUTHOR diff --git a/lib/Bookmarks/C/Main.pm b/lib/Bookmarks/C/Main.pm index 2cab5ee..b6170c0 100644 --- a/lib/Bookmarks/C/Main.pm +++ b/lib/Bookmarks/C/Main.pm @@ -3,7 +3,6 @@ package Bookmarks::C::Main; use strict; use base 'Catalyst::Base'; use Bookmarks::Utils; -use YAML; =head1 NAME @@ -25,6 +24,12 @@ Catalyst component. =cut +sub auto : Private { + my ( $self, $c ) = @_; + $c->stash->{href}=Bookmarks::C::Main::LinkHelper->new($c); + return 1; +} + sub tags : Global { my ( $self, $c ) = @_; $c->stash->{template}='tags'; @@ -54,9 +59,10 @@ sub icon : Global { my ( $self, $c ) = @_; my $link=Bookmarks::M::DB::Links->retrieve($c->req->param('link')); - if ($link->get_icon()) { + my $icon=$link->get_icon(); + if ($icon) { $c->res->content_type('image/x-icon'); - $c->res->body($link->get_icon()); + $c->res->body($icon); } else { $c->res->status(404); @@ -64,12 +70,6 @@ sub icon : Global { } } -sub favicon : Path('favicon.ico') { - my ( $self, $c ) = @_; - $c->res->status(404); - $c->res->body('nonce'); -} - sub jump : Global { my ( $self, $c ) = @_; @@ -91,9 +91,6 @@ sub add : Global { } my @tags=split /[ +]/,($c->req->param('tag')||''); - print {*STDERR} Dump(\%pre_link); - print {*STDERR} Dump($c->req); - # GET: prepare the form from the URL params if ($c->req->method eq 'GET') { $c->stash->{link}=\%pre_link; @@ -151,4 +148,65 @@ it under the same terms as perl itself. =cut +package Bookmarks::C::Main::LinkHelper; +use YAML; +use URI; + +sub new { + my ($class,$c)=@_; + return bless {c=>$c,base=>$c->req->base()},$class; +} + +sub tag_info { + my ($self, $tag)=@_; + return URI->new( + $self->{base} . 'tag-info/' . $tag->name() + )->as_string(); +} + +sub remove_tag { + my ($self, $tagset, $tag)=@_; + my @tags=grep {$_ ne $tag} $tagset->tags(); + return URI->new( + $self->{base} . 'tag/' + . (join '+',map {$_->name()} @tags) + )->as_string(); +} + +sub add_tag { + my ($self, $tagset, $tag)=@_; + return URI->new( + $self->{base} . 'tag/' + . (join '+',map {$_->name()} ($tagset->tags(),$tag)) + )->as_string(); +} + +sub to_tag { + my ($self, $tag)=@_; + return URI->new( + $self->{base} . 'tag/' . $tag->name() + )->as_string(); +} + +sub link_icon { + my ($self, $link)=@_; + my $uri=URI->new($self->{base} . 'icon'); + $uri->query_form(link=>$link->pk()); + return $uri->as_string(); +} + +sub link { + my ($self, $link)=@_; + my $uri=URI->new($self->{base} . 'jump'); + $uri->query_form(link=>$link->pk()); + return $uri->as_string(); +} + +sub add_action { + my ($self)=@_; + return URI->new( + $self->{base} . 'add' + )->as_string(); +} + 1; diff --git a/lib/Bookmarks/V/TT.pm b/lib/Bookmarks/V/TT.pm index d2063b6..f2f8e7d 100644 --- a/lib/Bookmarks/V/TT.pm +++ b/lib/Bookmarks/V/TT.pm @@ -3,6 +3,18 @@ package Bookmarks::V::TT; use strict; use base 'Catalyst::View::TT'; +sub process { + my ( $self, $c ) = @_; + my $ret=$self->NEXT::process($c); + if ($ret==1 + and $c->res->content_type =~ m{text/html}) { + my $ct=$c->res->content_type; + $ct=~s{text/html}{application/xhtml+xml}; + $c->res->content_type($ct); + } + return $ret; +} + =head1 NAME Bookmarks::V::TT - TT View Component diff --git a/root/add_form b/root/add_form index bbb608a..10e83bb 100644 --- a/root/add_form +++ b/root/add_form @@ -1,9 +1,10 @@ -<html> +<?xml version="1.0" encoding="utf-8"?> +<html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>add</title> </head> <body> -<form action="[% base _ 'add' %]" method="post"> +<form action="[% href.add_action() %]" method="post"> <p>Link: <input name="url" type="text" value="[% link.url %]" /></p> <p>Title: <input name="title" type="text" value="[% link.title %]" /></p> <p>Description: <input name="descr" type="text" value="[% link.descr %]" /></p> @@ -1,25 +1,68 @@ -<html> -<head> -<title>links</title> -</head> -<body> -<p> -[% IF tagset.size() == 1 %]Tag:[% ELSE %]Tags:[% END %] -[% FOR tag IN tagset.tags %] - [% tag.name %] ( [% tag.descr %] ) - -[% END %]</p> -<p>Related:</p> -<ul> -[% FOR rtag IN related %] -<li><a href="[% base _ 'tag/' _ rtag.name %]">[% rtag.name %]</a></li> -[% END %] -</ul> -<p>Links:</p> -<ol> -[% FOR link IN links %] -<li><img src="[% base _ 'icon?link=' _ link.pk %]" /> <a href="[% base _ 'jump?link=' _ link.pk %]">»[% link.title %]«</a> (creato: [% link.add_date() %]) -[% FOR rtag IN link.tags %] <a href="[% base _ 'tag/' _ rtag.name %]">[% rtag.name %]</a> - [% END %]</li> -[% END %] -</ol> -</body> +<?xml version="1.0" encoding="utf-8"?> +<html xmlns="http://www.w3.org/1999/xhtml"> + <head> + <title> + Links for + [% FOR tag IN tagset.tags; + tag.name; + ', ' UNLESS loop.last; + END %] + </title> + </head> + <body> + <div id="tagset"> + <h2>[% IF tagset.size() == 1 %]Tag:[% ELSE %]Tags:[% END %]</h2> + <ul> + [% FOR tag IN tagset.tags %] + <li> + <span class="tag name"> + <a href="[% href.tag_info(tag) %]">[% tag.name %]</a> + </span> + [% IF tagset.size() > 1 %] + <span class="tag remove"> + <a href="[% href.remove_tag(tagset,tag) %]">-</a> + </span> + [% END %] + </li> + [% END %] + </ul> + </div> + <div id="related"> + <h2>Related:</h2> + <ul> + [% FOR rtag IN related %] + <li> + <span class="tag name"><a href="[% href.to_tag(rtag) %]">[% rtag.name %]</a></span> + <span class="tag add"> + <a href="[% href.add_tag(tagset,rtag) %]">+</a> + </span> + </li> + [% END %] + </ul> + </div> + <div id="links"> + <h2>Links:</h2> + <ol> + [% FOR link IN links %] + <li> + <span class="link icon"> + <img src="[% href.link_icon(link) %]" /> + </span> + <span class="link title"> + <a href="[% href.link(link) %]">»[% link.title %]«</a> + </span> + <ul> + [% FOR rtag IN link.tags %] + <li> + <span class="tag name"> + <a href="[% href.to_tag(rtag) %]">[% rtag.name %]</a> + </span> + </li> + [% END %] + </ul> + </li> + [% END %] + </ol> + </div> + </body> </html> @@ -1,11 +1,12 @@ -<html> +<?xml version="1.0" encoding="utf-8"?> +<html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>tags</title> </head> <body> <ol> [% FOR tag IN tags %] -<li><a href="[% base _ 'tag/' _ tag.name %]">[% tag.name %]</a> ([% tag.how_many %])</li> +<li><a href="[% href.to_tag(tag) %]">[% tag.name %]</a> ([% tag.how_many %])</li> [% END %] </ol> </body> |