From 74927a08f548ed3ce6bc330ddce605abb9a02a07 Mon Sep 17 00:00:00 2001 From: dakkar Date: Thu, 8 Jan 2009 16:34:23 +0000 Subject: aggirato il problema dei titoli che in alcune lingue non esistono git-svn-id: svn://luxion/repos/WebCoso/trunk@407 fcb26f47-9200-0410-b104-b98ab5b095f3 --- lib/WebCoso/Common.pm | 20 ++++++++++++--- lib/WebCoso/XSLT.pm | 25 ++++++++++++++++++- t/test-site-output/bar/baz/document.en.html | 9 ++++--- t/test-site-output/bar/baz/document.it.html | 9 ++++--- t/test-site-output/bar/document.en.html | 9 ++++--- t/test-site-output/bar/document.it.html | 9 ++++--- t/test-site-output/document.en.html | 9 ++++--- t/test-site-output/document.it.html | 9 ++++--- t/test-site-output/en-only/document.en.html | 29 ++++++++++++++++++++++ t/test-site-output/feed.it.xml | 8 +++--- t/test-site-output/foo/document.en.html | 9 ++++--- t/test-site-output/foo/document.it.html | 9 ++++--- t/test-site-output/tags/one/document.en.html | 9 ++++--- t/test-site-output/tags/one/document.it.html | 9 ++++--- t/test-site-output/tags/one/feed.en.xml | 4 +-- t/test-site-output/tags/one/feed.it.xml | 4 +-- t/test-site-output/tags/three/bis/document.en.html | 9 ++++--- t/test-site-output/tags/three/bis/document.it.html | 9 ++++--- t/test-site-output/tags/three/document.en.html | 9 ++++--- t/test-site-output/tags/three/document.it.html | 9 ++++--- t/test-site-output/tags/two/document.en.html | 10 +++++--- t/test-site-output/tags/two/document.it.html | 9 ++++--- t/test-site-output/tags/two/feed.en.xml | 12 +++++++++ t/test-site-output/tags/two/feed.it.xml | 9 +++++++ t/test-site/src/common/base-feed.tt | 2 +- t/test-site/src/common/du2html.xsl | 25 ++++++++++++++++--- t/test-site/src/common/fillFeed.xsl | 2 +- t/test-site/src/en-only/document.en.rest.txt | 7 ++++++ t/test-site/src/en-only/du2html.xsl | 1 + t/test-site/src/tags/two/feed.en.tt | 1 + t/test-site/src/tags/two/feed.it.tt | 1 + t/test-site/src/tags/two/fillFeed.xsl | 1 + 32 files changed, 231 insertions(+), 65 deletions(-) create mode 100644 t/test-site-output/en-only/document.en.html create mode 100644 t/test-site-output/tags/two/feed.en.xml create mode 100644 t/test-site-output/tags/two/feed.it.xml create mode 100644 t/test-site/src/en-only/document.en.rest.txt create mode 120000 t/test-site/src/en-only/du2html.xsl create mode 120000 t/test-site/src/tags/two/feed.en.tt create mode 120000 t/test-site/src/tags/two/feed.it.tt create mode 120000 t/test-site/src/tags/two/fillFeed.xsl diff --git a/lib/WebCoso/Common.pm b/lib/WebCoso/Common.pm index 6c9a433..f01e739 100644 --- a/lib/WebCoso/Common.pm +++ b/lib/WebCoso/Common.pm @@ -8,6 +8,7 @@ use DateTime; use DateTime::Format::DateParse; use Log::Log4perl ':easy'; use List::MoreUtils 'uniq'; +use List::Util 'first'; our $SRCPATH='src'; our $DSTPATH='dst'; @@ -91,10 +92,23 @@ sub isLang { sub getTitleFor { my ($fc,$lang,$path,$name)=@_; DEBUG("getTitleFor($lang,$path,$name)"); - my $doc_name=srcXMLFor($lang,$path,$name); - DEBUG("getTitleFor -> $doc_name"); + my ($doc_name,$doc); + + if (ref($lang)) { # assume it's an array + for my $l (@$lang) { + $doc_name=srcXMLFor($l,$path,$name); + DEBUG("getTitleFor -> try $doc_name"); + $doc=$fc->get($doc_name); + last if $doc; + } + } + else { + $doc_name=srcXMLFor($lang,$path,$name); + DEBUG("getTitleFor -> $doc_name"); + + $doc=$fc->get($doc_name); + } - my $doc=$fc->get($doc_name); unless ($doc) { LOGWARN("No document for <$doc_name>, returning <$name>"); return "$name"; # force it to a string, since it might be an XML Node diff --git a/lib/WebCoso/XSLT.pm b/lib/WebCoso/XSLT.pm index 9cbeab0..28643c5 100644 --- a/lib/WebCoso/XSLT.pm +++ b/lib/WebCoso/XSLT.pm @@ -20,7 +20,7 @@ sub new { $self->{xslt_proc}=XML::LibXSLT->new(); $self->{xslt_proc}->register_function($NS,'title-for', - sub{$self->getTitleXML(WebCoso::Common::getTitleFor($self->{fc},@_))}); + sub{$self->getTitleForXML(@_)}); $self->{xslt_proc}->register_function($NS,'dst-uri-for', sub{WebCoso::Common::dstUriFor(@_)}); $self->{xslt_proc}->register_function($NS,'tagged',sub{$self->getTagsXML}); @@ -158,6 +158,29 @@ sub getDatesXML { } } +sub getTitleForXML { + my ($self,$lang,$path,$name)=@_; + + my $lang_cleaned; + if (ref($lang) && $lang->can('get_nodelist')) { + DEBUG('getTitleForXML with multple languages'); + for my $node ($lang->get_nodelist) { + my $val=$node->findvalue('normalize-space(string(.))'); + DEBUG(" <$val>"); + push @{$lang_cleaned},$val if length($val)>0; + } + } + else { + DEBUG('getTitleForXML with a single language'); + $lang_cleaned=$lang; + } + return $self->getTitleXML(WebCoso::Common::getTitleFor( + $self->{fc}, + $lang_cleaned, + $path, + $name)); +} + sub getTitleXML { my ($self,$title)=@_; diff --git a/t/test-site-output/bar/baz/document.en.html b/t/test-site-output/bar/baz/document.en.html index 7621bb1..93628a2 100644 --- a/t/test-site-output/bar/baz/document.en.html +++ b/t/test-site-output/bar/baz/document.en.html @@ -1,5 +1,5 @@ - + bar-baz english

