aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--stest.pl34
-rw-r--r--t/test-site/src/common/du2html.xsl29
-rw-r--r--t/test-site/src/foo/document.it.rest.txt6
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 @@
<?xml version="1.0" encoding="utf-8"?>
<x:stylesheet xmlns:x="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:wc="http://webcoso.thenautilus.net/"
version="1.0"
>
<x:import href="reST.xsl"/>
<x:param name="language" select="'en'"/>
+ <x:param name="path"/>
+ <x:param name="filename"/>
<x:output method="html" encoding="utf-8"
doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN"
indent="yes"/>
+ <x:template match="reference">
+ <x:element name="a">
+ <x:attribute name="href">
+ <x:choose>
+ <x:when test="@refid">
+ <x:value-of select="concat('#', @refid)" />
+ </x:when>
+ <x:when test="@refuri">
+ <x:value-of select="@refuri" />
+ </x:when>
+ </x:choose>
+ </x:attribute>
+
+ <x:choose>
+ <x:when test="@refuri and string(.)=string(@refuri)">
+ <x:apply-templates select="wc:title-for($language,$filename,@refuri)"/>
+ </x:when>
+ <x:otherwise>
+ <x:apply-templates />
+ </x:otherwise>
+ </x:choose>
+ </x:element>
+ </x:template>
+
<x:template match="/document">
<html xml:lang="{$language}" lang="{$language}">
<head>
- <title><x:apply-templates select="title/node()"/></title>
+ <title><x:value-of select="title"/></title>
</head>
<body>
<h1><x:apply-templates select="title/node()"/></h1>
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