From c485132380a87e93e49afba5bcf5f541f044c07b Mon Sep 17 00:00:00 2001 From: dakkar Date: Tue, 18 Aug 2009 17:07:21 +0200 Subject: export changes to XSLT --- lib/WebCoso/Maker.pm | 3 +++ lib/WebCoso/XSLT.pm | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/lib/WebCoso/Maker.pm b/lib/WebCoso/Maker.pm index b64c77f..0eb0b02 100644 --- a/lib/WebCoso/Maker.pm +++ b/lib/WebCoso/Maker.pm @@ -180,6 +180,7 @@ my @passes=( ["$WebCoso::Common::DSTPATH/tags/(**)/document.(*).html", ':', "$WebCoso::Common::SRCPATH/_webcoso/tags.yml", + "$WebCoso::Common::SRCPATH/_webcoso/changes.yml", "$WebCoso::Common::SRCPATH/tags/\$1/document.\$2.du.xml", '=', $xslt->du2html()], @@ -189,6 +190,7 @@ my @passes=( ["$WebCoso::Common::DSTPATH/(**)/document.(*).html", ':', "$WebCoso::Common::SRCPATH/_webcoso/tags.yml", + "$WebCoso::Common::SRCPATH/_webcoso/changes.yml", "$WebCoso::Common::SRCPATH/\$1/document.\$2.du.xml", '=', $xslt->du2html()], @@ -198,6 +200,7 @@ my @passes=( ["$WebCoso::Common::DSTPATH/()document.(*).html", ':', "$WebCoso::Common::SRCPATH/_webcoso/tags.yml", + "$WebCoso::Common::SRCPATH/_webcoso/changes.yml", "$WebCoso::Common::SRCPATH/document.\$2.du.xml", '=', $xslt->du2html()], diff --git a/lib/WebCoso/XSLT.pm b/lib/WebCoso/XSLT.pm index b52d596..73ba59d 100644 --- a/lib/WebCoso/XSLT.pm +++ b/lib/WebCoso/XSLT.pm @@ -27,6 +27,7 @@ sub new { $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,'changes',sub{$self->getChangesXML}); $self->{xslt_proc}->register_function($NS,'dates-for', sub{$self->getDatesXML(WebCoso::Common::getDatesFor($self->{fc},@_))}); $self->{xslt_proc}->register_function($NS,'document', @@ -57,6 +58,13 @@ sub new { } else { $self->setXMLTagsSource(undef); } + if (@$deps>2) { + INFO("changes from $deps->[1]"); + $self->setChangesSource($self->{fc}->get($deps->[1])); + } + else { + $self->setChangesSource(undef); + } my $out=$xslt->transform($du, XML::LibXSLT::xpath_to_string( path => $matches->[0], @@ -145,6 +153,41 @@ sub getTagsXML { my %name_map=(creation=>'wc:creation-date', last_change=>'wc:last-change'); my $format=DateTime::Format::Strptime->new(pattern=>'%F %T',time_zone=>'UTC'); +sub setChangesSource { + my ($self,$source)=@_; + # the weird copy seems to be needed, otherwise sometimes it looks empty + $self->{changes_source}=(defined $source) ? {%$source} : undef; + delete $self->{changes_document}; +} +sub getChangesXML { + my ($self)=@_; + if (defined $self->{chasges_document}) { + DEBUG('returing cached ChangesXML'); + return $self->{Changes_document} + } + DEBUG('building ChangesXML'); + my $doc=XML::LibXML::Document->new(); + return $doc unless defined $self->{changes_source}; + + my $de=$doc->createElementNS($NS,'wc:changes'); + $doc->setDocumentElement($de); + my ($docpath,$dates); + while (($docpath,$dates)=each %{$self->{changes_source}}) { + my $te=$doc->createElementNS($NS,'wc:document'); + $te->setAttribute('path',$docpath); + $te->setAttribute('uri',WebCoso::Common::dstUriFor($docpath)); + $te->setAttribute('lang',WebCoso::Common::langOf($docpath)); + $de->appendChild($te); + my ($type,$value); + while (($type,$value)=each %$dates) { + my $dle=$doc->createElementNS($NS,$name_map{$type}); + $dle->appendTextNode($format->format_datetime($value)); + $te->appendChild($dle); + } + } + return $self->{changes_document}=$doc; +} + sub getDatesXML { my ($self,$dates)=@_; my $doc=XML::LibXML::Document->new(); -- cgit v1.2.3