bar-baz english

sticaz @@ -15,7 +15,10 @@ (it | en)

Category 'two' -
Creato: 1970-01-01 00:00:00 - Ultima modifica: 2008-10-01 13:11:30
+ Ultima modifica: 2009-01-08 16:24:24 diff --git a/t/test-site-output/bar/baz/document.it.html b/t/test-site-output/bar/baz/document.it.html index c257503..9c95c18 100644 --- a/t/test-site-output/bar/baz/document.it.html +++ b/t/test-site-output/bar/baz/document.it.html @@ -1,5 +1,5 @@ - + bar-baz italiano

bar-baz italiano

sticaz @@ -14,11 +14,14 @@ (it | en)

Categoria 'two' -
Creato: 1970-01-01 00:00:00 - Ultima modifica: 2008-10-01 13:11:30
+ Ultima modifica: 2009-01-08 16:24:24 diff --git a/t/test-site-output/bar/document.en.html b/t/test-site-output/bar/document.en.html index a84b6e8..05956e1 100644 --- a/t/test-site-output/bar/document.en.html +++ b/t/test-site-output/bar/document.en.html @@ -1,5 +1,5 @@ - + bar (from template)

bar (from template)

Category 'two' -
Creato: 1970-01-01 00:00:00 - Ultima modifica: 2008-10-01 13:11:30
+ Ultima modifica: 2009-01-08 16:24:24 diff --git a/t/test-site-output/bar/document.it.html b/t/test-site-output/bar/document.it.html index f90b351..88418dd 100644 --- a/t/test-site-output/bar/document.it.html +++ b/t/test-site-output/bar/document.it.html @@ -1,5 +1,5 @@ - + bar (generato)

