From 2969fd3ef2ac1004ff4594198e84b31c60adb0c5 Mon Sep 17 00:00:00 2001 From: dakkar Date: Thu, 3 Jan 2008 20:35:26 +0000 Subject: refactoring: ReST git-svn-id: svn://luxion/repos/WebCoso/trunk@328 fcb26f47-9200-0410-b104-b98ab5b095f3 --- lib/WebCoso/Common.pm | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) (limited to 'lib/WebCoso/Common.pm') diff --git a/lib/WebCoso/Common.pm b/lib/WebCoso/Common.pm index e6e5ac9..6dbeeae 100644 --- a/lib/WebCoso/Common.pm +++ b/lib/WebCoso/Common.pm @@ -1,12 +1,14 @@ package WebCoso::Common; use strict; use warnings; +use File::Next; use Path::Class; use XML::LibXML::XPathContext; our $SRCPATH='src'; our $DSTPATH='dst'; our $DSTBASEURL='/'; +our @TMPLPATH=('common/'); my $xpath=XML::LibXML::XPathContext->new(); $xpath->registerNs('x', 'http://www.w3.org/1999/xhtml'); @@ -92,4 +94,61 @@ sub getTags { return \%tagged; } +sub fromTo { + my ($base,$opts)=@_; + my $iter=File::Next::files( + { + file_filter=>$opts->{files}, + descend_filter=>$opts->{dirs}, + }, + $base); + my (@ret,$file); + if (defined $opts->{transform}) { + push @ret,$opts->{transform}->($file) while $file=$iter->(); + } + else { + push @ret,$file while $file=$iter->(); + } + return @ret; +} + +{ +my %order=( + 'rest.tt'=>0, + 'rest.txt'=>1, + 'du.xml'=>2, +); +sub earliest { + my ($a,$b)=@_; + return $a unless $b; + return $order{$a} < $order{$b} + ? $a + : $b; +} + +sub keepEarliest { + my %dirs; + for my $f (@_) { + my $c=file($f); + my $lang=langOf($c->basename); + my $type=typeOf($c->basename); + if (!defined $lang or !defined $type) { + die "Weird document name <$f>"; + } + $dirs{$c->parent}->{$lang}=earliest($type,$dirs{$c->parent}->{$lang}); + } + my @ret; + while (my ($d,$langs)=each %dirs) { + while (my ($lang,$type)=each %$langs) { + push @ret,file($d,"document.$lang.$type")->stringify; + } + } + return @ret; +} +} + +our %docfiles=( + files=>sub{m{^document\.}}, + dirs=>sub{!m{^(tags|_webcoso|\.svn)$}}); + 1; -- cgit v1.2.3