From 8650f17901d87666f80aff7a5538c0edd4e382dc Mon Sep 17 00:00:00 2001 From: dakkar Date: Wed, 2 Jan 2008 13:55:03 +0000 Subject: ugly way to get titles... may require double-run git-svn-id: svn://luxion/repos/WebCoso/trunk@318 fcb26f47-9200-0410-b104-b98ab5b095f3 --- stest.pl | 34 +++++++++++++++++++++++++++++--- t/test-site/src/common/du2html.xsl | 29 ++++++++++++++++++++++++++- t/test-site/src/foo/document.it.rest.txt | 6 +++--- 3 files changed, 62 insertions(+), 7 deletions(-) diff --git a/stest.pl b/stest.pl index ac9b1a9..280a0c5 100644 --- a/stest.pl +++ b/stest.pl @@ -43,6 +43,8 @@ my $template=Template->new({ my $rest=Text::Restructured->new({},'WebCoso'); my $xml_parser=XML::LibXML->new(); my $xslt_proc=XML::LibXSLT->new(); +my $xpath=XML::LibXML::XPathContext->new(); +$xpath->registerNs('x', 'http://www.w3.org/1999/xhtml'); my $fc=File::Cache::Parsed->new(follow=>1); $fc->add_parser(qr{\.tt2?$} => @@ -76,6 +78,34 @@ sub dstUriFor { return $name; } +sub getTitleFor { + my ($lang,$path,$name)=@_; + + my $doc_name=$name; + $doc_name=~s{\.html$}{.du.xml}; + $doc_name=~s{/$}{/document.$lang.du.xml}; + if ($doc_name=~m{^\Q$DSTBASEURL\E}) { + $doc_name=~s{^\Q$DSTBASEURL\E}{$SRCPATH/}; + } + else { + $doc_name="$SRCPATH/$doc_name"; + } + #$doc_name=file($doc_name)->absolute(file($path)->parent); # absolutize it + warn "getTitleFor($lang,$path,$name)->$doc_name\n"; + + my $doc=$fc->get($doc_name); + unless ($doc) { + warn "No document for <$doc_name>, returning <$name>\n"; + return $name; + } + my $title=$xpath->findnodes( + q{/document/title}, + $doc); + return $title; +} + +$xslt_proc->register_function('http://webcoso.thenautilus.net/','title-for',\&getTitleFor); + sub isLang { my ($lang,$name)=@_; warn "isLang($lang,$name)\n"; @@ -125,12 +155,11 @@ sub du2html { XML::LibXSLT::xpath_to_string( path => $matches->[0], language => $matches->[1], + filename => $deps->[-1], )); $fc->put($target,$xslt->output_string($out)); } -{my $xpath=XML::LibXML::XPathContext->new(); -$xpath->registerNs('x', 'http://www.w3.org/1999/xhtml'); sub getTags { my ($maker,$target,$deps,$matches)=@_; @@ -146,7 +175,6 @@ sub getTags { } $fc->put($target,\%tagged); } -} sub getChanges { my ($maker,$target,$deps,$matches)=@_; diff --git a/t/test-site/src/common/du2html.xsl b/t/test-site/src/common/du2html.xsl index d7a9b62..b67dbe6 100644 --- a/t/test-site/src/common/du2html.xsl +++ b/t/test-site/src/common/du2html.xsl @@ -1,21 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + - <x:apply-templates select="title/node()"/> + <x:value-of select="title"/>

diff --git a/t/test-site/src/foo/document.it.rest.txt b/t/test-site/src/foo/document.it.rest.txt index e4d7333..7fc3936 100644 --- a/t/test-site/src/foo/document.it.rest.txt +++ b/t/test-site/src/foo/document.it.rest.txt @@ -1,6 +1,6 @@ -============ - Pagina foo -============ +============== + Pagina *foo* +============== :tags: * one * two -- cgit v1.2.3