bar (generato)

Categoria 'two' -
Creato: 1970-01-01 00:00:00 - Ultima modifica: 2008-10-01 13:11:30
+ Ultima modifica: 2009-01-08 16:24:24 diff --git a/t/test-site-output/document.en.html b/t/test-site-output/document.en.html index f88fe09..1725e9e 100644 --- a/t/test-site-output/document.en.html +++ b/t/test-site-output/document.en.html @@ -1,5 +1,5 @@ - + Main page

Main page

Category 'two' -
Creato: 2008-03-01 10:04:00 - Ultima modifica: 2008-10-01 13:11:30
+ Ultima modifica: 2009-01-08 16:24:24 diff --git a/t/test-site-output/document.it.html b/t/test-site-output/document.it.html index 8c17a42..cdb014b 100644 --- a/t/test-site-output/document.it.html +++ b/t/test-site-output/document.it.html @@ -1,5 +1,5 @@ - + Pagina principale

Pagina principale

Categoria 'uno' @@ -13,11 +13,14 @@ (it | en)
Categoria 'two' -
Creato: 1970-01-01 00:00:00 - Ultima modifica: 2008-10-01 13:11:30
+ Ultima modifica: 2009-01-08 16:24:24 diff --git a/t/test-site-output/en-only/document.en.html b/t/test-site-output/en-only/document.en.html new file mode 100644 index 0000000..ac7f65d --- /dev/null +++ b/t/test-site-output/en-only/document.en.html @@ -0,0 +1,29 @@ + + +document in English +

document in English +

only in English! +

Category 'one' +
Category 'three/bis' +
Category 'two' +
+ Creato: 1970-01-01 00:00:00 + Ultima modifica: 2009-01-08 16:27:30
diff --git a/t/test-site-output/feed.it.xml b/t/test-site-output/feed.it.xml index 099020e..f8958ba 100644 --- a/t/test-site-output/feed.it.xml +++ b/t/test-site-output/feed.it.xml @@ -1,12 +1,12 @@ -Gianni Ceccarellidakkar@thenautilus.nethttp://www.thenautilus.net/thenautilus.net2008-03-01T09:37:45+00002007-09-09T11:18:59+0000/bar/baz/
bar-baz italiano +Gianni Ceccarellidakkar@thenautilus.nethttp://www.thenautilus.net/thenautilus.net2009-01-08T16:27:01+0000tag:thenautilus.net,2007-09-09T11:18:59+0000
bar-baz italiano

sticaz -

2007-09-09T12:01:07+0000/bar/
bar (generato) +

tag:thenautilus.net,2007-09-09T12:01:07+0000
bar (generato)
  • line 1
  • line 2
  • line 3

link: bar-baz italiano -

2007-09-09T12:01:07+0000/
Pagina principale -
2008-01-02T13:55:03+0000/foo/
Pagina foo

foo +

tag:thenautilus.net,2007-09-09T12:01:07+0000
Pagina principale +
tag:thenautilus.net,2008-01-02T13:55:03+0000
Pagina foo

foo

diff --git a/t/test-site-output/foo/document.en.html b/t/test-site-output/foo/document.en.html index a69175e..7ac8437 100644 --- a/t/test-site-output/foo/document.en.html +++ b/t/test-site-output/foo/document.en.html @@ -1,5 +1,5 @@ - + foo page

foo page

foo @@ -15,7 +15,10 @@ (it | en)

