From 8d25800c67ad65defd98771bba2331ee64104f98 Mon Sep 17 00:00:00 2001 From: dakkar Date: Wed, 7 Jan 2009 12:51:13 +0000 Subject: feed fatti, e pure col test manca: testare feed intl, fare feed dei tag, mettere i tag nei feed git-svn-id: svn://luxion/repos/WebCoso/trunk@402 fcb26f47-9200-0410-b104-b98ab5b095f3 --- lib/WebCoso/Common.pm | 32 ++++++++++++++++++++++---- lib/WebCoso/TT.pm | 36 ++++++++++++++++++++++++----- lib/WebCoso/XSLT.pm | 4 +++- t/test-site-output/feed.it.xml | 12 ++++++++++ t/test-site/src/common/base-feed.tt | 18 +++++++++++++++ t/test-site/src/common/du2html.xsl | 16 +++++++++++-- t/test-site/src/common/fillFeed.xsl | 46 ++++++++++++++++++++++++++----------- t/test-site/src/feed.it.tt | 15 +----------- t/whole-01.t | 6 ++--- 9 files changed, 141 insertions(+), 44 deletions(-) create mode 100644 t/test-site-output/feed.it.xml create mode 100644 t/test-site/src/common/base-feed.tt diff --git a/lib/WebCoso/Common.pm b/lib/WebCoso/Common.pm index 5420063..eed6f3a 100644 --- a/lib/WebCoso/Common.pm +++ b/lib/WebCoso/Common.pm @@ -37,14 +37,20 @@ sub typedAs { } sub dstUriFor { - my ($name,$short)=(@_,1); - DEBUG("dstUriFor($name,$short)"); + my ($name,$path,$short)=@_; + $short=1 unless defined $short; + $path||=''; + DEBUG("dstUriFor($name,$path,$short)"); if ($short) { $name=~s{/[^/]+$}{/}; } else { $name=typedAs($name,'html'); } + if ($path) { + $name=file($name)->absolute(file($path)->parent)->relative($SRCPATH); + $name="$SRCPATH/$name"; + } $name=~s{^\Q$SRCPATH\E/}{$DSTBASEURL}; DEBUG("dstUriFor -> $name"); return $name; @@ -53,9 +59,7 @@ sub dstUriFor { sub srcXMLFor { my ($lang,$path,$name)=@_; - $name="$name"; # force it to a string, since it might be an XML Node - - my $doc_name=$name; + my $doc_name="$name"; # force it to a string, since it might be an XML Node $doc_name=~s{\.html$}{.du.xml}; $doc_name=~s{/$}{/document.$lang.du.xml}; if ($doc_name=~m{^\Q$DSTBASEURL\E}) { @@ -94,6 +98,24 @@ sub getTitleFor { return $title; } +sub getAtomIdFor { + my ($fc,$lang,$path,$name)=@_; + DEBUG("getAtomIdFor($lang,$path,$name)"); + my $doc_name=srcXMLFor($lang,$path,$name); + DEBUG("getAtomIdFor -> $doc_name"); + + my $doc=$fc->get($doc_name); + unless ($doc) { + LOGWARN("No document for <$doc_name>, returning ''"); + return ''; + } + my $atomId=$xpath->findnodes( + q{/document/docinfo/field[field_name='Id']/field_body}, + $doc); + $atomId=~s{(?:\A\s+)|(?:\s+\z)}{}smgx; + return $atomId; +} + { my $zero=DateTime->from_epoch(epoch=>0); sub getDatesFor { diff --git a/lib/WebCoso/TT.pm b/lib/WebCoso/TT.pm index b6962fd..15e2072 100644 --- a/lib/WebCoso/TT.pm +++ b/lib/WebCoso/TT.pm @@ -4,18 +4,43 @@ use warnings; use WebCoso::Common; use Path::Class; use Template; +use Template::Stash; use Log::Log4perl ':easy'; +$Template::Stash::HASH_OPS->{sortf}=sub { + my ($hash,$field)=@_; + + if ($field) { + return [ sort { lc $hash->{$a}{$field} cmp lc $hash->{$b}{$field} } (keys %$hash )]; + } + else { + return [ sort { lc $hash->{$a} cmp lc $hash->{$b} } (keys %$hash )]; + } +}; + +$Template::Stash::HASH_OPS->{nsortf}=sub { + my ($hash,$field)=@_; + + if ($field) { + return [ sort { $hash->{$a}{$field} <=> $hash->{$b}{$field} } (keys %$hash )]; + } + else { + return [ sort { $hash->{$a} <=> $hash->{$b} } (keys %$hash )]; + } +}; + sub new { my ($class,%opts)=@_; - $opts{stash}||={ + my $self={%opts}; + bless $self,$class; + + $self->{stash}||={ dstUriFor => \&WebCoso::Common::dstUriFor, isLang => \&WebCoso::Common::isLang, + atomIdFor => sub{WebCoso::Common::getAtomIdFor($self->{fc},@_)}, }; - my $self={%opts}; - $self->{template_provider}=Template::Provider->new({ INCLUDE_PATH=> $self->{TMPLPATH}, ABSOLUTE=>1, @@ -57,14 +82,13 @@ sub new { pop @{$self->{template_provider}->include_path}; }; - bless $self,$class; + return $self; } - sub expandTT { my ($self)=@_; return $self->{expander} - } +} 1; diff --git a/lib/WebCoso/XSLT.pm b/lib/WebCoso/XSLT.pm index cc64cfb..09c5b3f 100644 --- a/lib/WebCoso/XSLT.pm +++ b/lib/WebCoso/XSLT.pm @@ -20,6 +20,8 @@ sub new { $self->{xslt_proc}->register_function($NS,'title-for', sub{$self->getTitleXML(WebCoso::Common::getTitleFor($self->{fc},@_))}); + $self->{xslt_proc}->register_function($NS,'dst-uri-for', + sub{WebCoso::Common::dstUriFor(@_)}); $self->{xslt_proc}->register_function($NS,'tagged',sub{$self->getTagsXML}); $self->{xslt_proc}->register_function($NS,'dates-for', sub{$self->getDatesXML(WebCoso::Common::getDatesFor($self->{fc},@_))}); @@ -79,7 +81,7 @@ sub new { language => $matches->[1], filename => $deps->[-1], )); - $self->{fc}->put($target,$xslt->output_string($out)); + $self->{fc}->put($target,$out); }; bless $self,$class; diff --git a/t/test-site-output/feed.it.xml b/t/test-site-output/feed.it.xml new file mode 100644 index 0000000..df11489 --- /dev/null +++ b/t/test-site-output/feed.it.xml @@ -0,0 +1,12 @@ + + +Gianni Ceccarellidakkar@thenautilus.nethttp://www.thenautilus.net/thenautilus.net2008-03-01T09:36:00+00002008-02-29T21:09:09+0000/bar/baz/
bar-baz italiano +

