From 9deff2ac08868dcc097d4335b6919632f1c5d0d2 Mon Sep 17 00:00:00 2001 From: dakkar Date: Sun, 9 Sep 2007 11:18:59 +0000 Subject: first test (preparation) git-svn-id: svn://luxion/repos/WebCoso/trunk@286 fcb26f47-9200-0410-b104-b98ab5b095f3 --- stest.pl | 78 +++-- t/test-site/common/document-listing.tt | 3 + t/test-site/common/du2html.xsl | 27 ++ t/test-site/common/reST.xsl | 393 +++++++++++++++++++++++++ t/test-site/src/bar/baz/document.en.rest.txt | 7 + t/test-site/src/bar/baz/document.it.rest.txt | 7 + t/test-site/src/bar/baz/du2html.xsl | 1 + t/test-site/src/bar/document.en.rest.tt | 5 + t/test-site/src/bar/document.it.rest.tt | 5 + t/test-site/src/bar/du2html.xsl | 1 + t/test-site/src/bar/list.tt | 5 + t/test-site/src/document.en.rest.txt | 9 + t/test-site/src/document.it.rest.txt | 9 + t/test-site/src/foo/document.en.rest.txt | 7 + t/test-site/src/foo/document.it.rest.txt | 7 + t/test-site/src/foo/du2html.xsl | 1 + t/test-site/tags/one/document-listing.tt | 1 + t/test-site/tags/one/document.en.rest.tt | 5 + t/test-site/tags/one/document.it.rest.tt | 5 + t/test-site/tags/three/bis/document-listing.tt | 1 + t/test-site/tags/three/bis/document.en.rest.tt | 5 + t/test-site/tags/three/bis/document.it.rest.tt | 5 + t/test-site/tags/three/document-listing.tt | 1 + t/test-site/tags/three/document.en.rest.tt | 5 + t/test-site/tags/three/document.it.rest.tt | 5 + t/test-site/tags/two/document-listing.tt | 1 + t/test-site/tags/two/document.en.rest.tt | 5 + t/test-site/tags/two/document.it.rest.tt | 5 + 28 files changed, 592 insertions(+), 17 deletions(-) create mode 100644 t/test-site/common/document-listing.tt create mode 100644 t/test-site/common/du2html.xsl create mode 100644 t/test-site/common/reST.xsl create mode 100644 t/test-site/src/bar/baz/document.en.rest.txt create mode 100644 t/test-site/src/bar/baz/document.it.rest.txt create mode 120000 t/test-site/src/bar/baz/du2html.xsl create mode 100644 t/test-site/src/bar/document.en.rest.tt create mode 100644 t/test-site/src/bar/document.it.rest.tt create mode 120000 t/test-site/src/bar/du2html.xsl create mode 100644 t/test-site/src/bar/list.tt create mode 100644 t/test-site/src/document.en.rest.txt create mode 100644 t/test-site/src/document.it.rest.txt create mode 100644 t/test-site/src/foo/document.en.rest.txt create mode 100644 t/test-site/src/foo/document.it.rest.txt create mode 120000 t/test-site/src/foo/du2html.xsl create mode 120000 t/test-site/tags/one/document-listing.tt create mode 100644 t/test-site/tags/one/document.en.rest.tt create mode 100644 t/test-site/tags/one/document.it.rest.tt create mode 120000 t/test-site/tags/three/bis/document-listing.tt create mode 100644 t/test-site/tags/three/bis/document.en.rest.tt create mode 100644 t/test-site/tags/three/bis/document.it.rest.tt create mode 120000 t/test-site/tags/three/document-listing.tt create mode 100644 t/test-site/tags/three/document.en.rest.tt create mode 100644 t/test-site/tags/three/document.it.rest.tt create mode 120000 t/test-site/tags/two/document-listing.tt create mode 100644 t/test-site/tags/two/document.en.rest.tt create mode 100644 t/test-site/tags/two/document.it.rest.tt diff --git a/stest.pl b/stest.pl index a22c5ce..fc87b8b 100644 --- a/stest.pl +++ b/stest.pl @@ -11,6 +11,7 @@ use Text::Restructured; use Text::Restructured::Writer::LibXML; use XML::LibXML; use XML::LibXSLT; +use YAML::Syck; my $stash={}; my $template=Template->new(); @@ -18,7 +19,7 @@ my $rest=Text::Restructured->new({},'WebCoso'); my $xml_parser=XML::LibXML->new(); my $xslt_proc=XML::LibXSLT->new(); -my $fc=File::Cache::Parsed->new(); +my $fc=File::Cache::Parsed->new(follow=>1); $fc->add_parser(qr{\.tt2?$} => sub { $template->context->template($_[0]); @@ -36,35 +37,65 @@ $fc->add_parser(qr{\.xslt?$} => ($xml_parser->parse_string($_[1],$_[0])) }); $fc->add_writer(qr{\.xml$} => sub { $_[1]->toFile($_[0]) }); +$fc->add_parser(qr{\.ya?ml$} => + sub { Load($_[1]) }); +$fc->add_writer(qr{\.ya?ml$} => + sub { DumpFile($_[0],$_[1]) }); + sub expandTT { my ($maker,$target,$deps,$matches)=@_; - print "TT: $target <- @$deps, @$matches\n"; - open my $fh,'>',$target; + my $tmpl=$fc->get($deps->[-1]); + my $vars={ path=> $matches->[0], + language => $matches->[1], + %$stash, + }; + if (@$deps>1) { + $vars->{tagged}=$fc->get($deps->[0]); + } + $fc->put($target, + $template->context->process($tmpl, + $vars)); } sub parseRST { my ($maker,$target,$deps,$matches)=@_; - print "RST: $target <- @$deps, @$matches\n"; - open my $fh,'>',$target; + $fc->put($target,$fc->get($deps->[0])); } sub du2html { my ($maker,$target,$deps,$matches)=@_; - print "HTML: $target <- @$deps, @$matches\n"; - open my $fh,'>',$target; + my $du=$fc->get($deps->[-1]); + my $xslt=file($deps->[-1])->parent->file('du2html.xsl'); + $xslt=$fc->get($xslt); + my $out=$xslt->transform($du, + XML::LibXSLT::xpath_to_string( + path => $matches->[0], + language => $matches->[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)=@_; - print "tags: $target <- @$deps, @$matches\n"; - open my $fh,'>',$target; + my %tagged; + for my $doc_name (@$deps) { + my $doc=$fc->get($doc_name); + my @tags=map {$_->textContext} + $xpath->find( + q{/document/docinfo/field[field_name='tags']/field_body/*/list_item}, + $doc); + push @{$tagged{$_}},$doc_name for @tags; + } + $fc->put($target,\%tagged); +} } - sub getChanges { my ($maker,$target,$deps,$matches)=@_; @@ -133,11 +164,14 @@ my %files=(files=>sub{m{^document\.}}); my $maker=Slay::Maker->new({ rules => [ - ['src/(**)/document.rest.txt',':',ifExists('src/$1/document.rest.tt'),'=',\&expandTT], - ['src/(**)/document.du.xml',':',ifExists('src/$1/document.rest.txt'),'=',\&parseRST], - ['deps/tags.xml',':',fromTo('src/',{%files,transform=>sub{my $s=shift;$s=~s{\..*$}{.du.xml};$s}}),'=',\&getTags], - ['deps/changes.xml',':',keepEarliest(fromTo('src/',{%files})),'=',\&getChanges], - ['dst/(**)/document.xhtml',':','deps/tags.xml','deps/changes.xml',ifExists('src/$1/document.du.xml'),'=',\&du2html], + ['src/(**)/document.(*).rest.txt',':',ifExists('src/$1/document.$2.rest.tt'),'=',\&expandTT], + ['src/(**)/document.(*).du.xml',':',ifExists('src/$1/document.$2.rest.txt'),'=',\&parseRST], + ['deps/tags.xml',':',fromTo('src/',{%files,transform=>sub{my $s=shift;$s=~s{\.[^.]+\.[^.]+$}{.du.xml};$s}}),'=',\&getTags], + #['deps/changes.xml',':',keepEarliest(fromTo('src/',{%files})),'=',\&getChanges], + + ['tags/(**)/document.(*).rest.txt',':','deps/tags.yml',ifExists('tags/$1/document.$2.rest.tt'),'=',\&expandTT], + ['tags/(**)/document.(*).du.xml',':','deps/tags.yml',ifExists('tags/$1/document.$2.rest.txt'),'=',\&parseRST], + ['dst/(**)/document.(*).xhtml',':','deps/tags.yml','deps/changes.xml',ifExists('src/$1/document.$2.du.xml'),ifExists('tags/$1/document.$2.du.xml'),'=',\&du2html], ], options => { auto_create_dirs => 1, @@ -152,11 +186,21 @@ my @targets=fromTo('src/', %files, transform=>sub{ my $src=shift; - $src=~s{\..*$}{.xhtml}; + $src=~s{\.[^.]+\.[^.]+$}{.xhtml}; $src=~s{^src/}{dst/}; return $src; }, - }); + }), + fromTo('tags/', + { + %files, + transform=>sub{ + my $src=shift; + $src=~s{\.[^.]+\.[^.]+$}{.xhtml}; + $src=~s{^tags/}{dst/}; + return $src; + }, + }); print "targets: @targets\n"; $maker->make(@targets); diff --git a/t/test-site/common/document-listing.tt b/t/test-site/common/document-listing.tt new file mode 100644 index 0000000..5210458 --- /dev/null +++ b/t/test-site/common/document-listing.tt @@ -0,0 +1,3 @@ +[% FOR doc IN tagged.$current_cat %] +* `<[% doc %]>`_ +[% END %] diff --git a/t/test-site/common/du2html.xsl b/t/test-site/common/du2html.xsl new file mode 100644 index 0000000..d7a9b62 --- /dev/null +++ b/t/test-site/common/du2html.xsl @@ -0,0 +1,27 @@ + + + + + + + + + + + + + <x:apply-templates select="title/node()"/> + + +