Category 'two' -
Creato: 1970-01-01 00:00:00 - Ultima modifica: 2008-10-01 13:11:30
+ Ultima modifica: 2009-01-08 16:24:24
diff --git a/t/test-site-output/foo/document.it.html b/t/test-site-output/foo/document.it.html index 5a7fe12..f2720d3 100644 --- a/t/test-site-output/foo/document.it.html +++ b/t/test-site-output/foo/document.it.html @@ -1,5 +1,5 @@ - + Pagina foo

Pagina foo

foo

Categoria 'uno'
Categoria 'two' -
Creato: 1970-01-01 00:00:00 - Ultima modifica: 2008-10-01 13:11:30
+ Ultima modifica: 2009-01-08 16:24:24 diff --git a/t/test-site-output/tags/one/document.en.html b/t/test-site-output/tags/one/document.en.html index 99e7b46..0214576 100644 --- a/t/test-site-output/tags/one/document.en.html +++ b/t/test-site-output/tags/one/document.en.html @@ -1,5 +1,5 @@ - + Category 'one'
Creato: 1970-01-01 00:00:00 - Ultima modifica: 2008-10-01 13:11:30
+ Ultima modifica: 2009-01-08 16:30:06 diff --git a/t/test-site-output/tags/one/document.it.html b/t/test-site-output/tags/one/document.it.html index 57876be..046559b 100644 --- a/t/test-site-output/tags/one/document.it.html +++ b/t/test-site-output/tags/one/document.it.html @@ -1,5 +1,5 @@ - + Categoria 'uno'

Categoria 'uno'

Categoria 'two' -
Creato: 1970-01-01 00:00:00 - Ultima modifica: 2008-10-01 13:11:30
+ Ultima modifica: 2009-01-08 16:30:06 diff --git a/t/test-site-output/tags/one/feed.en.xml b/t/test-site-output/tags/one/feed.en.xml index 2a88222..a33bebc 100644 --- a/t/test-site-output/tags/one/feed.en.xml +++ b/t/test-site-output/tags/one/feed.en.xml @@ -1,7 +1,7 @@ -Gianni Ceccarellidakkar@thenautilus.nethttp://www.thenautilus.net/thenautilus.net2008-03-01T09:37:45+00002007-09-09T11:18:59+0000/foo/
foo page +Gianni Ceccarellidakkar@thenautilus.nethttp://www.thenautilus.net/thenautilus.net2009-01-08T16:27:01+0000tag:thenautilus.net,2007-09-09T11:18:59+0000
foo page

foo -

2007-09-09T11:18:59+0000/bar/baz/
bar-baz english +

tag:thenautilus.net,2007-09-09T11:18:59+0000
bar-baz english

sticaz

diff --git a/t/test-site-output/tags/one/feed.it.xml b/t/test-site-output/tags/one/feed.it.xml index 42c77d0..d0be744 100644 --- a/t/test-site-output/tags/one/feed.it.xml +++ b/t/test-site-output/tags/one/feed.it.xml @@ -1,6 +1,6 @@ -Gianni Ceccarellidakkar@thenautilus.nethttp://www.thenautilus.net/thenautilus.net2008-03-01T09:37:45+00002007-09-09T11:18:59+0000/bar/baz/
bar-baz italiano +Gianni Ceccarellidakkar@thenautilus.nethttp://www.thenautilus.net/thenautilus.net2009-01-08T16:27:01+0000tag:thenautilus.net,2007-09-09T11:18:59+0000
bar-baz italiano

sticaz -

2008-01-02T13:55:03+0000/foo/
Pagina foo

foo +

tag:thenautilus.net,2008-01-02T13:55:03+0000
Pagina foo

foo