sticaz +

2008-02-29T21:09:09+0000/foo/
Pagina foo

foo +

2008-03-01T09:06:41+0000/bar/
bar (generato) +
  • line 1 +
  • line 2 +
  • line 3 +

link: bar-baz italiano +

2008-03-01T09:36:00+0000/
Pagina principale +
diff --git a/t/test-site/src/common/base-feed.tt b/t/test-site/src/common/base-feed.tt new file mode 100644 index 0000000..e2669e3 --- /dev/null +++ b/t/test-site/src/common/base-feed.tt @@ -0,0 +1,18 @@ +[% USE df = DateTime::Format('DateTime::Format::Strptime', + { pattern => '%FT%T%z', + locale => 'en_US', + time_zone => 'GMT' }) -%] +[% USE Dumper -%] +[% docs=changed.nsortf('last_change') -%] + + +[% l=docs.last;df.format(changed.$l.last_change) %] +[% FOR doc IN docs; NEXT UNLESS isLang(language,doc) -%] + + [% IF changed.$doc.creation %][% df.format(changed.$doc.creation) %][% END %] + [% IF changed.$doc.last_change %][% df.format(changed.$doc.last_change) %][% END %] + [% atomIdFor(language,doc,path) %] + [% dstUriFor(doc,path) %] + +[% END -%] + diff --git a/t/test-site/src/common/du2html.xsl b/t/test-site/src/common/du2html.xsl index 88c70b0..8b73a82 100644 --- a/t/test-site/src/common/du2html.xsl +++ b/t/test-site/src/common/du2html.xsl @@ -15,6 +15,15 @@ doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN" indent="yes"/> + + @@ -23,14 +32,14 @@ - + - + @@ -39,6 +48,9 @@ + + diff --git a/t/test-site/src/common/fillFeed.xsl b/t/test-site/src/common/fillFeed.xsl index e6077eb..04a6de3 100644 --- a/t/test-site/src/common/fillFeed.xsl +++ b/t/test-site/src/common/fillFeed.xsl @@ -1,7 +1,8 @@ @@ -13,23 +14,42 @@ - - - - - + + + + Gianni Ceccarelli + dakkar@thenautilus.net + + http://www.thenautilus.net/ + + thenautilus.net + + + - - + + + + + + + + - - - - + + + +
+ +
+
+ +
- +
+
\ No newline at end of file diff --git a/t/test-site/src/feed.it.tt b/t/test-site/src/feed.it.tt index 9a7a4cd..f7b7730 100644 --- a/t/test-site/src/feed.it.tt +++ b/t/test-site/src/feed.it.tt @@ -1,14 +1 @@ -[% USE df = DateTime::Format('DateTime::Format::Strptime', - { pattern => '%F %T', - locale => 'en_US', - time_zone => 'GMT' }) -%] - - -[% FOR c IN changed; NEXT UNLESS isLang(language,c.key) -%] - - [% IF c.value.creation %][% df.format(c.value.creation) %][% END %] - [% IF c.value.last_change %][% df.format(c.value.last_change) %][% END %] - [% dstUriFor(c.key) %] - -[% END -%] - +[% INCLUDE 'base-feed.tt' %] diff --git a/t/whole-01.t b/t/whole-01.t index 639ecc0..f270c5e 100644 --- a/t/whole-01.t +++ b/t/whole-01.t @@ -8,13 +8,13 @@ chdir file(__FILE__)->parent->parent->stringify; $ENV{PERL5LIB}=join ':',@INC; -system($^X,qw(blib/script/webcoso.pl -s t/test-site/src/ -d t/test-site/output/ -I t/test-site/common/ --clean)) +system($^X,qw(blib/script/webcoso.pl -s t/test-site/src/ -d t/test-site/output/ -I t/test-site/src/common/ --clean)) and die "Problems running webcoso.pl (clean): $?\n"; -system($^X,qw(blib/script/webcoso.pl -s t/test-site/src/ -d t/test-site/output/ -I t/test-site/common/)) +system($^X,qw(blib/script/webcoso.pl -s t/test-site/src/ -d t/test-site/output/ -I t/test-site/src/common/)) and die "Problems running webcoso.pl: $?\n"; is(system(qw(diff -r -x .svn -I),'\(Ultima modifica\|Latest change\)',qw(t/test-site/output/ t/test-site-output/)),0,'output as expected'); -system($^X,qw(blib/script/webcoso.pl -s t/test-site/src/ -d t/test-site/output/ -I t/test-site/common/ --clean)) +system($^X,qw(blib/script/webcoso.pl -s t/test-site/src/ -d t/test-site/output/ -I t/test-site/src/common/ --clean)) and die "Problems running webcoso.pl (clean): $?\n"; -- cgit v1.2.3