From 78ba357af675bfc0ac7c6bfc23353565d94fd786 Mon Sep 17 00:00:00 2001 From: dakkar Date: Tue, 8 Nov 2005 13:15:46 +0000 Subject: ora il BookmarksManager gestisce per bene i tag multipli, e i template sono fatti meglio --- lib/Bookmarks.pm | 13 ++++++- lib/Bookmarks/C/Main.pm | 82 +++++++++++++++++++++++++++++++++++++------- lib/Bookmarks/V/TT.pm | 12 +++++++ root/add_form | 5 +-- root/links | 91 ++++++++++++++++++++++++++++++++++++------------- 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 @@ - + + add -
+

Link:

Title:

Description:

diff --git a/root/links b/root/links index 40bfa51..210a7e9 100644 --- a/root/links +++ b/root/links @@ -1,25 +1,68 @@ - - -links - - -

-[% IF tagset.size() == 1 %]Tag:[% ELSE %]Tags:[% END %] -[% FOR tag IN tagset.tags %] - [% tag.name %] ( [% tag.descr %] ) - -[% END %]

-

Related:

- -

Links:

-
    -[% FOR link IN links %] -
  1. »[% link.title %]« (creato: [% link.add_date() %]) -[% FOR rtag IN link.tags %] [% rtag.name %] - [% END %]
  2. -[% END %] -
- + + + + + Links for + [% FOR tag IN tagset.tags; + tag.name; + ', ' UNLESS loop.last; + END %] + + + +
+

[% IF tagset.size() == 1 %]Tag:[% ELSE %]Tags:[% END %]

+
    + [% FOR tag IN tagset.tags %] +
  • + + [% tag.name %] + + [% IF tagset.size() > 1 %] + + - + + [% END %] +
  • + [% END %] +
+
+ + + diff --git a/root/tags b/root/tags index 748631e..888f50e 100644 --- a/root/tags +++ b/root/tags @@ -1,11 +1,12 @@ - + + tags
    [% FOR tag IN tags %] -
  1. [% tag.name %] ([% tag.how_many %])
  2. +
  3. [% tag.name %] ([% tag.how_many %])
  4. [% END %]
-- cgit v1.2.3