diff --git a/t/test-site-output/tags/three/bis/document.en.html b/t/test-site-output/tags/three/bis/document.en.html index 5e904c3..214641f 100644 --- a/t/test-site-output/tags/three/bis/document.en.html +++ b/t/test-site-output/tags/three/bis/document.en.html @@ -1,5 +1,5 @@ - + Category 'three/bis'
Creato: 1970-01-01 00:00:00 - Ultima modifica: 2008-10-01 13:11:30
+ Ultima modifica: 2009-01-08 16:30:06
diff --git a/t/test-site-output/tags/three/bis/document.it.html b/t/test-site-output/tags/three/bis/document.it.html index 42d23fb..89f256c 100644 --- a/t/test-site-output/tags/three/bis/document.it.html +++ b/t/test-site-output/tags/three/bis/document.it.html @@ -1,5 +1,5 @@ - + Categoria 'three/bis'

Categoria 'three/bis'

Categoria 'two' -
Creato: 1970-01-01 00:00:00 - Ultima modifica: 2008-10-01 13:11:30
+ Ultima modifica: 2009-01-08 16:30:06
diff --git a/t/test-site-output/tags/three/document.en.html b/t/test-site-output/tags/three/document.en.html index d769920..3286505 100644 --- a/t/test-site-output/tags/three/document.en.html +++ b/t/test-site-output/tags/three/document.en.html @@ -1,5 +1,5 @@ - + Category 'three'

Category 'three'

Category 'one' @@ -14,7 +14,10 @@ (it | en)
Category 'two' -
Creato: 1970-01-01 00:00:00 - Ultima modifica: 2008-10-01 13:11:30
+ Ultima modifica: 2009-01-08 16:30:06 diff --git a/t/test-site-output/tags/three/document.it.html b/t/test-site-output/tags/three/document.it.html index 83f699e..f3fbbbc 100644 --- a/t/test-site-output/tags/three/document.it.html +++ b/t/test-site-output/tags/three/document.it.html @@ -1,5 +1,5 @@ - + Categoria 'three'

Categoria 'three'

Categoria 'uno' @@ -13,11 +13,14 @@ (it | en)
Categoria 'two' -
Creato: 1970-01-01 00:00:00 - Ultima modifica: 2008-10-01 13:11:30
+ Ultima modifica: 2009-01-08 16:30:06 diff --git a/t/test-site-output/tags/two/document.en.html b/t/test-site-output/tags/two/document.en.html index 7667ba7..4fb702b 100644 --- a/t/test-site-output/tags/two/document.en.html +++ b/t/test-site-output/tags/two/document.en.html @@ -1,9 +1,10 @@ - + Category 'two'
Category 'one'
Category 'two' -
Creato: 1970-01-01 00:00:00 - Ultima modifica: 2008-10-01 13:11:30
+ Ultima modifica: 2009-01-08 16:30:06 diff --git a/t/test-site-output/tags/two/document.it.html b/t/test-site-output/tags/two/document.it.html index 12499d1..cbdc35b 100644 --- a/t/test-site-output/tags/two/document.it.html +++ b/t/test-site-output/tags/two/document.it.html @@ -1,5 +1,5 @@ - + Categoria 'two'

Categoria 'two'

Categoria 'two' -
Creato: 1970-01-01 00:00:00 - Ultima modifica: 2008-10-01 13:11:30
+ Ultima modifica: 2009-01-08 16:30:06 diff --git a/t/test-site-output/tags/two/feed.en.xml b/t/test-site-output/tags/two/feed.en.xml new file mode 100644 index 0000000..129e4c3 --- /dev/null +++ b/t/test-site-output/tags/two/feed.en.xml @@ -0,0 +1,12 @@ + + +Gianni Ceccarellidakkar@thenautilus.nethttp://www.thenautilus.net/thenautilus.net2009-01-08T16:27:01+0000tag:thenautilus.net,2007-09-09T11:18:59+0000
foo page +

foo +

tag:thenautilus.net,2007-09-09T12:01:07+0000
bar (from template) +
  • line 1 +
  • line 2 +
  • line 3 +

link: bar-baz english +

tag:thenautilus.net,2009-01-08T16:27:01+0000
document in English +

only in English! +