+ + + +
+ +
\ No newline at end of file diff --git a/t/test-site/common/reST.xsl b/t/test-site/common/reST.xsl new file mode 100644 index 0000000..7db5de2 --- /dev/null +++ b/t/test-site/common/reST.xsl @@ -0,0 +1,393 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+
+ + +
+
+ + + +
+
+ + +
+
+ + + +

+
+ + + + + + + +
+ +
+ + +
+ Source: + +
+
+
+ + + + + + + + + footnoteref + + footnote-backref- + + + + #footnote- + + + + [ + + ] + + + + + + + footnote + + footnote- + + + + + footnotereturn + + #footnote-backref- + + + + return to content + + + # + + : + + + + + + + + + + +
+
+ + +
+
+ + + +
  • +
    + + + + + + + + + +
    +
    + + +
    +
    + + +
    +
    + + + + + + + + + + + +
    OptionDescription
    +
    + + + + + + + + +
    +
    + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    diff --git a/t/test-site/src/bar/baz/document.en.rest.txt b/t/test-site/src/bar/baz/document.en.rest.txt new file mode 100644 index 0000000..40a4841 --- /dev/null +++ b/t/test-site/src/bar/baz/document.en.rest.txt @@ -0,0 +1,7 @@ +================= + bar-baz english +================= +:tags: * one + * three/bis + +sticaz diff --git a/t/test-site/src/bar/baz/document.it.rest.txt b/t/test-site/src/bar/baz/document.it.rest.txt new file mode 100644 index 0000000..8d15da2 --- /dev/null +++ b/t/test-site/src/bar/baz/document.it.rest.txt @@ -0,0 +1,7 @@ +================== + bar-baz italiano +================== +:tags: * one + * three/bis + +sticaz diff --git a/t/test-site/src/bar/baz/du2html.xsl b/t/test-site/src/bar/baz/du2html.xsl new file mode 120000 index 0000000..b6e8ebc --- /dev/null +++ b/t/test-site/src/bar/baz/du2html.xsl @@ -0,0 +1 @@ +../../../common/du2html.xsl \ No newline at end of file diff --git a/t/test-site/src/bar/document.en.rest.tt b/t/test-site/src/bar/document.en.rest.tt new file mode 100644 index 0000000..0d1e3f2 --- /dev/null +++ b/t/test-site/src/bar/document.en.rest.tt @@ -0,0 +1,5 @@ +===================== + bar (from template) +===================== + +[% PROCESS list %] diff --git a/t/test-site/src/bar/document.it.rest.tt b/t/test-site/src/bar/document.it.rest.tt new file mode 100644 index 0000000..d6f5509 --- /dev/null +++ b/t/test-site/src/bar/document.it.rest.tt @@ -0,0 +1,5 @@ +================ + bar (generato) +================ + +[% PROCESS list %] diff --git a/t/test-site/src/bar/du2html.xsl b/t/test-site/src/bar/du2html.xsl new file mode 120000 index 0000000..6737f0e --- /dev/null +++ b/t/test-site/src/bar/du2html.xsl @@ -0,0 +1 @@ +../../common/du2html.xsl \ No newline at end of file diff --git a/t/test-site/src/bar/list.tt b/t/test-site/src/bar/list.tt new file mode 100644 index 0000000..567b32b --- /dev/null +++ b/t/test-site/src/bar/list.tt @@ -0,0 +1,5 @@ +:tags: two + +[% FOR i IN [1,2,3] %] +* line [% i %] +[% END %] diff --git a/t/test-site/src/document.en.rest.txt b/t/test-site/src/document.en.rest.txt new file mode 100644 index 0000000..15045d2 --- /dev/null +++ b/t/test-site/src/document.en.rest.txt @@ -0,0 +1,9 @@ +=========== + Main page +=========== + +* ``_ +* `bar! `_ +* `baz`_ + +.. _`baz`: baz/ diff --git a/t/test-site/src/document.it.rest.txt b/t/test-site/src/document.it.rest.txt new file mode 100644 index 0000000..f29a12b --- /dev/null +++ b/t/test-site/src/document.it.rest.txt @@ -0,0 +1,9 @@ +=================== + Pagina principale +=================== + +* ``_ +* `bar! `_ +* `baz`_ + +.. _`baz`: baz/ diff --git a/t/test-site/src/foo/document.en.rest.txt b/t/test-site/src/foo/document.en.rest.txt new file mode 100644 index 0000000..4380082 --- /dev/null +++ b/t/test-site/src/foo/document.en.rest.txt @@ -0,0 +1,7 @@ +========== + foo page +========== +:tags: * one + * two + +foo diff --git a/t/test-site/src/foo/document.it.rest.txt b/t/test-site/src/foo/document.it.rest.txt new file mode 100644 index 0000000..e4d7333 --- /dev/null +++ b/t/test-site/src/foo/document.it.rest.txt @@ -0,0 +1,7 @@ +============ + Pagina foo +============ +:tags: * one + * two + +foo diff --git a/t/test-site/src/foo/du2html.xsl b/t/test-site/src/foo/du2html.xsl new file mode 120000 index 0000000..6737f0e --- /dev/null +++ b/t/test-site/src/foo/du2html.xsl @@ -0,0 +1 @@ +../../common/du2html.xsl \ No newline at end of file diff --git a/t/test-site/tags/one/document-listing.tt b/t/test-site/tags/one/document-listing.tt new file mode 120000 index 0000000..9444be1 --- /dev/null +++ b/t/test-site/tags/one/document-listing.tt @@ -0,0 +1 @@ +../../common/document-listing.tt \ No newline at end of file diff --git a/t/test-site/tags/one/document.en.rest.tt b/t/test-site/tags/one/document.en.rest.tt new file mode 100644 index 0000000..76734b9 --- /dev/null +++ b/t/test-site/tags/one/document.en.rest.tt @@ -0,0 +1,5 @@ +================ + Category 'one' +================ + +[% PROCESS document-listing %] diff --git a/t/test-site/tags/one/document.it.rest.tt b/t/test-site/tags/one/document.it.rest.tt new file mode 100644 index 0000000..30033c8 --- /dev/null +++ b/t/test-site/tags/one/document.it.rest.tt @@ -0,0 +1,5 @@ +================= + Categoria 'uno' +================= + +[% PROCESS document-listing %] diff --git a/t/test-site/tags/three/bis/document-listing.tt b/t/test-site/tags/three/bis/document-listing.tt new file mode 120000 index 0000000..b2b2ee2 --- /dev/null +++ b/t/test-site/tags/three/bis/document-listing.tt @@ -0,0 +1 @@ +../../../common/document-listing.tt \ No newline at end of file diff --git a/t/test-site/tags/three/bis/document.en.rest.tt b/t/test-site/tags/three/bis/document.en.rest.tt new file mode 100644 index 0000000..18b7ac0 --- /dev/null +++ b/t/test-site/tags/three/bis/document.en.rest.tt @@ -0,0 +1,5 @@ +================ + Category 'three/bis' +================ + +[% PROCESS document-listing %] diff --git a/t/test-site/tags/three/bis/document.it.rest.tt b/t/test-site/tags/three/bis/document.it.rest.tt new file mode 100644 index 0000000..0f1414d --- /dev/null +++ b/t/test-site/tags/three/bis/document.it.rest.tt @@ -0,0 +1,5 @@ +================= + Categoria 'three/bis' +================= + +[% PROCESS document-listing %] diff --git a/t/test-site/tags/three/document-listing.tt b/t/test-site/tags/three/document-listing.tt new file mode 120000 index 0000000..9444be1 --- /dev/null +++ b/t/test-site/tags/three/document-listing.tt @@ -0,0 +1 @@ +../../common/document-listing.tt \ No newline at end of file diff --git a/t/test-site/tags/three/document.en.rest.tt b/t/test-site/tags/three/document.en.rest.tt new file mode 100644 index 0000000..3848f3c --- /dev/null +++ b/t/test-site/tags/three/document.en.rest.tt @@ -0,0 +1,5 @@ +================ + Category 'three' +================ + +[% PROCESS document-listing %] diff --git a/t/test-site/tags/three/document.it.rest.tt b/t/test-site/tags/three/document.it.rest.tt new file mode 100644 index 0000000..0c1a4a4 --- /dev/null +++ b/t/test-site/tags/three/document.it.rest.tt @@ -0,0 +1,5 @@ +================= + Categoria 'three' +================= + +[% PROCESS document-listing %] diff --git a/t/test-site/tags/two/document-listing.tt b/t/test-site/tags/two/document-listing.tt new file mode 120000 index 0000000..9444be1 --- /dev/null +++ b/t/test-site/tags/two/document-listing.tt @@ -0,0 +1 @@ +../../common/document-listing.tt \ No newline at end of file diff --git a/t/test-site/tags/two/document.en.rest.tt b/t/test-site/tags/two/document.en.rest.tt new file mode 100644 index 0000000..861ee70 --- /dev/null +++ b/t/test-site/tags/two/document.en.rest.tt @@ -0,0 +1,5 @@ +================ + Category 'two' +================ + +[% PROCESS document-listing %] diff --git a/t/test-site/tags/two/document.it.rest.tt b/t/test-site/tags/two/document.it.rest.tt new file mode 100644 index 0000000..71c4dc0 --- /dev/null +++ b/t/test-site/tags/two/document.it.rest.tt @@ -0,0 +1,5 @@ +================= + Categoria 'two' +================= + +[% PROCESS document-listing %] -- cgit v1.2.3