diff --git a/t/test-site-output/tags/two/feed.it.xml b/t/test-site-output/tags/two/feed.it.xml new file mode 100644 index 0000000..cdf3789 --- /dev/null +++ b/t/test-site-output/tags/two/feed.it.xml @@ -0,0 +1,9 @@ + + +Gianni Ceccarellidakkar@thenautilus.nethttp://www.thenautilus.net/thenautilus.net2009-01-08T16:27:01+0000tag:thenautilus.net,2007-09-09T12:01:07+0000
bar (generato) +
  • line 1 +
  • line 2 +
  • line 3 +

link: bar-baz italiano +

tag:thenautilus.net,2008-01-02T13:55:03+0000
Pagina foo

foo +

diff --git a/t/test-site/src/common/base-feed.tt b/t/test-site/src/common/base-feed.tt index 2559f29..d91ec0e 100644 --- a/t/test-site/src/common/base-feed.tt +++ b/t/test-site/src/common/base-feed.tt @@ -19,7 +19,7 @@ [% IF changed.$doc.creation %][% df.format(changed.$doc.creation) %][% END %] [% IF changed.$doc.last_change %][% df.format(changed.$doc.last_change) %][% END %] - [% atomIdFor(language,filename,dstUriFor(doc,filename)) %] + tag:thenautilus.net,[% atomIdFor(language,filename,dstUriFor(doc,filename)) %] [% dstUriFor(doc,filename) %] [% END -%] diff --git a/t/test-site/src/common/du2html.xsl b/t/test-site/src/common/du2html.xsl index 8b73a82..cc4372b 100644 --- a/t/test-site/src/common/du2html.xsl +++ b/t/test-site/src/common/du2html.xsl @@ -1,7 +1,9 @@ @@ -11,6 +13,23 @@ + + + + it + en + + + en + it + + + + + + + + @@ -39,7 +58,7 @@ - + @@ -83,7 +102,7 @@ -
+
    @@ -93,7 +112,7 @@
  • - + ()
  • diff --git a/t/test-site/src/common/fillFeed.xsl b/t/test-site/src/common/fillFeed.xsl index 30d167b..593ff51 100644 --- a/t/test-site/src/common/fillFeed.xsl +++ b/t/test-site/src/common/fillFeed.xsl @@ -38,7 +38,7 @@ - +
    diff --git a/t/test-site/src/en-only/document.en.rest.txt b/t/test-site/src/en-only/document.en.rest.txt new file mode 100644 index 0000000..d5028bd --- /dev/null +++ b/t/test-site/src/en-only/document.en.rest.txt @@ -0,0 +1,7 @@ +===================== + document in English +===================== +:tags: * two + +only in English! + diff --git a/t/test-site/src/en-only/du2html.xsl b/t/test-site/src/en-only/du2html.xsl new file mode 120000 index 0000000..bea6032 --- /dev/null +++ b/t/test-site/src/en-only/du2html.xsl @@ -0,0 +1 @@ +../common/du2html.xsl \ No newline at end of file diff --git a/t/test-site/src/tags/two/feed.en.tt b/t/test-site/src/tags/two/feed.en.tt new file mode 120000 index 0000000..7af7c9e --- /dev/null +++ b/t/test-site/src/tags/two/feed.en.tt @@ -0,0 +1 @@ +../../common/base-feed.tt \ No newline at end of file diff --git a/t/test-site/src/tags/two/feed.it.tt b/t/test-site/src/tags/two/feed.it.tt new file mode 120000 index 0000000..7af7c9e --- /dev/null +++ b/t/test-site/src/tags/two/feed.it.tt @@ -0,0 +1 @@ +../../common/base-feed.tt \ No newline at end of file diff --git a/t/test-site/src/tags/two/fillFeed.xsl b/t/test-site/src/tags/two/fillFeed.xsl new file mode 120000 index 0000000..0ec1e81 --- /dev/null +++ b/t/test-site/src/tags/two/fillFeed.xsl @@ -0,0 +1 @@ +../../common/fillFeed.xsl \ No newline at end of file -- cgit v1.2.3